Search code examples
pythondjangostripe-paymentsstripe-connect

Django Stripe Connect account creation


I am trying to create an account on Stripe Connect, using the code provided by Stripe. Everything is working fine, I submit the create, and I record the stripe_id to my database. However, if I want to get the keys also, how can I retrieve them? What is the proper syntax to do so?

Here is my code in the view:

if form.is_valid():
    mail = form.cleaned_data['email']
    name = form.cleaned_data['first_name']
    lastName = form.cleaned_data['last_name']
    country = form.cleaned_data['country']
    stripeId = stripe.Account.create(type="custom", country=country, email=mail, )
    p = UserStripe.objects.create(
        user=request.user,
        stripe_id=stripeId['id'])
    print(p)
    print(stripeId['id'])

The keys are returned by the API as:

<Account account id=... at 0x00000a> JSON: {
  "id": "acct_1033zf2gFw4ArzaQ",
.
.
.
"keys": {
    "secret": "sk_test_AdveEkmolYxHOzV4K4qLWoJt",
    "publishable": "pk_test_Gt3Bk3C07gz2wnrI3hQWJQIi"
  }
}

So to get the id I am using stripeId['id'], but how can I get the info inside the keys and pass it to my database? Thank you.


Solution

  • you can do like:

    keys = stripeId['keys']
    secret = keys['secret']
    publishable = keys['publishable']
    

    Now you can save values of secret and publishable in database.