Skip to content

Instantly share code, notes, and snippets.

@codegeek1001
Last active August 29, 2015 14:06
Show Gist options
  • Save codegeek1001/69d0419b332ea1e206b4 to your computer and use it in GitHub Desktop.
Save codegeek1001/69d0419b332ea1e206b4 to your computer and use it in GitHub Desktop.
Purpose: Migrating customer from one stripe account to another with credit card details. For sake of description, we will call the 2 accounts "From_Stripe" and "To_Stripe". So we are going to take customer from the "From_Stripe" account and import it into "To_Stripe" account.
You need to first connect the 2 stripe accounts.
Step 1: To connect the 2 accounts, Create a "Connect App" first in the "From_Stripe" account. Once created, it will have the client id which is 'ca_xxxxx'
Step 2: Make sure you now login to "To_Stripe" account in your browser. Then run the following URL
https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_xxxxxx&scope=read_write
Step 3: You will get the ACCESS_TOKEN returned to you when you run the above url. Note this ACCESS_TOKEN down. it will be something like 'sk_live_xxxxxxxx' just like a secret key
Step 4: Now you can run the following script (I am using python but use any from stripe's API)
import stripe
# Get the Customer id from the "From_Stripe" account
CUST_ID='cus_xxxxxxxx'
# Access token below is the one we got earlier when we established connect linkage between the 2 accounts
ACCESS_TOKEN = 'sk_live_xxxxxxxxxxxxxxxxxxx'
# Get the card id from the "From_Stripe" account
CARD_ID='card_xxxxxxxxxxxxxxxx'
# Create a Token from the existing customer on the application's account
card_token = stripe.Token.create(customer=CUST_ID,card=CARD_ID,api_key=ACCESS_TOKEN)
Step 5: Finally, run the following command to create a new customer in the "To_Stripe" account which will be using the token created above and hence essentially importing the customer from "From_Stripe" account
curl https://api.stripe.com/v1/customers -u ACCESS_TOKEN -d "description=My Customer" -d card=card_token
You are done. the customer should be successfully imported into the new account from the old account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment