forked from maxio-com/chargify_direct_example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchargify_direct_example_app.rb
More file actions
72 lines (58 loc) · 1.33 KB
/
chargify_direct_example_app.rb
File metadata and controls
72 lines (58 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'yaml'
class ChargifyDirectExampleApp < Sinatra::Base
get '/' do
erb :index
end
get '/verify' do
if chargify.direct.response_parameters(params).verified?
@call = chargify.calls.read(params[:call_id])
if @call.successful?
redirect "/receipt/#{@call.id}"
else
erb :index
end
else # Unverified redirect
erb :unverified
end
end
get '/receipt/:call_id' do
@call = chargify.calls.read(params[:call_id])
if @call
erb :receipt
else
not_found
end
end
not_found do
"Not found"
end
helpers do
def chargify
@chargify ||= Chargify2::Client.new(config)
end
def config
@config ||= YAML.load(File.open(config_file)) || {}
end
def config_file
File.expand_path File.join(File.dirname(__FILE__), 'config', 'config.yml')
end
def h(s)
Rack::Utils.escape_html(s)
end
def signup_params
@call ? @call.request.signup : nil
end
def product_params
signup_params ? signup_params.product : {}
end
def coupon_code
signup_params ? signup_params[:coupon_code] : nil
end
def customer_params
signup_params ? signup_params.customer : {}
end
def payment_profile_params
signup_params ? signup_params.payment_profile : {}
end
end
end