Created
February 25, 2014 15:39
-
-
Save hoshinaoshi/9211347 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'active_merchant' | |
ActiveMerchant::Billing::Base.mode = :test | |
# ActiveMerchant の金額はセント単位の整数でInputするため、日本円の場合は*100しなければならない。 | |
# ¥1,000 | |
amount = 100000 | |
# カードセキュリティコードで使用できるのはCVV2, CVC2, CID | |
credit_card = ActiveMerchant::Billing::CreditCard.new( | |
first_name: 'FirstName', | |
last_name: 'LastName', | |
number: '1234567890123456', | |
month: '8', | |
year: '2014', | |
verification_value: '123' | |
) | |
# カードの種類を検出 | |
if credit_card.valid? | |
# Beanstreamゲートウェイ作成 | |
gateway = ActiveMerchant::Billing::BeanstreamGateway.new( | |
login: 'TestMerchant', | |
password: 'password', | |
pass_code: 'pass_code' | |
) | |
# 定期購読支払いの実行 | |
response = gateway.recurring(amount, credit_card, { | |
recurring_billing: { | |
end_of_month: '1', | |
tax1: 0, | |
interval: { | |
unit: :months, | |
length: '1' | |
}, | |
duration: { | |
start_date: Date.today, | |
occurrences: 5 | |
} | |
}) | |
if response.success? | |
puts "クレジットカードで#{amount / 100}円の定期購読を受け付けました" | |
else | |
raise StandardError, response.message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment