【发布时间】:2018-05-22 19:20:44
【问题描述】:
我在将 paypal 支付网关与 rails 集成时遇到问题。我将在下面解释我所做的步骤。
我首先去了 developer.paypal.com
我创建了两个沙盒帐户,一个用于买家,一个用于企业帐户。
我将企业帐户更改为 Business-Pro
然后我在 rails 中安装了 activemerchant gem。
在 config/environments/development.rb 我粘贴了以下块
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
login: "aGthYkgkYXVA_api1.gmail.com",
password: "DH2RB21WR2EWNSTM",
signature: "ApBHX2qbpxJW-Ll3oP22LSao0WeuAT.A.uNyDDqIArQeMLYzMTqsZnCW"
}
::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
end
然后在控制器中我创建了一个测试方法并粘贴了代码来进行结帐
# ActiveMerchant accepts all amounts as Integer values in cents
amount = 1000 # $10.00
# The card verification value is also known as CVV2, CVC2, or CID
credit_card = ActiveMerchant::Billing::CreditCard.new(
:brand => 'visa',
:first_name => 'Bob',
:last_name => 'Bobsen',
:number => '4132033791119477',
:month => 3,
:year => 2022,
:verification_value => '123')
# Validating the card automatically detects the card type
if credit_card.validate.empty?
# Capture $10 from the credit card
response = GATEWAY.purchase(amount, credit_card, :ip => '128.1.1.1')
if response.success?
puts "Successfully charged $#{sprintf("%.2f", amount / 100)} to the credit card #{credit_card.display_number}"
else
raise StandardError, response.message
end
end
当我执行控制器方法时,我得到以下错误
无法处理此交易。商户账号不 能够处理交易。
我想知道这个错误的原因。
我使用了我在上面创建的买家沙盒帐户中的信用卡号和过期日期。
感谢您的帮助!
【问题讨论】:
-
快速-那些凭据肯定都是基于沙盒的,是吗?就个人而言,无论如何我都会编辑它们:)
标签: ruby-on-rails ruby paypal payment-gateway activemerchant