[英]How can I resolve the 10007 - “permission denied” PayPal API error using the paypal-express gem in ruby on rails
我在我的ruby on rails項目中使用了paypal-express寶石。 我希望用戶能夠在我的Web應用程序上購買數字商品。 我創建了一個帶有new和create動作的控制器。 new
操作將生成用戶訪問的PayPal鏈接。 用戶從貝寶(PayPal)返回到我嘗試完成訂單的create
操作。
使用沙盒憑據時,開發過程中一切正常,使用生產憑據時,我從PayPal收到“ 10007-權限被拒絕”錯誤。
我已對輸入的用於生產的用戶名/密碼/ API簽名進行了三重檢查,它們是正確的(將用戶發送到正確的PayPal商店)。
這是我的控制器:
class DigitalPaymentsController < ApplicationController
before_filter :authenticate_user!, :only => [ :new, :create ]
def new
Paypal.sandbox! unless Rails.env.production?
response = paypal_request.setup(
payment_request,
success_url,
cancel_url,
:no_shipping => true
)
@paypal_url = response.redirect_uri
end
def create
begin
response = paypal_request.checkout!(params[:token], params[:PayerID], payment_request)
if response.payment_info.first.payment_status == 'Completed'
# TODO: Handle complete payments
else
# TODO: Handle non complete payments
end
rescue Paypal::Exception::APIError => e
# Payment has failed, failure details are in e.message, also check params
end
end
private
def paypal_request
@request ||= Paypal::Express::Request.new(
:username => PAYPAL_USERNAME,
:password => PAYPAL_PASSWORD,
:signature => PAYPAL_SIGNATURE
)
end
def payment_request
@payment_request ||= Paypal::Payment::Request.new(
:currency_code => :USD,
:amount => 15,
:items => [{
:name => "Awesome Product",
:description => 'Description of awesomeness',
:amount => 15,
:category => :Digital
}]
)
end
end
在看看到貝寶快遞的寶石,好像叫DoExpressCheckoutPayment
的PayPal API並通過PayerID和令牌。 PayPal API文檔未列出解決我的錯誤的方法(10007)。
PayPal API錯誤的原因是,我需要在簽出交易之前調用PayPal GetExpressCheckoutDetails
操作。 我是通過在此處添加來自paypal-express gem Wiki的一行來做到這一點的: https : //github.com/nov/paypal-express/wiki/Instant-Payment
我需要的只是paypal_request.details(params[:token])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.