Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactor to use passed in option instead of instance method

  • Loading branch information...
commit 45682c0dfe33cfabfabad503bd3448ca03cd5b1f 1 parent 1fab5fa
Mikel Lindsaar authored
21  lib/active_merchant/billing/gateways/payment_express.rb
@@ -21,11 +21,8 @@ class PaymentExpressGateway < Gateway
21 21
       self.homepage_url = 'http://www.paymentexpress.com/'
22 22
       self.display_name = 'PaymentExpress'
23 23
       
24  
-      # Use "BillingId" for the Token type.  If set to false, then the token will be sent
25  
-      # as the DPS specified "DpsBillingId".  This is per the documentation at
26  
-      # http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling
27  
-      attr_accessor :use_billing_id_for_token
28  
-      alias :use_billing_id_for_token? :use_billing_id_for_token
  24
+      attr_reader :use_custom_payment_token
  25
+      alias :use_custom_payment_token? :use_custom_payment_token
29 26
 
30 27
       URL = 'https://sec.paymentexpress.com/pxpost.aspx'
31 28
       
@@ -41,8 +38,12 @@ class PaymentExpressGateway < Gateway
41 38
       
42 39
       # We require the DPS gateway username and password when the object is created.
43 40
       def initialize(options = {})
44  
-        # A DPS username and password must exist 
  41
+        # A DPS username and password must exist
45 42
         requires!(options, :login, :password)
  43
+        # Use "BillingId" for the Token type.  If set to false, then the token will be sent
  44
+        # as the DPS specified "DpsBillingId".  This is per the documentation at
  45
+        # http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling
  46
+        @use_custom_payment_token = !!options[:use_custom_payment_token]
46 47
         # Make the options an instance variable
47 48
         @options = options
48 49
         super
@@ -107,14 +108,14 @@ def credit(money, identification, options = {})
107 108
       # Firstly, pass in a `:billing_id` as an option in the hash of this store method.  No
108 109
       # validation is done on this BillingId by PaymentExpress so you must ensure that it is unique.
109 110
       #
110  
-      # Secondly, you will need to pass in the option `{:use_billing_id_for_token => true}` when
  111
+      # Secondly, you will need to pass in the option `{:use_custom_payment_token => true}` when
111 112
       # initializing your gateway instance, like so:
112 113
       #
113 114
       #     gateway = ActiveMerchant::Billing::PaymentExpressGateway.new(
114 115
       #       :login    => 'USERNAME',
115  
-      #       :password => 'PASSWORD'
  116
+      #       :password => 'PASSWORD',
  117
+      #       :use_custom_payment_token => true
116 118
       #     )
117  
-      #     gateway.use_billing_id_for_token = true
118 119
       #
119 120
       # see: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling
120 121
       #
@@ -183,7 +184,7 @@ def add_credit_card(xml, credit_card)
183 184
       end
184 185
       
185 186
       def add_billing_token(xml, token)
186  
-        if use_billing_id_for_token?
  187
+        if use_custom_payment_token?
187 188
           xml.add_element("BillingId").text = token
188 189
         else
189 190
           xml.add_element("DpsBillingId").text = token
2  test/unit/gateways/payment_express_test.rb
@@ -102,7 +102,7 @@ def test_purchase_using_merchant_specified_billing_id_token
102 102
     @gateway = PaymentExpressGateway.new(
103 103
       :login => 'LOGIN',
104 104
       :password => 'PASSWORD',
105  
-      :use_billing_id_for_token => true
  105
+      :use_custom_payment_token => true
106 106
     )
107 107
 
108 108
     @gateway.expects(:ssl_post).returns( successful_store_response({:billing_id => 'TEST1234'}) )

0 notes on commit 45682c0

Please sign in to comment.
Something went wrong with that request. Please try again.