有没有办法模拟购买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)
我还没有找到实现此目标的任何方法,因此这可能对许多人有帮助...
除此以外的任何更好的解决方案将不胜感激
提前致谢
最佳答案
简短的答案是,您将必须逐步进行测试购买。另外,这将使您从头到尾经历买方所经历的经历。您是否有特定原因要跳过一两个步骤?
一些商家也将只浏览流程一次,捕获返回的信息,然后仅使用相同的字符串来创建一个表单页面,然后将其用于将信息发布回其页面以进行测试。这样,他们不必一遍又一遍地进行工作,但这取决于您的设置,这可能会或可能不会起作用。
最典型的是使用选项A,并从头到尾进行整个流程。
关于ruby-on-rails-3 - ActionController::TestCase模拟PayPal购买,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15113497/