Class: BcaStatement::Client
- Inherits:
-
Object
- Object
- BcaStatement::Client
- Defined in:
- lib/bca_statement/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#balance ⇒ Object
Get your BCA Bisnis account balance information.
-
#get_statement(start_date = '2016-08-29', end_date = '2016-09-01') ⇒ Object
Get your BCA Bisnis account statement for a period up to 31 days.
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 |
# File 'lib/bca_statement/client.rb', line 13 def initialize @base_url = BcaStatement.configuration.base_url @corporate_id = BcaStatement.configuration.corporate_id @account_number = BcaStatement.configuration.account_number @api_key = BcaStatement.configuration.api_key @domain = BcaStatement.configuration.domain authentication end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
11 12 13 |
# File 'lib/bca_statement/client.rb', line 11 def access_token @access_token end |
Instance Method Details
#balance ⇒ Object
Get your BCA Bisnis account balance information
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bca_statement/client.rb', line 63 def balance return nil unless @access_token begin = Time.now.iso8601(3) @relative_url = "/banking/v3/corporates/#{@corporate_id}/accounts/#{@account_number}" response = RestClient.get("#{@base_url}#{@relative_url}", "Content-Type": 'application/json', "Authorization": "Bearer #{@access_token}", "Origin": @domain, "X-BCA-Key": @api_key, "X-BCA-Timestamp": , "X-BCA-Signature": signature) data = JSON.parse response.body if account_detail_success = data['AccountDetailDataSuccess'] detail = account_detail_success.first attribute = { account_number: detail['AccountNumber'], currency: detail['Currency'], balance: detail['Balance'].to_f, available_balance: detail['AvailableBalance'].to_f, float_amount: detail['FloatAmount'].to_f, hold_amount: detail['HoldAmount'].to_f, plafon: detail['Plafon'].to_f } BcaStatement::Entities::Balance.new(attribute) else return nil end rescue RestClient::ExceptionWithResponse => err return nil end end |
#get_statement(start_date = '2016-08-29', end_date = '2016-09-01') ⇒ Object
Get your BCA Bisnis account statement for a period up to 31 days.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bca_statement/client.rb', line 24 def get_statement(start_date = '2016-08-29', end_date = '2016-09-01') return nil unless @access_token = Time.now.iso8601(3) @start_date = start_date.to_s @end_date = end_date.to_s @path = "/banking/v3/corporates/" @relative_url = "#{@path}#{@corporate_id}/accounts/#{@account_number}/statements?EndDate=#{@end_date}&StartDate=#{@start_date}" begin response = RestClient.get("#{@base_url}#{@relative_url}", "Content-Type": 'application/json', "Authorization": "Bearer #{@access_token}", "Origin": @domain, "X-BCA-Key": @api_key, "X-BCA-Timestamp": , "X-BCA-Signature": signature) elements = JSON.parse response.body statements = [] elements['Data'].each do |element| year = Date.parse(@start_date).strftime('%m').to_i.eql?(12) ? Date.parse(@start_date).strftime('%Y') : Date.parse(@end_date).strftime('%Y') date = element['TransactionDate'].eql?("PEND") ? element['TransactionDate'] : "#{element['TransactionDate']}/#{year}" attribute = { date: date, brance_code: element['BranchCode'], type: element['TransactionType'], amount: element['TransactionAmount'].to_f, name: element['TransactionName'], trailer: element['Trailer'] } statements << BcaStatement::Entities::Statement.new(attribute) end statements rescue RestClient::ExceptionWithResponse => err return nil end end |