Class: Ecocash::Client
- Inherits:
-
Object
- Object
- Ecocash::Client
- Includes:
- HTTParty
- Defined in:
- lib/ecocash/client.rb
Instance Method Summary collapse
- #charge_subscriber(msisdn, amount) ⇒ Object
- #list_transactions(msisdn) ⇒ Object
- #transaction_reversal(msisdn, transaction_id, amount) ⇒ Object
- #transaction_status(msisdn, client_correlator) ⇒ Object
Instance Method Details
#charge_subscriber(msisdn, amount) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 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 |
# File 'lib/ecocash/client.rb', line 5 def charge_subscriber(msisdn, amount) url = "#{Ecocash.configuration.api_base_url}/transactions/amount" args = { clientCorrelator: generated_client_correlator, notifyUrl: Ecocash.configuration.notify_url, referenceCode: Ecocash.configuration.reference_code, tranType: 'MER', endUserId: msisdn, remarks: Ecocash.configuration.payment_remarks, transactionOperationStatus: 'CHARGED', paymentAmount: { charginginformation: { amount: amount, currency: Ecocash.configuration.currency_code, description: Ecocash.configuration.description }, chargeMetaData: { channel: 'WEB', purchaseCategoryCode: Ecocash.configuration.purchase_category_code, onBeHalfOf: Ecocash.configuration.on_behalf_of } }, merchantCode: Ecocash.configuration.merchant_code, merchantPin: Ecocash.configuration.merchant_pin, merchantNumber: Ecocash.configuration.merchant_number, currencyCode: Ecocash.configuration.currency_code, countryCode: Ecocash.configuration.country_code, terminalID: Ecocash.configuration.terminal_id, location: Ecocash.configuration.location, superMerchantName: Ecocash.configuration.super_merchant_name, merchantName: Ecocash.configuration.merchant_name }.to_json = { body: args, basic_auth: auth, headers: { 'Content-Type' => 'application/json' } } response = self.class.post(url, ) JSON.parse(response.body) end |
#list_transactions(msisdn) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/ecocash/client.rb', line 57 def list_transactions(msisdn) url = "#{Ecocash.configuration.api_base_url}/#{msisdn}/transactions" = { basic_auth: auth, headers: { 'Content-Type' => 'application/json' } } response = self.class.get(url, ) JSON.parse(response.body) end |
#transaction_reversal(msisdn, transaction_id, amount) ⇒ Object
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 98 99 100 101 102 103 104 105 106 |
# File 'lib/ecocash/client.rb', line 67 def transaction_reversal(msisdn, transaction_id, amount) url = "#{Ecocash.configuration.api_base_url}/transactions/refund" args = { clientCorrelator: generated_client_correlator, referenceCode: Ecocash.configuration.reference_code, tranType: 'REF', endUserId: msisdn, originalEcocashReference: transaction_id, remark: Ecocash.configuration.refund_remarks, paymentAmount: { charginginformation: { amount: amount, currency: Ecocash.configuration.currency_code, description: Ecocash.configuration.description }, chargeMetaData: { channel: 'SMS', purchaseCategoryCode: Ecocash.configuration.purchase_category_code, onBeHalfOf: Ecocash.configuration.on_behalf_of } }, merchantCode: Ecocash.configuration.merchant_code, merchantPin: Ecocash.configuration.merchant_pin, merchantNumber: Ecocash.configuration.merchant_number, currencyCode: Ecocash.configuration.currency_code, countryCode: Ecocash.configuration.country_code, terminalID: Ecocash.configuration.terminal_id, location: cocash.configuration.location, superMerchantName: Ecocash.configuration.super_merchant_name, merchantName: Ecocash.configuration.merchant_name }.to_json = { body: args, basic_auth: auth, headers: { 'Content-Type' => 'application/json' } } response = self.class.post(url, ) JSON.parse(response.body) end |
#transaction_status(msisdn, client_correlator) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/ecocash/client.rb', line 47 def transaction_status(msisdn, client_correlator) url = "#{Ecocash.configuration.api_base_url}/#{msisdn}/transactions/amount/#{client_correlator}}" = { basic_auth: self.class.auth, headers: { 'Content-Type' => 'application/json' } } response = self.class.get(url, ) JSON.parse(response.body) end |