Class: Stanbic::Client
- Inherits:
-
Object
- Object
- Stanbic::Client
- Defined in:
- lib/stanbic/client.rb
Constant Summary collapse
- HTTP_OK_CODE =
200- BASE_URL =
"https://api.connect.stanbicbank.co.ke/api/sandbox/".freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#currency_code ⇒ Object
readonly
Returns the value of attribute currency_code.
Instance Method Summary collapse
-
#initialize(api_key:, api_secret:, currency_code: "KES", adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #inter_bank_transfer ⇒ Object
- #mobile_transfer(sender, receipient, amount, provider) ⇒ Object
- #mpesa_checkout(mobile_number, amount, bill_account_ref) ⇒ Object
- #stanbic_payments(account_to, amount) ⇒ Object
Constructor Details
#initialize(api_key:, api_secret:, currency_code: "KES", adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 |
# File 'lib/stanbic/client.rb', line 11 def initialize(api_key:, api_secret:, currency_code: "KES", adapter: Faraday.default_adapter) @api_key = api_key @api_secret = api_secret @adapter = adapter @currency_code = currency_code end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/stanbic/client.rb', line 9 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/stanbic/client.rb', line 9 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
9 10 11 |
# File 'lib/stanbic/client.rb', line 9 def api_secret @api_secret end |
#currency_code ⇒ Object (readonly)
Returns the value of attribute currency_code.
9 10 11 |
# File 'lib/stanbic/client.rb', line 9 def currency_code @currency_code end |
Instance Method Details
#inspect ⇒ Object
133 134 135 |
# File 'lib/stanbic/client.rb', line 133 def inspect "#<Stanbic::Client>" end |
#inter_bank_transfer ⇒ Object
118 119 120 |
# File 'lib/stanbic/client.rb', line 118 def inter_bank_transfer request(http_method: :post, endpoint: "pesalink-payments", params: ) end |
#mobile_transfer(sender, receipient, amount, provider) ⇒ Object
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/stanbic/client.rb', line 71 def mobile_transfer(sender, receipient, amount, provider) # PROVIDERS = { # MPESA, # T-KASH, # AIRTET MONEY # } dbs_reference_id = Random.rand(1_000_000_000_000) end_to_end_id = Random.rand(1_000_000_000) post_body = { "originatorAccount": { "identification": { "mobileNumber": sender.to_s } }, "requestedExecutionDate": Time.now.strftime("%Y-%m-%d"), "dbsReferenceId": dbs_reference_id.to_s, "txnNarrative": "TRANSACTION NARRATIVE", "callBackUrl": "http://client_domain.com/omnichannel/esbCallback", "transferTransactionInformation": { "instructedAmount": { "amount": amount.to_s, "currencyCode": currency_code }, "mobileMoneyMno": { "name": provider.to_s }, "counterparty": { "name": "J. Sparrow", "mobileNumber": receipient.to_s, "postalAddress": { "addressLine1": "Some street", "addressLine2": "99", "postCode": "1100 ZZ", "town": "Amsterdam", "country": "NL" } }, "remittanceInformation": { "type": "UNSTRUCTURED", "content": "SALARY" }, "endToEndIdentification": end_to_end_id.to_s } } request(http_method: :post, endpoint: "mobile-payments", params: post_body) end |
#mpesa_checkout(mobile_number, amount, bill_account_ref) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/stanbic/client.rb', line 122 def mpesa_checkout(mobile_number, amount, bill_account_ref) dbs_reference_id = ([*("A".."Z"), *("0".."9")] - %w[0 1 I O]).sample(13).join post_body = { "dbsReferenceId": dbs_reference_id.to_s, "billAccountRef": bill_account_ref.to_s, "amount": amount.to_s, "mobileNumber": mobile_number.to_s } request(http_method: :post, endpoint: "mpesa-checkout", params: post_body) end |
#stanbic_payments(account_to, amount) ⇒ Object
18 19 20 21 22 23 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 61 62 63 64 65 66 67 68 69 |
# File 'lib/stanbic/client.rb', line 18 def stanbic_payments(account_to, amount) dbs_reference_id = Random.rand(1_000_000_000_000) end_to_end_id = Random.rand(1_000_000_000) post_body = { "originatorAccount": { "identification": { "mobileNumber": "" } }, "requestedExecutionDate": Time.now.strftime("%Y-%m-%d"), "dbsReferenceId": dbs_reference_id.to_s, "txnNarrative": "TRANSACTION NARRATIVE", "callBackUrl": "http://clientdomain.com/omnichannel/esbCallback", "transferTransactionInformation": { "instructedAmount": { "amount": amount.to_s, "currencyCode": currency_code }, "counterparty": { "name": "J. Sparrow", "postalAddress": { "addressLine1": "Some street", "addressLine2": "99", "postCode": "1100 ZZ", "town": "Amsterdam", "country": "NL" } }, "counterpartyAccount": { "identification": { "identification": account_to.to_s } }, "remittanceInformation": { "type": "UNSTRUCTURED", "content": "SALARY" }, "endToEndIdentification": end_to_end_id.to_s } } request(http_method: :post, endpoint: "stanbic-payments", params: post_body) end |