我通过以下步骤很容易地做到了这一点:
-
在创建新帐户
Paymill
.
-
从Paymill设置页面获取公钥和私钥
-
安装
activemerchant
宝石:
gem install activemerchant
-
我使用了下面的脚本进行购买
请注意,只要您不在Paymill激活您的帐户,它就会在测试模式下运行。因此,实际上不会转账。他们还列出
test credit cards
这也永远不会被记入借方。
脚本:
require 'rubygems'
require 'active_merchant'
require 'json'
# Use the TrustCommerce test servers
ActiveMerchant::Billing::Base.mode = :test
gateway = ActiveMerchant::Billing::PaymillGateway.new(
:public_key => 'MY_PAYMILL_PUBLIC_KEY',
:private_key => 'MY_PAYMILL_PRIVATE_KEY')
gateway.default_currency = 'USD'
# 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(
:first_name => 'Bob',
:last_name => 'Bobsen',
:number => '5500000000000004',
:month => '8',
:year => Time.now.year+1,
:verification_value => '000')
# Validating the card automatically detects the card type
if credit_card.valid?
# Capture the amount from the credit card
response = gateway.purchase(amount, credit_card)
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