class OffsitePayments::Integrations::Pxpay::Notification

Public Class Methods

new(query_string, options={}) click to toggle source
Calls superclass method OffsitePayments::Notification::new
# File lib/offsite_payments/integrations/pxpay.rb, line 110
def initialize(query_string, options={})
  # PxPay appends ?result=...&userid=... to whatever return_url was specified, even if that URL ended with a ?query.
  # So switch the first ? if present to a &
  query_string[/\?/] = '&' if query_string[/\?/]
  super

  @encrypted_params = @params
  @params = {}

  requires! @encrypted_params, "result"
  requires! @options, :credential1, :credential2

  decrypt_transaction_result(@encrypted_params["result"])
end

Public Instance Methods

account() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 159
def account
  @params['userid']
end
acknowledge(authcode = nil) click to toggle source

was the notification a validly formed request?

# File lib/offsite_payments/integrations/pxpay.rb, line 126
def acknowledge(authcode = nil)
  @valid == '1'
end
auth_code() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 171
def auth_code
  @params['AuthCode']
end
cancelled?() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 140
def cancelled?
  !success?
end
card_holder_name() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 179
def card_holder_name
  @params['CardHolderName']
end
card_number() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 183
def card_number
  @params['CardNumber']
end
card_type() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 175
def card_type
  @params['CardName']
end
client_ip() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 191
def client_ip
  @params['ClientInfo']
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 136
def complete?
  @params['TxnType'] == 'Purchase' && success?
end
currency() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 155
def currency
  @params['CurrencySettlement']
end
currency_input() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 167
def currency_input
  @params['CurrencyInput']
end
expiry_date() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 187
def expiry_date
  @params['DateExpiry']
end
gross() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 151
def gross
  @params['AmountSettlement']
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 163
def item_id
  @params['MerchantReference']
end
message() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 216
def message
  @params['ResponseText']
end
optional_data() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 220
def optional_data
  [@params['TxnData1'],@fields['TxnData2'],@fields['TxnData3']]
end
order_id() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 195
def order_id
  item_id
end
payer_email() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 199
def payer_email
  @params['EmailAddress']
end
received_at() click to toggle source

When was this payment was received by the client.

# File lib/offsite_payments/integrations/pxpay.rb, line 225
def received_at
  settlement_date
end
settlement_date() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 207
def settlement_date
  @params['DateSettlement']
end
status() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 130
def status
  return 'Failed' unless success?
  return 'Completed' if complete?
  'Error'
end
success?() click to toggle source

for field definitions see www.paymentexpress.com/Technical_Resources/Ecommerce_Hosted/PxPay

# File lib/offsite_payments/integrations/pxpay.rb, line 147
def success?
  @params['Success'] == '1'
end
test?() click to toggle source

Was this a test transaction?

# File lib/offsite_payments/integrations/pxpay.rb, line 230
def test?
  nil
end
transaction_id() click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 203
def transaction_id
  @params['DpsTxnRef']
end
txn_mac() click to toggle source

Indication of the uniqueness of a card number

# File lib/offsite_payments/integrations/pxpay.rb, line 212
def txn_mac
  @params['TxnMac']
end

Private Instance Methods

decrypt_transaction_result(encrypted_result) click to toggle source
# File lib/offsite_payments/integrations/pxpay.rb, line 236
def decrypt_transaction_result(encrypted_result)
  request_xml = REXML::Document.new
  root = request_xml.add_element('ProcessResponse')

  root.add_element('PxPayUserId').text = @options[:credential1]
  root.add_element('PxPayKey').text = @options[:credential2]
  root.add_element('Response').text = encrypted_result

  @raw = ssl_post(Pxpay.token_url, request_xml.to_s)

  response_xml = REXML::Document.new(@raw)
  root = REXML::XPath.first(response_xml)
  @valid = root.attributes["valid"]
  @params = {}
  root.elements.each { |e| @params[e.name] = e.text }
end