Class: ActiveMerchant::Billing::Integrations::Pxpay::Helper

Inherits:
Helper
  • Object
show all
Includes:
PostsData
Defined in:
lib/active_merchant/billing/integrations/pxpay/helper.rb

Overview

An example. Note the username as a parameter and transaction key you will want to use later. The amount that you pass in will be rounded, so preferably pass in X.2 decimal so that no rounding occurs. You need to set :credential2 to your PxPay secret key.

PxPay accounts have Failproof Notification enabled by default which means in addition to the user being redirected to your return_url, the return_url will be accessed by the PxPay servers directly, immediately after transaction success.

payment_service_for('order_id', 'pxpay_user_ID', :service => :pxpay, 
                     :amount => 157.0, :currency => 'USD', :credential2 => 'pxpay_key') do |service|

 service.customer :email => '[email protected]'

 service.description 'Order 123 for MyStore'

 # Must specify both a return_url or PxPay will show an error instead of
 # capturing credit card details.

 service.return_url "http://t/pxpay/payment_received_notification_sub_step"

 # These fields will be copied verbatim to the Notification
 service.custom1 'custom text 1'
 service.custom2 ''
 service.custom3 ''
 # See the helper.rb file for various custom fields

end

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.



48
49
50
51
52
53
# File 'lib/active_merchant/billing/integrations/pxpay/helper.rb', line 48

def initialize(order, , options = {})
  super
  add_field 'AmountInput', "%.2f" % options[:amount].to_f.round(2)
  add_field 'EnableAddBillCard', '0'
  add_field 'TxnType', 'Purchase'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Instance Method Details

#form_fieldsObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_merchant/billing/integrations/pxpay/helper.rb', line 60

def form_fields
  # if either return URLs are blank PxPay will generate a token but redirect user to error page.
  raise "error - must specify return_url" if @fields['UrlSuccess'].blank?
  raise "error - must specify cancel_return_url" if @fields['UrlFail'].blank?

  result = request_secure_redirect
  raise "error - failed to get token - message was #{result[:redirect]}" unless result[:valid] == "1"

  url = URI.parse(result[:redirect])

  CGI.parse(url.query)
end

#form_methodObject



73
74
75
# File 'lib/active_merchant/billing/integrations/pxpay/helper.rb', line 73

def form_method
  "GET"
end

#return_url(url) ⇒ Object



55
56
57
58
# File 'lib/active_merchant/billing/integrations/pxpay/helper.rb', line 55

def return_url(url)
  add_field 'UrlSuccess', url
  add_field 'UrlFail', url
end