#mxd3-pricingtable-reference
1 messages ยท Page 1 of 1 (latest)
@tranquil isle https://stripe.com/docs/payments/checkout/pricing-table#handle-fulfillment-with-the-stripe-api shows you how to pass the client_reference_id
mxd3-pricingtable-reference
ok testing it out now,
HTTP status code
400 (Bad Request)
{
"message": "No user_id found in event metadata",
"status": "failure"
}```
๐ stepping in here as koopajah needed to step away
Is the above coming from your Webhook handler?
yes I just click the 'start trial' filled out the credit card form, and this is from: dashboard stripe /test/webhooks/
Are you listening for checkout_session.completed here?
When you pass a client-reference-id via URL Params on Pricing Table it will then be present in the client_reference_id property of the Checkout Session object: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-client_reference_id
I'm not sure what you mean by that.
Going to need a lot more details about exactly what you are doing in order to be able to help!
so i did the {{client-reference-id="{{ current_user.id }}" and the number is 7
for the pricing table
then submitted the form
and here are the results after adding that client-reference-id: ```HTTP status code
400 (Bad Request)
{
"message": "No user_id found in event metadata",
"status": "failure"
}```
Where do you see this error exactly?
Are you looking at an Event and that is the Response body?
Also are you working with a third party integration here?
i have a mysql table, with a field called stripe_customer_id, and its currently NULL, and after paying, im trying to get it to flip to: cus_OG3syY0HXU7Xzg from NULL. and trying to associate the user of id=7
so the pricing page has the client-reference-id which takes the current logged in user id which is 7
Yep and are you listening for Webhooks to then ingest this data that way?
can I paste the webhook?
Yep if you can show me your webhook code that would help
@app.route('/webhook', methods=['POST'])
def webhook():
...
user_id = None
stripe_customer_id = None
if 'user_id' in event['data']['object']['metadata']:
if event['type'] == 'customer.created':
user_id = event['data']['object']['metadata']['user_id']
stripe_customer_id = event['data']['object']['id']
elif event['type'] in ['customer.subscription.created', 'customer.subscription.updated', 'customer.subscription.deleted', 'checkout.session.completed']:
user_id = event['data']['object']['metadata']['user_id']
stripe_customer_id = event['data']['object']['customer']
else:
return jsonify({'status': 'failure', 'message': 'No user_id found in event metadata'}), 400
user = User.query.filter_by(id=user_id).first()
if not user:
return jsonify({'status': 'failure', 'message': 'No user found for this id'}), 400
user.stripe_customer_id = stripe_customer_id
db.session.commit()
stripe_subscription_id = event['data']['object']['id']
stripe_product_id = event['data']['object']['plan']['product'] if 'plan' in event['data']['object'] else None
subscription_record = Subscription.query.filter_by(stripe_subscription_id=stripe_subscription_id).first()
if subscription_record:
subscription_record.user_id = user.id
subscription_record.active = event['type'] != 'customer.subscription.deleted'
subscription_record.stripe_product_id = stripe_product_id
else:
subscription_record = Subscription(user_id=user.id, stripe_subscription_id=stripe_subscription_id,
active=event['type'] != 'customer.subscription.deleted', stripe_product_id=stripe_product_id)
db.session.add(subscription_record)
db.session.commit()
return jsonify({'status': 'success'}), 200```
Okay cool. So see how you have if 'user_id' in event['data']['object']['metadata']:
That will never work
yeah i tried this before getting the idea to do the client-reference-id thing
What you want to do is something like if event and event['type'] == 'checkout_session.completed': user_id = event['data']['object'][client_reference_id]
does client_reference_id show up in the Request?
What is "the Request"?
HTTP status code
400 (Bad Request)
{
"message": "No user_id found in event metadata",
"status": "failure"
}
Request
{
"id": "evt_1Z",
"object": "event",
"api_version": "2022-08-01",
"created": 1689621266,
"data": {
"object": {
"id": "sub_1Q",
"object": "subscription",
"application": null,
"application_fee_percent": null,
"automatic_tax": {
"enabled": false
},```
Yes, it would be a property there within data.object but that is a Subscription object so that is the wrong Event type. It shows up on the Checkout Session object.
Which is why you need the checkout_session.completed Event.
I see it: "after_expiration": null, "allow_promotion_codes": true, "amount_subtotal": 0, "amount_total": 0, "automatic_tax": { "enabled": false, "status": null }, "billing_address_collection": "required", "cancel_url": "https://stripe.com", "client_reference_id": "7",
i did the resend on checkout.session.completed
๐
now I will try the if event and event['type']
Sounds good!
Would recommend referring to https://stripe.com/docs/webhooks/quickstart?lang=python for some example code of what your handler should look like
thats what it started off looking like
do you think the webhook code is poor? and I should rewrite it? is that what you are recommending?
Well I don't think you are doing signature verification above. But maybe you removed that part
Okay then yeah you probably just need to clean up your code. I didn't look at it too closely
Just saying that our webhook quickstart is a good clean example to refer to
oh ok
Which it sounds like you are already doing
I got this now : ```checkout.session.completed
Response
HTTP status code
200 (OK)
{
"status": "success"
}```
thank you very much, I have no further questions