#some1ataplace

1 messages · Page 1 of 1 (latest)

void mossBOT
solid marlin
#

Hi 👋 breaking this out

#

I am wondering what webhook event to create the gift cards in in? payment_intent.succeeded or checkout.session.completed?
The big factor here is whether you're accepting delayed-notification payment methods as forms of payment. checkout.session.completed is triggered when the customer completes the checkout flow, but if you're accepting delayed notification payment methods then payment failures can still occur later.
https://stripe.com/docs/payments/checkout/fulfill-orders#delayed-notification

Then I am wondering from either of those webhook events how to create X quantity number of coupon/promo codes for the user. I guess I have to use the line_items array to pull the quantity and the name of the gift card (Monthly Gift Card vs Yearly Gift Card) since I do not have a product id?
I'm not too sure how you're structuring your product information, so I don't have a ton of advice to offer on how to parse it, but if your flow requires creating multiple "gift cards" then you will need to make multiple requests.

Also not sure if I should give the user a promo code or a coupon code? I guess promo code? The coupon would be the parent of all the child monthly and yearly promo codes?
If you want the customer to be able to redeem it directly on surfaces like Checkout Sessions, promotion codes are better. Otherwise Coupons are likely sufficient, but sort of depends on how you want to let your customers redeem these "gift card" balances.

naive osprey
#

yes, i am allowing either ach or credit card payments so there will be delayed notification stuff.

solid marlin
#

I would not use checkout.session.completed then.

naive osprey
#

i will most likely make the promo codes 1 time use only, no redeeming

#

I have product id of "Monthly" $50 snf product id of "Yearly" of $600 for example. When a user checks out, they get a 100% off promo code for whichever product type they select from the form.

#

product = Monthly
quantity = 2

loop 2 times:
stripe.PromotionCode.create(
coupon="abcdefg", #100% off coupon parent (let's say Monthly for example)
active=True,
max_redemptions=1,
)

Get 2 promo codes returned for 100% off Monthly

#

From the payment_intent.success webhook how do I then get quantity and name of the product?

Checkout session creation:

                    mode='payment',
                    line_items=[{
                      'price_data': {
                        'currency': 'usd',
                        'unit_amount': yearly_price_amount,
                        'product_data': {
                          'name': 'Monthly Gift Card',
                          'description': 'One Time Monthly Gift Card',
                        },
                      },
                      'quantity':quantity,
solid marlin
#

You need to get from the Payment Intent to the associated Checkout Session, since the Checkout Session is the object that stores the line item information.

If you have the ID of the Payment Intent, you can use it as a filter when listing Checkout Sessions to only retrieve the relevant one:
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent

naive osprey
#

stripe.checkout.Session.retrieve(
payment_intent=payment_intent_id,
)
?

solid marlin
#

Is there more to that question?

naive osprey
#

or it has to be list?

#

stripe.checkout.Session.list(payment_intent=payment_intent_id,)

#

I am wondering if that is the right way to do it?

solid marlin
#

It has to be list

naive osprey
#

ok cool ty let me try a few things

#

what is the next step after getting the checkout session to find the quantity and product name?

solid marlin
#

Hm, I'd use expand, when listing the Checkout Session, to expand data.line_items. So then you can look right into the details you provided in the Checkout Sessions line items without needing to fetch them as well.
https://stripe.com/docs/api/expanding_objects

naive osprey
#

Isn't that only for retrieve though not list?

solid marlin
#

No

naive osprey
#

if event.type == 'payment_intent.succeeded':

payment_intent_id =  event.data.object.id
checkout_session = stripe.checkout.Session.list(payment_intent=payment_intent_id,expand=["data.line_items",]).auto_paging_iter()
for x in checkout_session:
    print(x)
solid marlin
#

It works for list requests as well, and the instructions shown in the reference discuss the change you need to make for list requests (which I included, it's the data. prefix)

naive osprey
#

ah alright

#

very nice that worked thank you again