有没有办法模拟购买 PaypalExpressGateway
我对 PayPal 付款处理使用了两个操作,第一个操作将用户带到 paypal 沙箱登录,并将重定向回我的应用程序以进行付款确认
但是该PAYPAL_GATEWAY.purchase
方法不成功并返回错误消息Payment has not been authorized by the user.
好吧,我想这是由于跳过了授权用户购买的步骤
有没有办法我可以伪造或模拟 PayPal 来接受交易?
我ActionController::TestCase
要测试这些操作products#initiate_payment
products#confirm_payment
将这些操作称为
post :initiate_payment, initiate_payment_action_params(@product)
get :confirm_payment, confirm_action_params(@product, product_purchased, paypal_token)
并设置贝宝回调响应,然后重定向到贝宝登录
@setup_response = PAYPAL_GATEWAY.setup_purchase(amount, ip: request.remote_ip,
items: [{name: @product.name, quantity: 1, description: @product.description, amount: amount}],
currency: 'USD',
return_url: url_for(action: 'confirm_payment',
product_purchased: @product_purchased.id,
only_path: false),
cancel_return_url: url_for(action: 'index',
product_purchased: @product_purchased.id,
only_path: false))
redirect_to PAYPAL_GATEWAY.redirect_url_for(@setup_response.token)
我已经在我的操作中处理了购买交易,我products#confirm_payment
将 confirm_payment 的参数模拟为
{"product_purchased"=>"10", "token"=>"EC-91J25480XA799581U", "PayerID"=>"4QBC9Y658K6MA", "id"=>"55", "controller"=>"products", "action"=>"confirm_payment"}
get :confirm_payment, confirm_action_params(@product, product_purchased, paypal_token)
PAYPAL_GATEWAY 的配置
PAYPAL_GATEWAY ||= ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
我还没有找到任何方法来实现这一点,所以这可能会帮助他们中的许多人......
除此以外的任何更好的解决方案将不胜感激
提前致谢