Module: Pesapal::Helper::Status

Defined in:
lib/pesapal/helper/status.rb

Overview

Contains helper methods relating to any queries for transaction payment status. See Merchant#query_payment_status source.

Class Method Summary collapse

Class Method Details

.set_parameters(consumer_key, merchant_reference, transaction_tracking_id = nil) ⇒ Hash

Prepares parameters to be used during the QueryPaymentStatus and QueryPaymentStatusByMerchantRef oAuth 1.0 calls.

The QueryPaymentStatus and QueryPaymentStatusByMerchantRef oAuth 1.0 calls require the following parameters;

  1. oauth_consumer_key - your Pesapal consumer key sent to you via email or obtained from the dashboard
  2. oauth_nonce - a random string, uniquely generated for each request. See section 8 of the oAuth 1.0 spec
  3. oauth_signature - the signature as defined in the oAuth 1.0 spec under section 9 of the oAuth 1.0 spec
  4. oauth_signature_method - HMAC-SHA1 (do not change). See section 9.2 of the oAuth 1.0 spec
  5. oauth_timestamp - number of seconds since January 1, 1970 00:00:00 GMT, also known as Unix Time. See section 8 of the oAuth 1.0 spec
  6. oauth_version - 1.0 (do not change)
  7. pesapal_merchant_reference - the transaction merchant reference (same as merchant_reference defined below)
  8. pesapal_transaction_tracking_id - the transaction tracking id (same as transaction_tracking_id defined below)

This method generates all the above except the oauth_signature which is generated later by Oauth.generate_oauth_signature since generation of this oauth_signature requires these parameters as inputs anyway. See section 9.2.1 of the oAuth 1.0 spec for more details.

Parameters:

  • consumer_key (String)

    your Pesapal consumer key sent to you via email or obtained from the dashboard

  • merchant_reference (String)

    the unique id generated for the transaction by your application before posting the order

  • transaction_tracking_id (String) (defaults to: nil)

    the unique id assigned by Pesapal to the transaction after it's posted

Returns:

  • (Hash)

    parameters to be used in generating the oAuth 1.0 URL query parameters and the oauth_signature itself.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pesapal/helper/status.rb', line 40

def self.set_parameters(consumer_key, merchant_reference, transaction_tracking_id = nil)
  timestamp = Time.now.to_i.to_s
  params = { oauth_consumer_key: consumer_key,
             oauth_nonce: "#{timestamp}" + Pesapal::Oauth.generate_nonce(12),
             oauth_signature_method: 'HMAC-SHA1',
             oauth_timestamp: "#{timestamp}",
             oauth_version: '1.0',
             pesapal_merchant_reference: merchant_reference
          }
  params[:pesapal_transaction_tracking_id] = transaction_tracking_id unless transaction_tracking_id.nil?
  params
end