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
- Sign up at stripe.com
- Click the 'Viewing test data' slider to on in the sidebar
- Go to the Developers > API keys in the side bar
- Copy the
Publishable keyinto your application.yml asSTRIPE_PUBLISHABLE_KEY - Copy the
Secret keyinto your applicaiton .yml asSTRIPE_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
-
Go to your Platform account on stripe.com
-
Ensure Viewing test data is turned on
-
Go to Settings > Connect settings
-
Ensure that you see No redirect URIs set (we'll do that later)
-
Click the Test OAuth button and follow the prompt
-
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
-
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 -
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" } -
Copy the
stripe_user_idvalue (acct_1BZ2OwXeDDexvDWm) and use it for yourSTRIPE_DEV_MARKET_ACCOUNT_IDin your application.yml. -
Run
rake resetto 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 dospring stop, and try again. -
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.
- Go to Stripe Dashboard > Connect > Settings
- With Viewing test data still enabled, click Add redirect URI...
- Enter
http://app.localtest.me:3000/users/auth/stripe_connect/callbackand hit Save. - 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