Class: Paylense::Collections

Inherits:
Client
  • Object
show all
Defined in:
lib/paylense-sdk/collections.rb

Instance Method Summary collapse

Methods inherited from Client

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

Instance Method Details

#request_to_pay(api_key, account_number, amount, merchant_reference, payment_method, provider, currency, encrypted_card = '', narration = '', account_name = '', account_email = '', redirect_url = '', callback_url = '') ⇒ 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 request to pay 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 is received via the webhook



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/paylense-sdk/collections.rb', line 20

def request_to_pay(api_key,, amount, merchant_reference, payment_method, provider, currency,
                   encrypted_card ='', narration = '',  = '',  ='', redirect_url = '', callback_url = '')
  Paylense::Validate.new.validate(, amount)
  merchant_reference = SecureRandom.uuid unless merchant_reference.blank?

  body = {
    "account_number": ,
    "narration": narration,
    "merchant_reference": merchant_reference,
    "amount": amount.to_i,
    "api_key": api_key,
    "payment_method": payment_method,
    "provider": provider,
    "currency": currency,
    "encrypted_card": encrypted_card,
    "account_name": ,
    "account_email": ,
    "redirect_url": redirect_url,
    "callback_url": callback_url
  }
  path = '/request-to-pay'
  send_request('collections', 'post', path, body)
  #{ transaction_reference: uuid }
end