Skip to content

Instantly share code, notes, and snippets.

@vesan
Created November 23, 2014 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vesan/49b7fe4b0f7a2eb74a21 to your computer and use it in GitHub Desktop.
Save vesan/49b7fe4b0f7a2eb74a21 to your computer and use it in GitHub Desktop.
ActiveMerchant testing gateway for Paypal Express
# from: https://github.com/sideshowcoder/active_merchant/blob/192f49762172dc41450d7a3605158d45eb55b83b/lib/active_merchant/billing/gateways/paypal_bogus.rb
require File.dirname(__FILE__) + '/paypal/paypal_common_api'
require File.dirname(__FILE__) + '/paypal/paypal_express_response'
require File.dirname(__FILE__) + '/paypal_express_common'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalBogusGateway < BogusGateway
REDIRECT_URL = "https://bogus.paypal.com"
def setup_authorization money, options = {}
requires!(options, :return_url, :cancel_return_url)
PaypalExpressResponse.new true, SUCCESS_MESSAGE, { Token: AUTHORIZATION }, test: true
end
def setup_purchase money, options = {}
requires!(options, :return_url, :cancel_return_url)
PaypalExpressResponse.new true, SUCCESS_MESSAGE, { Token: AUTHORIZATION }, test: true
end
def authorize money, options = {}
requires!(options, :token, :payer_id)
case normalize(options[:token])
when '1'
PaypalExpressResponse.new false, FAILURE_MESSAGE, {:authorized_amount => money}, :test => true
else
PaypalExpressResponse.new true, SUCCESS_MESSAGE, {:authorized_amount => money}, :test => true, :authorization => AUTHORIZATION
end
end
def purchase money, options = {}
requires!(options, :token, :payer_id)
case normalize(options[:token])
when '1'
PaypalExpressResponse.new false, FAILURE_MESSAGE, {:amount => money}, :test => true
else
PaypalExpressResponse.new true, SUCCESS_MESSAGE, {:amount => money}, :test => true, :authorization => AUTHORIZATION
end
end
def redirect_url_for token
REDIRECT_URL
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment