#jamesroper_error
1 messages ¡ Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- jamesroper_error, 1 day ago, 42 messages
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1222560639130665021
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Frontend code:
const CtPaymentScreen = () => {
const { currentCompany } = useAuth()
const fetchClientSecret = async () => {
const response = await api.post("/create-ct600-checkout-session", { stripeId: currentCompany.stripeID });
const data = response.data;
return data.clientSecret
};
const options = { fetchClientSecret };
return (
<div id="checkout">
<EmbeddedCheckoutProvider
stripe={stripePromise}
options={options}
>
<EmbeddedCheckout />
</EmbeddedCheckoutProvider>
</div>
)
}
export default CtPaymentScreen;```
Backend code:
@jwt_required()
def create_ct600_checkout_session():
try:
#data = request.get_json()
#stripe_id = data.get('stripeId')
session = stripe.checkout.Session.create(
#customer=stripe_id,
ui_mode = 'embedded',
line_items=[
{
# Provide the exact Price ID (for example, pr_1234) of the product you want to sell
'price': 'price_1OyZQ8P7FVbVKqazVzf2YYDX',
'quantity': 1,
},
],
mode='payment',
return_url='http://localhost:3000' + '/ctreturn?session_id={CHECKOUT_SESSION_ID}',
automatic_tax={'enabled': True},
)
except Exception as e:
return str(e)
return jsonify(clientSecret=session.client_secret)```
Setting this customer ID on the backend when you create the session should work as far as I know. Can you try that call again and send me the request ID so I can see this error? (req_123) https://docs.stripe.com/api/request_ids
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
To clarify, this is the part of the code which runs when I create a new company instance in our database, and this works correctly. It also correctly loads the Stripe ID into the useAuth context from our database as I have set up logging to check that:
stripe_customer = stripe.Customer.create(
name=data['name'],
#email=data.get('email', ''), # Assuming 'email' is in 'data'; adjust as necessary
description=f"Company number: {data['companyNumber']}"
)
stripe_customer_id = stripe_customer.id```
The issue instead is when I try to pass this Stripe ID to the backend from useAuth (currentCompany.StripeId), it throws this error
If that was your understanding already, where should I put the code you suggested?
Our backend doesn't have a concept of fetchClientSecret so I don't think that error is coming from your backend
OK I have found a work around in my frontend - the one issue now is it doesn't seem to be accepting the stripe id correctly in the checkout call - is there something I should be associating it with other than 'customer'? It works apart from that:
customer=stripe_id,
ui_mode = 'embedded',
line_items=[
{
# Provide the exact Price ID (for example, pr_1234) of the product you want to sell
'price': 'price_1OyZQ8P7FVbVKqazVzf2YYDX',
'quantity': 1,
},
],
mode='payment',
return_url='http://localhost:3000' + '/ctreturn?session_id={CHECKOUT_SESSION_ID}',
automatic_tax={'enabled': True},
)```
Or could the issue instead be related to the data type of stripe_id - what type should it be when passing it to the create function?
Also I have checked the stripe_id is being correctly passed to the backend and it now is
That parameter is expecting an ID of the format cus_1234
Can you try the create checkout session call again and send me the request ID so I can see exactly what you are getting back? https://support.stripe.com/?contact=true
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Oddly it seems to be printing the stripe_id for both the print calls (or perhaps the second print isn't set up correctly):
cus_Poa87yPUrYMHb0
cus_Poa87yPUrYMHb0
127.0.0.1 - - [27/Mar/2024 15:39:45] "POST /api/create-ct600-checkout-session HTTP/1.1" 200 -
127.0.0.1 - - [27/Mar/2024 15:39:45] "POST /api/create-ct600-checkout-session HTTP/1.1" 200 -
@jwt_required()
def create_ct600_checkout_session():
try:
data = request.get_json()
stripe_id = data.get('stripeId')
print(stripe_id)
session = stripe.checkout.Session.create(
customer=stripe_id,
ui_mode = 'embedded',
line_items=[
{
# Provide the exact Price ID (for example, pr_1234) of the product you want to sell
'price': 'price_1OyZQ8P7FVbVKqazVzf2YYDX',
'quantity': 1,
},
],
mode='payment',
return_url='http://localhost:3000' + '/ctreturn?session_id={CHECKOUT_SESSION_ID}',
automatic_tax={'enabled': True},
)
print(session.last_response.request_id)
except Exception as e:
return str(e)
return jsonify(clientSecret=session.client_secret)```
Ah it looks like the backend error is about their tax location being invalid. You are passing the customer in but they don't have an address so we don't know what taxes could apply to them
https://dashboard.stripe.com/test/logs/req_seK6yHXTqsLfoF
For now, could i instead turn off automatic tax?
And then sort that when I set up customer billing info in my app?
Yes you can disable it in your account settings or per checkout session https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-automatic_tax-enabled