Class: Payment
Constant Summary collapse
- CHARGE_URL =
'https://devapi.globelabs.com.ph/payment/v1/transactions/amount?access_token=%s'
- LAST_REFERENCE_URL =
'https://devapi.globelabs.com.ph/payment/v1/transactions/getLastRefCode?app_id=%s&app_secret=%s'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
Returns the value of attribute app_secret.
Instance Method Summary collapse
-
#get_last_reference_code ⇒ Object
Get last reference code request.
-
#initialize(app_id, app_secret, access_token = nil) ⇒ Object
constructor
Starts up whenever the class is being called.
-
#send_payment_request(amount, description, end_user_id, reference_code, transaction_operation_status) ⇒ Object
Sends payment request.
Methods inherited from Base
#send_get_request, #send_post_request
Constructor Details
#initialize(app_id, app_secret, access_token = nil) ⇒ Object
Starts up whenever the class is being called.
14 15 16 17 18 |
# File 'lib/globe_connect/payment.rb', line 14 def initialize(app_id, app_secret, access_token = nil) @app_id = app_id @app_secret = app_secret @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/globe_connect/payment.rb', line 6 def access_token @access_token end |
#app_id ⇒ Object
Returns the value of attribute app_id.
6 7 8 |
# File 'lib/globe_connect/payment.rb', line 6 def app_id @app_id end |
#app_secret ⇒ Object
Returns the value of attribute app_secret.
6 7 8 |
# File 'lib/globe_connect/payment.rb', line 6 def app_secret @app_secret end |
Instance Method Details
#get_last_reference_code ⇒ Object
Get last reference code request.
56 57 58 59 60 61 62 63 64 |
# File 'lib/globe_connect/payment.rb', line 56 def get_last_reference_code # set the url url = sprintf(LAST_REFERENCE_URL, @app_id, @app_secret) # send response response = send_get_request(url) return JSON.parse(response) end |
#send_payment_request(amount, description, end_user_id, reference_code, transaction_operation_status) ⇒ Object
Sends payment request.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/globe_connect/payment.rb', line 28 def send_payment_request(amount, description, end_user_id, reference_code, transaction_operation_status) # set the request url url = sprintf(CHARGE_URL, @access_token) # make sure that amount has 2 decimal places amount = '%.2f' % amount # set the payload payload = { "amount" => amount.to_s, "description" => description, "endUserId" => end_user_id, "referenceCode" => reference_code, "transactionOperationStatus" => transaction_operation_status } # convert to JSON payload = JSON.generate(payload) # send post request response = send_post_request(url, payload) return JSON.parse(response) end |