次の手順を使用して、これを非常に簡単に達成できました。
Paymillで新しいアカウントを作成します。
Paymill 設定ページから公開鍵と秘密鍵を取得します
activemerchant gemをインストールします。
gem install activemerchant
購入するために、以下のスクリプトを使用しました
Paymill でアカウントを有効にしない限り、アカウントはテスト モードで実行されることに注意してください。したがって、実際に送金されることはありません。彼らはまた、引き落とされないテストクレジットカードもリストしています.
スクリプト:
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