Class: Payhere::Inpayments

Inherits:
Client
  • Object
show all
Defined in:
lib/payhere-sdk/inpayments.rb

Instance Method Summary collapse

Methods inherited from Client

#create_connection, #get_credentials, #handle_error, #interpret_response, #send_request

Instance Method Details

#get_transaction_status(transaction_id) ⇒ Object



13
14
15
16
# File 'lib/payhere-sdk/inpayments.rb', line 13

def get_transaction_status(transaction_id)
  path = "/inpayments/#{transaction_id}"
  super(path)
end

#request_to_pay(phone_number, amount, processing_number = '', narration = '') ⇒ Object

This method is used to request a payment from a Payer The payer will be asked to authorize the payment. The transaction will be executed once the payer has authorized the payment. The requesttopay will be in status PENDING until the transaction is authorized or declined by the payer or it is timed out by the system. The status of the transaction can be validated by using ‘get_transation_status`



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/payhere-sdk/inpayments.rb', line 25

def request_to_pay(phone_number, amount, processing_number = '', narration = '')
  Payhere::Validate.new.validate(phone_number, amount)
  processing_number = SecureRandom.uuid unless processing_number.blank?

  body = {
    "msisdn": phone_number,
    "narration": narration,
    "processingNumber": processing_number,
    "amount": amount.to_i
  }
  path = '/inpayments'
  send_request('post', path, body)
  { transaction_reference: uuid }
end