Skip to content

Instantly share code, notes, and snippets.

@keikubo
Created December 25, 2013 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keikubo/8119850 to your computer and use it in GitHub Desktop.
Save keikubo/8119850 to your computer and use it in GitHub Desktop.
require 'twilio-ruby'
require 'webpay'
post '/' do
Twilio::TwiML::Response.new do |r|
r.Gather :timeout => "10", :finishOnKey => "*", :action => '/month' do |g|
g.Say "Please enter your credit card number and then press star."
end
end.text
end
post '/month' do
number = params['Digits']
Twilio::TwiML::Response.new do |r|
r.Gather :timeout => "10", :finishOnKey => "*", :action => "/year?number=#{number}" do |g|
g.Say "Please enter your two digit credit card expiration month and then press star."
end
end.text
end
post '/year' do
number = params['number']
month = params['Digits']
Twilio::TwiML::Response.new do |r|
r.Gather :timeout => "10", :finishOnKey => "*", :action => "/cvv?number=#{number}&month=#{month}" do |g|
g.Say "Please enter your four digit credit card expiration year and then press star."
end
end.text
end
post '/cvv' do
number = params['number']
month = params['month']
year = params['Digits']
Twilio::TwiML::Response.new do |r|
r.Gather :timeout => "10", :finishOnKey => "*", :action => "/charge-via-webpay?number=#{number}&month=#{month}&year=#{year}" do |g|
g.Say "Please enter your credit card CVV number and then press star."
end
end.text
end
post '/charge-via-webpay' do
number = params['number']
month = params['month']
year = params['year']
cvv = params['Digits']
amount = 19800
WebPay.api_key = "test_secret_eHn4TTgsGguBcW764a2KA8Yd"
WebPay::Charge.create(
:amount => amount,
:currency => "jpy",
:card =>
{:number => number,
:exp_month => month,
:exp_year => year,
:cvc => cvv}
)
Twilio::TwiML::Response.new do |r|
r.Say "You successfully paid #{amount} Japanese Yen. Thank you."
end.text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment