【发布时间】:2013-02-13 08:14:03
【问题描述】:
有没有办法模拟购买PaypalExpressGateway
我使用了两个操作来处理 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)
我还没有找到任何方法来实现这一点,所以这可能会对他们中的许多人有所帮助...
除此之外的任何更好的解决方案将不胜感激
提前致谢
【问题讨论】:
标签: ruby-on-rails-3 unit-testing paypal functional-testing activemerchant