尽管遵循了implementation guide信件,我仍然遇到以下错误:
PayPal::SDK::Core::Exceptions::MethodNotAllowed in SiteController#execute_payment
Failed. Response code = 405. Response message = Method Not Allowed.
这是违规行:
@payment.execute( :payer_id => params[:PayerID] )
我做错了什么? (这是我的控制者):
class SiteController < ApplicationController
def index
end
def create_payment
payment = PayPal::SDK::REST::Payment.new({
:intent => "sale",
:payer => {
:payment_method => "paypal" },
:redirect_urls => {
:return_url => execute_payment_url,
:cancel_url => "https://devtools-paypal.com/guide/pay_paypal/ruby?cancel=true" },
:transactions => [ {
:amount => {
:total => "12",
:currency => "USD" },
:description => "creating a payment" } ] } )
payment.transactions[0].item_list.items[0] = {
quantity: 1,
name: 'Poop',
price: 12,
currency: 'USD'
}
if payment.create
session[:payment_id] = payment.id
redirect_to payment.links[1].href
end
end
def execute_payment
@payment = PayPal::SDK::REST::Payment.new({
:payment_id => session[:payment_id]})
@payment.execute( :payer_id => params[:PayerID] )
end
end
答案 0 :(得分:0)
您应该使用find ..更改:
,而不是创建新的付款 @payment = PayPal::SDK::REST::Payment.new({
:payment_id => session[:payment_id]})
到
@payment = PayPal::SDK::REST::Payment.find(session[:payment_id])
这解决了我的代码副本中的问题。