Class: Payment

Inherits:
Base
  • Object
show all
Defined in:
lib/globe_connect/payment.rb

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

Instance Method Summary collapse

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.

Parameters:

  • string

    app_id

  • string

    app_secret

  • string

    access_token



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_tokenObject

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_idObject

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_secretObject

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_codeObject

Get last reference code request.

Returns:

  • json



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.

Parameters:

  • float

    amount

  • string

    description

  • string

    end_user_id

  • string

    reference_code

  • string

    transaction_operation_status

Returns:

  • json



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