Skip to content

Instantly share code, notes, and snippets.

@keikubo
Created December 25, 2013 12:21
Show Gist options
  • Save keikubo/8122781 to your computer and use it in GitHub Desktop.
Save keikubo/8122781 to your computer and use it in GitHub Desktop.
require 'active_merchant'
ActiveMerchant::Billing::Base.mode = :test
gateway = ActiveMerchant::Billing::WebpayGateway.new(:login => 'test_secret_eHn4TTgsGguBcW764a2KA8Yd')
amount = 10000 # 100 yen
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => 'Kei',
:last_name => 'Kubo',
:number => '4242424242424242',
:month => '8',
:year => Time.now.year+1,
:verification_value => '000')
if credit_card.valid?
response = gateway.purchase(amount, credit_card)
if response.success?
puts "Charged #{sprintf("%.2f", amount / 100)} yen to #{credit_card.display_number}."
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