• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example app of various bits and pieces needed to build a Stripe Connect app with Ruby on Rails.

Rails + Stripe Connect Example Application

This repository contains a bare-bones example Stripe Connect application. It's purpose is to demonstrate the various pieces needed to get up and running with your own application.

This application is not meant to be used as a starting point or run in production!

Pre-requisites

This application currently uses the following Stripe API version: 2015-04-07

This application is based on Rails 4.2 and running on Ruby 2.1 (with bundler). It will probably work fine with versions after these, and I will endeavour to keep it up to date.

You need a Stripe account configured with a Connect application. That can be setup in your Account Settings under 'Apps'. Here's what it should look like configured:

App Configuration

Note the 'Redirect URIs' setting.

You'll also need the regular API keys for the same account, which you can also get in Account Settings under 'API Keys'.

API Keys

Setup

To get started, first clone this repo and install dependencies:

git clone [email protected]:rfunduk/rails-stripe-connect-example.git
cd rails-stripe-connect-example
bundle install

Next we need to run the setup script that will put your various Stripe credentials in the appropriate place. Since this will be asking for API keys, you probably want to read it over first to be confident nothing nefarious is being done with your API keys :)

bin/rake app:setup

Once you get through that, your keys will be in config/secrets.yml and picked up by Rails when you start it.

Now load the schema into the database:

bin/rake db:schema:load

And start up the server:

bin/rails s

Then as usual visit http://localhost:3000 in your browser of choice.

Webhooks

Optionally, if you want webhooks to work, signup for ngrok (and donate!). Then run:

ngrok -authtoken=NGROK_TOKEN -subdomain=a-name 3000

Then configure your Stripe Connect application's 'Webhook URL' on the application settings page to be http://a-name.ngrok.com/hooks/stripe.

The account.application.deauthorized webhook will do the right things, but to see others you'll want to just look at the Rails request log.

How It Works

Step 0

If you want to try out a subscription with Stripe Connect, add some plans to your application's account on the dashboard.

Step 1

Visit the app and click 'Get Started'. You'll be prompted to create a user account. This app has a basic user login/cookie-based session system.

Step 2

Connect to Stripe. You'll have the option of 3 different types of connection:

1. OAuth Standalone

Create an account or connect to an existing account via an OAuth flow.

You may want to do this in an incognito window or similar so that you don't accidentally connect your platform/main account to itself which will be very confusing.

It's probably best to make another Stripe account with a test email address (eg, with Gmail you can do things like [email protected] to make this easier), or you can just use the 'Create New Account...' option in the menu at the top right of your Stripe dashboard.

When you click 'Connect', look for the development mode bar at the top of the page:

Development Mode Prompt

...and click Skip this account form... if you aren't activated yet.

This account + Stripe connection becomes the 'seller'.

2. Standalone Account via API

You can create a standalone Stripe account via the API, which doesn't require the user to leave your site at all.

Doing this is a simple matter of choosing a country and clicking 'Create'

This account + Stripe connection becomes the 'seller'.

3. Managed Account via API

You can create an entirely managed-by-you Stripe account via the API. With this method the user will have the least interaction with Stripe.

Doing this is a simple matter of choosing a country, agreeing to the Stripe Terms of Service, and clicking 'Create'.

Currently managed accounts are in beta and only available to US or Canadian platform accounts.

This account + Stripe connection becomes the 'seller'.

Step 3

Now log out of the example app and signup again for another account. This time don't bother connecting to Stripe (although you can if you want).

This account becomes the 'buyer'.

Step 4

Purchase something from the seller as the buyer! Visit http://localhost:3000/users and choose the connected/seller account. And make a payment or subscribe to a plan.

Step 5

Go through the code! I've tried to heavily comment the relevant and most important parts of the code. Let me know if anything is unclear or broken by opening an issue or sending me an email.

I suggest perusing the Connect docs before trying to dig into the code.

More Repositories

1

jquery-tourbus

A jQuery tour/walkthrough plugin.
JavaScript
157
star
2

flot

[defunct] This fork is no longer maintained. Please use the official repository. See website below.
JavaScript
46
star
3

ilac

Flex 3 Color Wheel
ActionScript
6
star
4

sellbot

A micro-app for DIY digital product sales.
CSS
6
star
5

feedbackasaurus

An extremely quick and dirty hack clone of redpen.io
Clojure
5
star
6

onirim

Redux/React/Webpack solitaire card game.
JavaScript
5
star
7

shared-auth-example

Example app as companion to ryanfunduk.com/shared-auth-for-rack-apps
Ruby
5
star
8

bigpuller

A weekend project to help figure out the 'willingness-to-pull' of a project on GitHub.
CSS
4
star
9

jen

[defunct] node.js static site generator with a live updating development server - still in early stages - see rfunduk/blog for an example site that uses this
CSS
4
star
10

auto_error

A rails engine for automatic exception handling (and an interface to view them). Early stages still!
Ruby
2
star
11

route53web

Well, the AWS management console now supports everything I was attempting to do here. https://console.aws.amazon.com/route53/home <strike>A web interface for viewing Amazon Route53 DNS records.</strike>
Ruby
2
star
12

jmodal

jQuery-based slidey modal window inspired by Modalbox.
JavaScript
2
star
13

s3_stat_proxy

A really simple s3 redirect proxy thing to count requests.
JavaScript
2
star
14

adhoc_script

A simple wrapper class for doing adhoc scripts over datasets and such.
Ruby
1
star
15

mrpassword

A 1PasswordAnywhere-like password vault built on the Dropbox API.
CoffeeScript
1
star
16

comfy

[defunct] A super simple CouchDB library in Ruby. I would not use this :)
Ruby
1
star
17

non_blocking_lock

A non_blocking_lock implementation for ActiveRecord adapters (well, just mysql2, at the moment). This is just a quick and dirty extraction due to the Rails 3.2 deprecation of vendor/plugins. README/tests/etc coming later.
Ruby
1
star