Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit b93d157

Browse files
authored
Merge pull request #21 from stripe/ksun-body-params
Make endpoint to form encoded and body params
2 parents 1d316c6 + fcc3e47 commit b93d157

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

web.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@
3333

3434
post '/charge' do
3535
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
4045
# Create the charge on Stripe's servers - this will charge the user's card
4146
begin
4247
charge = Stripe::Charge.create(
43-
:amount => params[:amount], # this number should be in cents
48+
:amount => payload[:amount], # this number should be in cents
4449
:currency => "usd",
4550
:customer => customer,
4651
:source => source,
4752
:description => "Example Charge",
48-
:shipping => params[:shipping],
53+
:shipping => payload[:shipping],
4954
)
5055
rescue Stripe::StripeError => e
5156
status 402
@@ -76,7 +81,7 @@ def authenticate!
7681
@customer
7782
end
7883

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.
8085
post '/create_charge' do
8186
# Create the charge on Stripe's servers
8287
begin

0 commit comments

Comments
 (0)