This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding a ruby backend * Updating README * Fix shipping_change endpoint. * Fixing nits, README and removing API Version hack * Load skus separately. * Update main README.
- Loading branch information
1 parent
a5ce738
commit 2d0df99
Showing
8 changed files
with
511 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'https://rubygems.org/' | ||
|
||
gem 'sinatra' | ||
gem 'sinatra-reloader' | ||
gem 'stripe' | ||
gem 'dotenv' | ||
gem 'json' | ||
gem 'ruby-debug-ide' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
backports (3.12.0) | ||
connection_pool (2.2.2) | ||
dotenv (2.7.1) | ||
faraday (0.15.4) | ||
multipart-post (>= 1.2, < 3) | ||
json (2.2.0) | ||
multi_json (1.13.1) | ||
multipart-post (2.0.0) | ||
mustermann (1.0.3) | ||
net-http-persistent (3.0.0) | ||
connection_pool (~> 2.2) | ||
rack (2.0.6) | ||
rack-protection (2.0.5) | ||
rack | ||
rake (12.3.2) | ||
ruby-debug-ide (0.6.1) | ||
rake (>= 0.8.1) | ||
sinatra (2.0.5) | ||
mustermann (~> 1.0) | ||
rack (~> 2.0) | ||
rack-protection (= 2.0.5) | ||
tilt (~> 2.0) | ||
sinatra-contrib (2.0.5) | ||
backports (>= 2.8.2) | ||
multi_json | ||
mustermann (~> 1.0) | ||
rack-protection (= 2.0.5) | ||
sinatra (= 2.0.5) | ||
tilt (>= 1.3, < 3) | ||
sinatra-reloader (1.0) | ||
sinatra-contrib | ||
sorbet (0.0.1.pre.prealpha) | ||
stripe (4.9.0) | ||
faraday (~> 0.13) | ||
net-http-persistent (~> 3.0) | ||
tilt (2.0.9) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
dotenv | ||
json | ||
ruby-debug-ide | ||
sinatra | ||
sinatra-reloader | ||
sorbet (~> 0.0.1.pre.prealpha) | ||
stripe | ||
|
||
BUNDLED WITH | ||
2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Stripe Payments Demo - Ruby Server | ||
|
||
This demo uses a simple [Sinatra](http://sinatrarb.com/) application as the server. | ||
|
||
## Payments Integration | ||
|
||
- [`app.rb`](app.rb) contains the routes that interface with Stripe to create charges and receive webhook events. | ||
- [`setup.rb`](setup.rb) a simple setup script to make some fake Products and SKUs for our Stripe store. | ||
- [`inventory.rb`](inventory.rb) a minimal wrapper over the Stripe Python SDK that handles creating/fetching products and caluclating payment amounts from SKUs. You can override this class with your own product and order management system code. | ||
|
||
## Requirements | ||
|
||
You’ll new the following: | ||
|
||
- [Ruby 2.X](https://www.ruby-lang.org/en/downloads/) | ||
- Modern browser that supports ES6 (Chrome to see the Payment Request, and Safari to see Apple Pay). | ||
- Stripe account to accept payments ([sign up](https://dashboard.stripe.com/register) for free!) | ||
|
||
## Getting Started | ||
|
||
Before getting started check that you have ruby installed | ||
|
||
``` | ||
ruby --version | ||
``` | ||
|
||
Copy the example environment variables file `.env.example` from the root of the repo into your own environment file called `.env`: | ||
|
||
``` | ||
cp .env.example .env | ||
``` | ||
|
||
User `bundler` to install the required gems by navigating to ./server/ruby and running: | ||
|
||
``` | ||
bundle install | ||
``` | ||
|
||
Run the Sinatra application | ||
|
||
``` | ||
bundle exec ruby app.rb | ||
``` | ||
|
||
You should now see it running on [`http://localhost:4567/`](http://localhost:4567/) | ||
|
||
### Testing Webhooks | ||
|
||
If you want to test [receiving webhooks](https://stripe.com/docs/webhooks), we recommend using ngrok to expose your local server. | ||
|
||
First [download ngrok](https://ngrok.com) and start your Sinatra application. | ||
|
||
[Run ngrok](https://ngrok.com/docs). Assuming your Sinatra application is running on the default port 4567, you can simply run ngrok in your Terminal in the directory where you downloaded ngrok: | ||
|
||
``` | ||
ngrok http 4567 | ||
``` | ||
|
||
ngrok will display a UI in your terminal telling you the new forwarding address for your Sinatra app. Use this URL as the URL to be called in your developer [webhooks panel.](https://dashboard.stripe.com/account/webhooks) | ||
|
||
Don't forget to append `/webhook` when you set up your Stripe webhook URL in the Dashboard. Example URL to be called: `https://75795038.ngrok.io/webhook`. | ||
|
||
## Credits | ||
- Code: [Mike Shaw](https://www.linkedin.com/in/mandshaw/) |
Oops, something went wrong.