David - Musings of an SRE

Testing PaypalExpress Gateway on ActiveMerchant

Background: ActiveMerchant’s BogusGateway class which is usually used in a Test environment, does not have setup_purchase/setup_authorization method which is used in Paypal’s Express Checkout.

This gives an:

undefined method `setup_purchase' for #

When testing for controller actions that interact with ActiveMerchant’s Paypal Express Gateway.

To fix this, according to Skud, you will need to download and unpack the active_merchant and active_utils gems into your local vendor directory.

/webapps/myapp/$ gem unpack /path/to/activemerchant-1.x.x.gem --target vendor/gems
/webapps/myapp/$ gem unpack /path/to/active_utils-1.x.x.gem --target vendor/gems

Once that is done, copy paypal_bogus.rb into ../vendor/gems/activemerchant-1.x.x/lib/active_merchant/billing/gateways/paypal_bogus.rb

This is taken from sideshowcoder’s pull request that was rejected by active_merchant’s maintainers.

Next in /webapps/myapp/config/environments/test.rb, replace the following (or whatever variant you have)

::EXPRESS_GATEWAY = ActiveMerchant::Billing::BogusGateway.new

with

::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalBogusGateway.new

Source: Infotrope.net