|
10 | 10 | use Rack::Session::EncryptedCookie,
|
11 | 11 | :secret => 'replace_me_with_a_real_secret_key' # Actually use something secret here!
|
12 | 12 |
|
| 13 | +def log_info(message) |
| 14 | + puts "\n" + message + "\n\n" |
| 15 | + return message |
| 16 | +end |
| 17 | + |
13 | 18 | get '/' do
|
14 | 19 | status 200
|
15 |
| - return "Great, your backend is set up. Now you can configure the Stripe example apps to point here." |
| 20 | + return log_info("Great, your backend is set up. Now you can configure the Stripe example apps to point here.") |
16 | 21 | end
|
17 | 22 |
|
18 | 23 | post '/ephemeral_keys' do
|
|
24 | 29 | )
|
25 | 30 | rescue Stripe::StripeError => e
|
26 | 31 | status 402
|
27 |
| - return "Error creating ephemeral key: #{e.message}" |
| 32 | + return log_info("Error creating ephemeral key: #{e.message}") |
28 | 33 | end
|
29 | 34 |
|
30 | 35 | status 200
|
|
35 | 40 | authenticate!
|
36 | 41 | # Get the credit card details submitted
|
37 | 42 | payload = params
|
38 |
| - if request.content_type.include? 'application/json' and params.empty? |
| 43 | + if request.content_type.include? 'application/json' and params.empty? |
39 | 44 | payload = indifferent_params(JSON.parse(request.body.read))
|
40 | 45 | end
|
41 | 46 |
|
|
53 | 58 | )
|
54 | 59 | rescue Stripe::StripeError => e
|
55 | 60 | status 402
|
56 |
| - return "Error creating charge: #{e.message}" |
| 61 | + return log_info("Error creating charge: #{e.message}") |
57 | 62 | end
|
58 | 63 |
|
59 | 64 | status 200
|
60 |
| - return "Charge successfully created" |
| 65 | + return log_info("Charge successfully created") |
61 | 66 | end
|
62 | 67 |
|
63 | 68 | def authenticate!
|
@@ -92,11 +97,11 @@ def authenticate!
|
92 | 97 | )
|
93 | 98 | rescue Stripe::StripeError => e
|
94 | 99 | status 402
|
95 |
| - return "Error creating charge: #{e.message}" |
| 100 | + return log_info("Error creating charge: #{e.message}") |
96 | 101 | end
|
97 | 102 |
|
98 | 103 | status 200
|
99 |
| - return "Charge successfully created" |
| 104 | + return log_info("Charge successfully created") |
100 | 105 | end
|
101 | 106 |
|
102 | 107 | # This endpoint responds to webhooks sent by Stripe. To use it, you'll need
|
@@ -125,8 +130,7 @@ def authenticate!
|
125 | 130 | :description => "Example Charge"
|
126 | 131 | )
|
127 | 132 | rescue Stripe::StripeError => e
|
128 |
| - p "Error creating charge: #{e.message}" |
129 |
| - return |
| 133 | + return log_info("Error creating charge: #{e.message}") |
130 | 134 | end
|
131 | 135 | # After successfully creating a charge, you should complete your customer's
|
132 | 136 | # order and notify them that their order has been fulfilled (e.g. by sending
|
|
0 commit comments