This repository was archived by the owner on Feb 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change 33
33
34
34
post '/charge' do
35
35
authenticate!
36
- # Get the credit card details submitted by the form
37
- source = params [ :source ]
38
- customer = params [ :customer_id ] || @customer . id
39
-
36
+ # Get the credit card details submitted
37
+ payload = params
38
+ if request . accept? 'application/json' and params . empty?
39
+ payload = indifferent_params ( JSON . parse ( request . body . read ) )
40
+ end
41
+
42
+ source = payload [ :source ]
43
+ payload [ :amount ]
44
+ customer = payload [ :customer_id ] || @customer . id
40
45
# Create the charge on Stripe's servers - this will charge the user's card
41
46
begin
42
47
charge = Stripe ::Charge . create (
43
- :amount => params [ :amount ] , # this number should be in cents
48
+ :amount => payload [ :amount ] , # this number should be in cents
44
49
:currency => "usd" ,
45
50
:customer => customer ,
46
51
:source => source ,
47
52
:description => "Example Charge" ,
48
- :shipping => params [ :shipping ] ,
53
+ :shipping => payload [ :shipping ] ,
49
54
)
50
55
rescue Stripe ::StripeError => e
51
56
status 402
@@ -76,7 +81,7 @@ def authenticate!
76
81
@customer
77
82
end
78
83
79
- # This endpoint is used by the Obj-C example app to create a charge.
84
+ # This endpoint is used by the Obj-C and Android example apps to create a charge.
80
85
post '/create_charge' do
81
86
# Create the charge on Stripe's servers
82
87
begin
You can’t perform that action at this time.
0 commit comments