我在我的 ruby on rails 项目中使用了paypal-express gem。我希望用户能够在我的 Web 应用程序上购买数字商品。我创建了一个带有新和创建操作的控制器。该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
查看 paypal-express gem,它似乎调用DoExpressCheckoutPayment
了 PayPal API 并传递了 PayerID 和令牌。PayPal API 文档没有列出解决我的错误 (10007) 的方法。