环境:
ruby 1.9.2
rails 3.2.8
gem 'ActiveMerchant' 1.34.1
我想使用 Paypal 定期付款选项作为自动续订选项。
为此,我使用 Paypal 付款选项,该选项转到 paypal 网站以允许用户登录并确认付款,然后进行处理。
正常付款(不是经常性付款)工作正常。 对于正常付款,我使用:
在类里面:
ActiveMerchant::Billing::Base.mode = :test
@@paypal_express_gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
:login => 'my_login_id@domail.com',
:password => 'password',
:signature => 'Signature'
)
在express_checkout
方法:
setup_response = @@paypal_express_gateway.setup_purchase(@@amount,
:ip => request.remote_ip,
:return_url => url_for(:action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:action => 'new', :only_path => false)
)
redirect_to @@paypal_express_gateway.redirect_url_for(setup_response.token)
在confirm
方法:
details_response = @@paypal_express_gateway.details_for(params[:token])
然后details_response
返回成功方法 true
或 false
.然后我将它发送到完成或错误页面。 这是我想要的定期付款。
对于使用 PaypalExpressCheckout 的定期付款,我使用了以下内容:
在类里面:
ActiveMerchant::Billing::Base.mode = :test
@@paypal_express_gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
:login => 'my_login_id@domail.com',
:password => 'password',
:signature => 'Signature'
)
在express_checkout
方法:
setup_response = @@paypal_express_gateway.setup_purchase(@@amount, <br>
:ip => request.remote_ip, <br>
:return_url => url_for(:action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:action => 'new', :only_path => false)
)
redirect_to @@paypal_express_gateway.redirect_url_for(setup_response.token)
在confirm
方法:
details_response = @@paypal_express_gateway.recurring(@@amount, "", options = {
:token => params[:token],
:period => "Month",
:frequency => 3,
:start_date => Time.now,
:description => "Checking recurring auto-renewal"
})
现在我收到错误 undefined method "add_credit_card" for #<ActiveMerchant::Billing::PaypalExpressGateway:0x00000006c831a0>
循环方法定义Here (Active Merchant)这将返回 profile_id。
所以我想使用 PaypalExpressGateway(而不是 PaypalGateway)进行定期付款,开发人员无法将信用卡详细信息发送到定期付款方式,因为付款是在 Paypal 网站上完成的。
那么为什么在 PaypalExpressGateway 中使用 credit_card 参数。以及 recurring
调用的方法“build_create_profile_request(options)”方法不应检查 credit_card,因为我没有在选项中传递任何参数“credit_card”。(参见给定 link 中的第 127 行)
请检查代码,让我知道哪里错了。 如果有人可以向我提供准备好的代码,那么它会更有用。
我尝试了很多博客和解决方案但都没有成功。 请尽快给我解决方案。
最佳答案
我使用 ActiveMerchant 进行定期 PayPal 付款。您需要将 nil
而不是空字符串作为第二个参数(它是表示信用卡对象的某种对象,但我不认为是为 ActiveMerchant 的 PayPal Express Checkout 集成实现的)传递给循环
方法。
details_response = @@paypal_express_gateway.recurring(@@amount, nil, {
:token => params[:token],
:period => "Month",
:frequency => 3,
:start_date => Time.now,
:description => "Checking recurring auto-renewal"
})
关于ruby-on-rails - PaypalExpressGateway 上的 Activemerchant Paypal 重复付款错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17742782/