Class: OffsitePayments::Integrations::Pxpay::Helper

Inherits:
Helper
  • Object
show all
Includes:
ActiveUtils::PostsData
Defined in:
lib/offsite_payments/integrations/pxpay.rb

Instance Attribute Summary collapse

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

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

Constructor Details

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

Returns a new instance of Helper.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/offsite_payments/integrations/pxpay.rb', line 23

def initialize(order, , options = {})
  @token_parameters = {
    'PxPayUserId'       => ,
    'PxPayKey'          => options[:credential2],
    'CurrencyInput'     => options[:currency],
    'MerchantReference' => order,
    'EmailAddress'      => options[:customer_email],
    'TxnData1'          => options[:custom1],
    'TxnData2'          => options[:custom2],
    'TxnData3'          => options[:custom3],
    'AmountInput'       => "%.2f" % options[:amount].to_f.round(2),
    'EnableAddBillCard' => '0',
    'TxnType'           => 'Purchase',
    'UrlSuccess'        => options[:return_url],
    'UrlFail'           => options[:return_url]
  }
  @redirect_parameters = {}

  super

  raise ArgumentError, "error - must specify return_url"        if token_parameters['UrlSuccess'].blank?
  raise ArgumentError, "error - must specify cancel_return_url" if token_parameters['UrlFail'].blank?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper

Instance Attribute Details

#redirect_parametersObject (readonly)

Returns the value of attribute redirect_parameters.



21
22
23
# File 'lib/offsite_payments/integrations/pxpay.rb', line 21

def redirect_parameters
  @redirect_parameters
end

#token_parametersObject (readonly)

Returns the value of attribute token_parameters.



21
22
23
# File 'lib/offsite_payments/integrations/pxpay.rb', line 21

def token_parameters
  @token_parameters
end

Instance Method Details

#credential_based_urlObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/offsite_payments/integrations/pxpay.rb', line 47

def credential_based_url
  raw_response = ssl_post(Pxpay.token_url, generate_request)
  result = parse_response(raw_response)

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

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

  if url.query
    @redirect_parameters = CGI.parse(url.query)
    url.query = nil
  end

  url.to_s
rescue ActiveUtils::ConnectionError
  raise ActionViewHelperError, "A connection error occurred while contacting the payment gateway. Please try again."
end

#form_fieldsObject



69
70
71
# File 'lib/offsite_payments/integrations/pxpay.rb', line 69

def form_fields
  redirect_parameters
end

#form_methodObject



65
66
67
# File 'lib/offsite_payments/integrations/pxpay.rb', line 65

def form_method
  "GET"
end