class WebpayInterswitch::TransactionQuery

This class can be used to fetch transaction details Initialization Parameters:

post_params: Parameters sent via POST by the gateway at the redirect_url amount: This is needed to detect the masquerading or parameter tampering to alter the amount. WebpayInterswitch::TransactionQuery.new(params, amount)

Constants

LIVE_URL
TEST_URL

Attributes

amount[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

cardNum[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

desc[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

payRef[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

resp[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

response[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

retRef[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

txnref[RW]

resp and desc are empty when transaction is successful txnref is the unique number sent in request. cardNum is always zero apprAmt is always zero response is populated when a transactions search query is sent.

Public Class Methods

new(post_params={}, amount) click to toggle source
# File lib/webpay_interswitch/transaction_query.rb, line 29
def initialize(post_params={}, amount)
  post_params.to_hash.symbolize_keys!
  post_params.each_pair do |key, val|
    instance_variable_set("@#{key}", val)
  end
  @amount = amount
  fetch_response
end

Public Instance Methods

error_message() click to toggle source

Returns error message if present. Else returns a blank string. This is generally due to incorrect parameters such as product_id, pay_item_id etc.

# File lib/webpay_interswitch/transaction_query.rb, line 59
def error_message
  @desc.strip.gsub(',', '')
end
fetch_response() click to toggle source

fetches a returns a transaction as json

# File lib/webpay_interswitch/transaction_query.rb, line 39
def fetch_response
  uri              = URI.parse(make_request)
  http             = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl     = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  @response = JSON.parse http.get(uri.request_uri, { 'Hash' => sha_hash(string_for_get_query) }).body
end
full_error_message() click to toggle source
# File lib/webpay_interswitch/transaction_query.rb, line 53
def full_error_message
  "#{ error_message }. #{ query_error_message }"
end
query_error_message() click to toggle source

Returns error message recd from the gateway if the txn query was failed. else, returns nil This is due to: incorrect amount, invalid card number etc.

# File lib/webpay_interswitch/transaction_query.rb, line 66
def query_error_message
  @response['ResponseDescription'] unless success?
end
success?() click to toggle source

Returns true or false

# File lib/webpay_interswitch/transaction_query.rb, line 49
def success?
  @response['ResponseCode'] == '00'
end
transaction_url() click to toggle source
# File lib/webpay_interswitch/transaction_query.rb, line 70
def transaction_url
  WebpayInterswitch::Gateway.test ? TEST_URL : LIVE_URL
end

Private Instance Methods

make_request() click to toggle source
# File lib/webpay_interswitch/transaction_query.rb, line 76
def make_request
  url =  transaction_url
  url += "?productid=#{WebpayInterswitch::Gateway.product_id}"
  url += "&transactionreference=#{@txnref}"
  url += "&amount=#{@amount}"
end
string_for_get_query() click to toggle source

Returns a string that is used to compute the sha hash for get transaction query on webpay.

# File lib/webpay_interswitch/transaction_query.rb, line 84
def string_for_get_query
  WebpayInterswitch::Gateway.product_id +
  @txnref.to_s +
  WebpayInterswitch::Gateway.mac_key
end