Setting up Stripe on your local development environment

February 3, 2020 ยท View on GitHub

You'll need to create two Stripe accounts. One to act as the Local Orbit "Platform" and one as the food hub market's "Connect" account.

First, create the Platform account

  1. Sign up at stripe.com
  2. Click the 'Viewing test data' slider to on in the sidebar
  3. Go to the Developers > API keys in the side bar
  4. Copy the Publishable key into your application.yml as STRIPE_PUBLISHABLE_KEY
  5. Copy the Secret key into your applicaiton .yml as STRIPE_SECRET_KEY

Then, create the Connect account

Repeat the same steps as you did for the Platform account.

To get your local market setup via the OAuth flow

Note, these steps may be out of date or wrong

  1. Go to your Platform account on stripe.com

  2. Ensure Viewing test data is turned on

  3. Go to Settings > Connect settings

  4. Ensure that you see No redirect URIs set (we'll do that later)

  5. Click the Test OAuth button and follow the prompt

  6. On the page that shows how a user would sign up, instead click the link in the caution strip at the top of the page that says Skip this account form

  7. Copy the instructions that look like this and run it on the command line:

    curl -X POST https://connect.stripe.com/oauth/token \\
    -d client_secret=... \\
    -d code=... \\
    -d grant_type=authorization_code
    
  8. Your response will look something like

    {
       "access_token": "sk_test_n6m3slSJEOhFJK5Vk7mOum2T",
       "livemode": false,
       "refresh_token": "rt_BwwjfUUxrqTq33hRCoSbEMpt2UadtIKAaS3G4SZbpPKuY6j3",
       "token_type": "bearer",
       "stripe_publishable_key": "pk_test_JGvIa3qWQtEsT8rpY6DveIqO",
       "stripe_user_id": "acct_1BZ2OwXeDDexvDWm",
       "scope": "read_write"
    }
    
  9. Copy the stripe_user_id value (acct_1BZ2OwXeDDexvDWm) and use it for your STRIPE_DEV_MARKET_ACCOUNT_ID in your application.yml.

  10. Run rake reset to drop your dev db, recreate with new seed data. If it doesn't work, you may needs to stop all process running under spring (guard, rails console, etc.), and do spring stop, and try again.

  11. You should be able to login as a buyer and interact with a working Market.

Set up a Stripe Application Redirect URI for your local dev instance

Although the above steps ensure your development seed's markets are configured with Stripe, you may want to test the full user flow locally. To do so, complete these last steps.

  1. Go to Stripe Dashboard > Connect > Settings
  2. With Viewing test data still enabled, click Add redirect URI...
  3. Enter http://app.localtest.me:3000/users/auth/stripe_connect/callback and hit Save.
  4. Now if you create a new Market locally, you can test the complete UX from the Market > Stripe tab.

How to set up webhook testing

We use the stripe-event gem with an endpoint configured at /webhooks/stripe to receive event notifications from Stripe webhooks.

We can use ngrok to map a development domain to the webhook receiver in your stripe developer account settings.

To use ngrok, create an account, then configure it with a reserved domain , and setup the CNAME for app.yourdevdomain.com.

Then in a terminal type:

ngrok http -region=us -hostname=app.yourdevdomain.com 3000

and add your webhooks url to your own development Stripe webhook settings Eg.

http://app.yourdevdomain.com/webhooks/stripe

and then open the ngrok web interface to inspect the requests:

http://127.0.0.1:4040/http/in