#some1ataplace_checkout-webhooks-metadata
1 messages ยท Page 1 of 1 (latest)
๐ 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/1277740692281753601
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- some1ataplace_webhooks, 51 minutes ago, 8 messages
I want to loop through the value in the webhook*
Hi ๐
Taking a look at your request
updated_course_ids_and_prices = checkout_session.metadata.updated_course_ids_and_prices
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'AnyIterator' object has no attribute 'metadata'
Okay I think the issue is how the data is getting serialized. It looks like you are passing in an array to updated_course_ids_and_prices, is that correct?
Here is what it looks like:
[{'course_id': 3, 'price': 2.0, 'percent_off': None, 'amount_off': None, 'promo_code': None, 'promo_id': None, 'product_type': None, 'coupon_id': None}, {'course_id': 29, 'price': 1.0, 'percent_off': None, 'amount_off': None, 'promo_code': None, 'promo_id': None, 'product_type': None, 'coupon_id': None}]
Yeah, that would wind up getting serialized to
updated_course_ids_and_prices: {
0: {
course_id: "3",
price: "2.0",
},
1: {
course_id: "29",
price: "1.0",
},
},
This is no good because we need strings as keys, not integers
Also, you should assign all the metadata to a variable and inspect it first
my_data = checkout_session.metadata
print(my_data)
Metadata needs to be key: value pairs all the way down if you want structured data
ok
If I put json in the checkout metadata I get:
"metadata": {
"order": "order",
"order_id": "61",
"updated_course_ids_and_prices": "[{"course_id": 3, "price": 2.0, "percent_off": null, "amount_off": null, "promo_code": null, "promo_id": null, "product_type": null, "coupon_id": null}, {"course_id": 29, "price": 1.0, "percent_off": null, "amount_off": null, "promo_code": null, "promo_id": null, "product_type": null, "coupon_id": null}]"
}
Sorry not sure what that means here.
Is this the payload you are testing?
If so, what is the response?
Checkout:
mode='payment',
metadata={"order": "order", "order_id":order.id, 'updated_course_ids_and_prices':json.dumps(updated_course_ids_and_prices),},
webhook:
updated_course_ids_and_prices = checkout_session.metadata.updated_course_ids_and_prices
Yes I am trying to create a payload for the webhook
using json.loads does not work either:
updated_course_ids_and_prices = json.loads(checkout_session.metadata.get('updated_course_ids_and_prices'))
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'AnyIterator' object has no attribute 'metadata'
Unless... what if I put this into a session variable? Rather than stripe metadata... hmm
I don't think you should try to wrap all of this. I recommend putting the metadata in it's own variable and attempting to covert it to a dict for access in a separate line
Sounds good!