#some1ataplace_checkout-webhooks-metadata

1 messages ยท Page 1 of 1 (latest)

leaden merlinBOT
#

๐Ÿ‘‹ 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.

flint obsidian
#

I want to loop through the value in the webhook*

shadow barn
#

Hi ๐Ÿ‘‹

Taking a look at your request

flint obsidian
#

updated_course_ids_and_prices = checkout_session.metadata.updated_course_ids_and_prices
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'AnyIterator' object has no attribute 'metadata'

shadow barn
#

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?

flint obsidian
#

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}]

shadow barn
#

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

flint obsidian
#

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}]"
}

shadow barn
#

Sorry not sure what that means here.

#

Is this the payload you are testing?

#

If so, what is the response?

flint obsidian
#

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

shadow barn
#

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

flint obsidian
#

okay I will try that

#

thanks, i will try later when i get back online

shadow barn
#

Sounds good!