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

Commit 3957cb4

Browse files
committed
initial code commit
1 parent f452b5d commit 3957cb4

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source "https://rubygems.org"
2+
ruby "2.1.2"
3+
gem 'sinatra', '1.4.5'
4+
gem 'stripe', '1.20.0'
5+
gem 'dotenv', '1.0.2'

Gemfile.lock

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
dotenv (1.0.2)
5+
json (1.8.2)
6+
mime-types (2.4.3)
7+
netrc (0.10.3)
8+
rack (1.5.2)
9+
rack-protection (1.5.3)
10+
rack
11+
rest-client (1.7.3)
12+
mime-types (>= 1.16, < 3.0)
13+
netrc (~> 0.7)
14+
sinatra (1.4.5)
15+
rack (~> 1.4)
16+
rack-protection (~> 1.4)
17+
tilt (~> 1.3, >= 1.3.4)
18+
stripe (1.20.0)
19+
json (~> 1.8.1)
20+
mime-types (>= 1.25, < 3.0)
21+
rest-client (~> 1.4)
22+
tilt (1.4.1)
23+
24+
PLATFORMS
25+
ruby
26+
27+
DEPENDENCIES
28+
dotenv (= 1.0.2)
29+
sinatra (= 1.4.5)
30+
stripe (= 1.20.0)

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: bundle exec ruby web.rb -p $PORT

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Example iOS Backend
2+
====
3+
4+
This is a really simple [Sinatra](http://www.sinatrarb.com/) webapp that you can use to test Stripe's [example iOS apps](https://github.com/stripe/stripe-ios).
5+
6+
It has a single endpoint, `/charge`, which takes 2 parameters (`stripeToken` and `amount`) to create a charge on your Stripe account.
7+
8+
This is intended for example purposes only: you'll likely need something more serious for your production apps.
9+
10+
To deploy this for free on Heroku, click this button:
11+
12+
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
13+
14+
Then set the `backendChargeURLString` variable in our example apps to your Heroku URL (it'll be in the format https://my-example-app.herokuapp.com).
15+
16+
Happy testing!

app.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Example Stripe iOS Backend",
3+
"description": "For testing the Stripe example iOS apps at github.com/stripe/stripe-ios",
4+
"repository": "https://github.com/stripe/example-ios-backend",
5+
"keywords": ["ios", "stripe"],
6+
"env": {
7+
"STRIPE_TEST_PUBLISHABLE_KEY": {
8+
"description": "Find me at https://dashboard.stripe.com/account/apikeys (pk_test_****)",
9+
"required": true
10+
},
11+
}
12+
}

web.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'sinatra'
2+
require 'stripe'
3+
require 'dotenv'
4+
5+
Dotenv.load
6+
7+
Stripe.api_key = ENV['STRIPE_API_KEY']
8+
9+
post '/charge' do
10+
11+
# Get the credit card details submitted by the form
12+
token = params[:stripeToken]
13+
14+
# Create the charge on Stripe's servers - this will charge the user's card
15+
begin
16+
charge = Stripe::Charge.create(
17+
:amount => params[:amount], # this number should be in cents
18+
:currency => "usd",
19+
:card => token,
20+
:description => "Example Charge"
21+
)
22+
rescue Stripe::CardError => e
23+
status 402
24+
return "Error creating charge."
25+
end
26+
27+
status 200
28+
return "Order successfully created"
29+
30+
end

0 commit comments

Comments
 (0)