Skip to content

Commit

Permalink
Refactor to use passed in option instead of instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikel Lindsaar committed Apr 10, 2012
1 parent 1fab5fa commit 45682c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions lib/active_merchant/billing/gateways/payment_express.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ class PaymentExpressGateway < Gateway
self.homepage_url = 'http://www.paymentexpress.com/' self.homepage_url = 'http://www.paymentexpress.com/'
self.display_name = 'PaymentExpress' self.display_name = 'PaymentExpress'


# Use "BillingId" for the Token type. If set to false, then the token will be sent attr_reader :use_custom_payment_token
# as the DPS specified "DpsBillingId". This is per the documentation at alias :use_custom_payment_token? :use_custom_payment_token
# http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling
attr_accessor :use_billing_id_for_token
alias :use_billing_id_for_token? :use_billing_id_for_token


URL = 'https://sec.paymentexpress.com/pxpost.aspx' URL = 'https://sec.paymentexpress.com/pxpost.aspx'


Expand All @@ -41,8 +38,12 @@ class PaymentExpressGateway < Gateway


# We require the DPS gateway username and password when the object is created. # We require the DPS gateway username and password when the object is created.
def initialize(options = {}) def initialize(options = {})
# A DPS username and password must exist # A DPS username and password must exist
requires!(options, :login, :password) requires!(options, :login, :password)
# Use "BillingId" for the Token type. If set to false, then the token will be sent
# as the DPS specified "DpsBillingId". This is per the documentation at
# http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling
@use_custom_payment_token = !!options[:use_custom_payment_token]
# Make the options an instance variable # Make the options an instance variable
@options = options @options = options
super super
Expand Down Expand Up @@ -107,14 +108,14 @@ def credit(money, identification, options = {})
# Firstly, pass in a `:billing_id` as an option in the hash of this store method. No # Firstly, pass in a `:billing_id` as an option in the hash of this store method. No
# validation is done on this BillingId by PaymentExpress so you must ensure that it is unique. # validation is done on this BillingId by PaymentExpress so you must ensure that it is unique.
# #
# Secondly, you will need to pass in the option `{:use_billing_id_for_token => true}` when # Secondly, you will need to pass in the option `{:use_custom_payment_token => true}` when
# initializing your gateway instance, like so: # initializing your gateway instance, like so:
# #
# gateway = ActiveMerchant::Billing::PaymentExpressGateway.new( # gateway = ActiveMerchant::Billing::PaymentExpressGateway.new(
# :login => 'USERNAME', # :login => 'USERNAME',
# :password => 'PASSWORD' # :password => 'PASSWORD',
# :use_custom_payment_token => true
# ) # )
# gateway.use_billing_id_for_token = true
# #
# see: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling # see: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling
# #
Expand Down Expand Up @@ -183,7 +184,7 @@ def add_credit_card(xml, credit_card)
end end


def add_billing_token(xml, token) def add_billing_token(xml, token)
if use_billing_id_for_token? if use_custom_payment_token?
xml.add_element("BillingId").text = token xml.add_element("BillingId").text = token
else else
xml.add_element("DpsBillingId").text = token xml.add_element("DpsBillingId").text = token
Expand Down
2 changes: 1 addition & 1 deletion test/unit/gateways/payment_express_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_purchase_using_merchant_specified_billing_id_token
@gateway = PaymentExpressGateway.new( @gateway = PaymentExpressGateway.new(
:login => 'LOGIN', :login => 'LOGIN',
:password => 'PASSWORD', :password => 'PASSWORD',
:use_billing_id_for_token => true :use_custom_payment_token => true
) )


@gateway.expects(:ssl_post).returns( successful_store_response({:billing_id => 'TEST1234'}) ) @gateway.expects(:ssl_post).returns( successful_store_response({:billing_id => 'TEST1234'}) )
Expand Down

0 comments on commit 45682c0

Please sign in to comment.