Class: WebpayInterswitch::TransactionQuery

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/webpay_interswitch/transaction_query.rb

Constant Summary collapse

TEST_URL =
'https://sandbox.interswitchng.com/webpay/api/v1/gettransaction.json'
LIVE_URL =
'https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core

#sha_hash

Constructor Details

#initialize(post_params = {}, amount) ⇒ TransactionQuery

Returns a new instance of TransactionQuery.



29
30
31
32
33
34
35
36
# 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

Instance Attribute Details

#amountObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def amount
  @amount
end

#cardNumObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def cardNum
  @cardNum
end

#descObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def desc
  @desc
end

#payRefObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def payRef
  @payRef
end

#respObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def resp
  @resp
end

#responseObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def response
  @response
end

#retRefObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def retRef
  @retRef
end

#txnrefObject

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.



23
24
25
# File 'lib/webpay_interswitch/transaction_query.rb', line 23

def txnref
  @txnref
end

Instance Method Details

#error_messageObject

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.



59
60
61
# File 'lib/webpay_interswitch/transaction_query.rb', line 59

def error_message
  @desc.strip.gsub(',', '')
end

#fetch_responseObject

fetches a returns a transaction as json



39
40
41
42
43
44
45
46
# 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_messageObject



53
54
55
# File 'lib/webpay_interswitch/transaction_query.rb', line 53

def full_error_message
  "#{ error_message }. #{ query_error_message }"
end

#query_error_messageObject

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.



66
67
68
# File 'lib/webpay_interswitch/transaction_query.rb', line 66

def query_error_message
  @response['ResponseDescription'] unless success?
end

#success?Boolean

Returns true or false

Returns:

  • (Boolean)


49
50
51
# File 'lib/webpay_interswitch/transaction_query.rb', line 49

def success?
  @response['ResponseCode'] == '00'
end

#transaction_urlObject



70
71
72
# File 'lib/webpay_interswitch/transaction_query.rb', line 70

def transaction_url
  WebpayInterswitch::Gateway.test ? TEST_URL : LIVE_URL
end