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