Paypal REST API在转向生产时出现401错误

时间:2015-12-09 21:13:36

标签: ruby-on-rails ruby heroku paypal

我们正在尝试在Ruby on Rails中使用Paypal的REST API,它在沙盒中完美运行。 当我们搬到生产区时,它突然不起作用。这是来自heroku的日志:

Started POST "/transfer/payments/start_payment" for 77.127.249.103 at 2015-12-09 21:05:37 +0000
2015-12-09T21:05:37.709999+00:00 app[web.1]: Request[post]: https://api.paypal.com/v1/oauth2/token
2015-12-09T21:05:38.383206+00:00 app[web.1]: Response[401]: Unauthorized, Duration: 0.673s
2015-12-09T21:05:38.396230+00:00 app[web.1]: 
2015-12-09T21:05:38.396233+00:00 app[web.1]: PayPal::SDK::Core::Exceptions::UnauthorizedAccess (Failed.  Response code = 401.  Response message = Unauthorized.  Response debug ID = 9287826b548af.):
2015-12-09T21:05:38.396234+00:00 app[web.1]:   app/controllers/transfer/payments_controller.rb:23:in `start_payment'
2015-12-09T21:05:38.396234+00:00 app[web.1]: 
2015-12-09T21:05:38.396235+00:00 app[web.1]: 
2015-12-09T21:05:38.394396+00:00 app[web.1]: Completed 500 Internal Server Error in 1020ms (ActiveRecord: 23.9ms)
2015-12-09T21:05:38.394396+00:00 app[web.1]: Completed 500 Internal Server Error in 1020ms (ActiveRecord: 23.9ms)

我们的代码是:

def start_payment
            @payment = Payment.new(payment_params)
            @paypal_payment = PayPal::SDK::REST::Payment.new({
                :intent => "sale",
                :payer => {
                :payment_method => "paypal" },
                :redirect_urls => {
                :return_url => root_url + transfer_payments_path,
                :cancel_url => "https://devtools-paypal.com/guide/pay_paypal/ruby?cancel=true" },
                :transactions => [ {
                    :amount => {
                    :total => sprintf('%.2f', @payment.amount),
                    :currency => "USD" 
                    },
                    :description => "Bounty Balance" 
                    } ]              
                })
            @paypal_payment.create

            index = @paypal_payment.links.find_index {|item| item.rel == "approval_url"}
            link = @paypal_payment.links[index]
            redirect_to link.href
        end 

我们在paypal.com上查了一下,我们在paypal的相关服务旁边有绿色复选标记 - 我们唯一没有的是直接信用卡,未来付款和付款。

任何人都知道问题可能是什么?

0 个答案:

没有答案