I am able to create a connected accounts with charges enabled and payouts enabled using Stripe test keys. But when I went live and created a stripe connected account, it shows the account is restricted in the Stripe dashboard. I am using AWS lambda to write the account creation code in python in the backend. I have two lambda functions’ code below. One for generating stripe account id, one for generating stripe account creation url. I am just writing the api calls here and not the lambda handler because it worked for test keys. Can someone explain why this is so? Has anyone faced this issue while going live? Do I need to add some more parameters in the below api calls?
I tried to create a stripe account using the below code.
import json
import http.client
import urllib.parse
def create_stripe_account(user_name, email):
user_name = user_name
email = email
url = "https://api.stripe.com/v1/accounts"
api_key = "sk_live_123"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/x-www-form-urlencoded"
}
print("log-1")
parameters = {
"type": "express",
"country": "US",
"email": email,
"capabilities[card_payments][requested]": True,
"capabilities[transfers][requested]": True,
"business_type": "individual",
"business_profile[mcc]": 5971,
"business_profile[name]": user_name,
"business_profile[product_description]": "Artwork"
}
print("log-2")
# json_data = json.dumps(parameters)
encoded_parameters = urllib.parse.urlencode(parameters)
request_body = encoded_parameters.encode("utf-8")
print("log-3")
conn = http.client.HTTPSConnection("api.stripe.com")
conn.request("POST", url, body=request_body, headers=headers)
response = conn.getresponse()
print("log-4")
if response.status == 200:
response_data = response.read().decode("utf-8")
return response_data, response.status
else:
print(f"Error: Invalid HTTP response ({response.status})")
response_data = response.read().decode("utf-8")
print(f"Response data: {response_data}")
return response_data, response.status
Using the above code, I retrieved stripe account id and generated a stripe account creation URL using the below code.
import json
import http.client
import urllib.parse
import json
def create_account_link(stripe_account_id):
stripe_account_id = stripe_account_id
test_flight_url = "https://testflight.apple.com/join/57vVCOVf"
# Define the URL and API key
url = "https://api.stripe.com/v1/account_links"
api_key = "sk_live_123"
# Define the parameters
parameters = {
"account": stripe_account_id,
"refresh_url": test_flight_url,
"return_url": test_flight_url,
"type": "account_onboarding"
}
# Encode the parameters
encoded_parameters = urllib.parse.urlencode(parameters)
body = encoded_parameters.encode("utf-8")
# Define the headers
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/x-www-form-urlencoded"
}
# Establish connection
conn = http.client.HTTPSConnection("api.stripe.com")
# Send POST request
conn.request("POST", url, body, headers)
# Get response
response = conn.getresponse()
# Read and decode response data
response_data = response.read().decode("utf-8")
# Print response status code and data
print("Status Code:", response.status)
print("Response:", response_data)
if response.status == 200:
return response_data, response.status
else:
print(f"Error: Invalid HTTP response ({response.status})")
print(f"Response data: {response_data}")
return response_data, response.status