0

I need my users to have a test mode / live mode switch, exactly like Stripe has on its dashboard. I'm using python-social-auth to authenticate the user with Stripe, using a custom pipeline step to retrieve the access token and publishable key, and saving it to a field in the user model.

The problem is that I have to define in the settings these two values: SOCIAL_AUTH_STRIPE_KEY and SOCIAL_AUTH_STRIPE_SECRET, but I need something more like SOCIAL_AUTH_STRIPE_TEST_KEY, SOCIAL_AUTH_STRIPE_TEST_SECRET, SOCIAL_AUTH_STRIPE_LIVE_KEY and SOCIAL_AUTH_STRIPE_LIVE_SECRET.

Depending on which client id is used when initiating the OAuth flow, that's how Stripe selects which type of API access code to send, if I use my app's test cliend ID, Stripe will only send the test keys for that user. But if I use my production/live client ID, then I will be getting the live access code for that user.

Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45

1 Answers1

0

The way I've implemented this in my projects before is to run the Stripe Connect Oauth Process in Live mode. Once you connect to Stripe in live mode and you have a live Access Token and a live Refresh Token for your user, you can use the refresh token to generate a test access token and a test publishable key for your user.

You can see https://stripe.com/docs/connect/reference#post-token for how to convert a live Refresh Token into a test Access Token

Matthew Arkin
  • 4,460
  • 2
  • 27
  • 28