我有一个简单的 Rails 网站,我现在需要向其添加支付网关。我看到一个railscast on integrating activemerchant with paypal但我想改用 braintree。
我找不到任何说明如何将 braintree 端到端集成到 Rails 应用程序的教程。我看到人们对 braintree 有很多好话要说,但是教程怎么样?
有人在他们的 Rails 应用程序中使用过这个支付网关吗?它会类似于带有 paypal 的 railscasts 吗...只需将 paypal 替换为 braintree 即可?
最佳答案
Active Merchant 是一个更加灵活的选择,因为它使您的公司可以自由更改网关,而无需对代码进行重大更改。最初的问题是如何将其与 Active Merchant 集成,而不是如何使用 BT 的专有 API。这是我在深入研究代码后找到的答案。您可以在“账户”->“我的用户”->“API Keys”中找到您的公钥、私钥和商家ID。
gateway = ActiveMerchant::Billing::BraintreeGateway.new(
:merchant_id => 'Your Merchant ID',
:public_key => 'Your Public Key',
:private_key => 'Your Private Key'
)
creditcard = ActiveMerchant::Billing::CreditCard.new(
:type => 'visa',
:number => '41111111111111111',
:month => 10,
:year => 2014,
:first_name => 'Bob',
:last_name => 'Bobsen'
)
response = gateway.purchase(1000, creditcard)
STDERR.puts response.success?
STDERR.puts response.message
STDERR.puts response.authorization
关于ruby-on-rails - 如何将 braintree 与 rails 和 activemerchant 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6651489/