#louislegourmet

1 messages ยท Page 1 of 1 (latest)

charred leafBOT
nocturne mirage
#

You may set line_items with one-time price and subscription price with mode='subscription' in one single checkout session

solid swan
#

Thank you

nocturne mirage
#

No problem! Happy to help ๐Ÿ˜„

solid swan
#

Mm...I seem to have an issue though. I need to have at least one item in subscription mode for that work, right?
Is there a way for me to access the type of payment (PAYMENT or SUBSCRIPTION) from the id_prices ?

nocturne mirage
#

Mm...I seem to have an issue though. I need to have at least one item in subscription mode for that work, right?
Yup! If one of the price has subscription plan, then mode='subscription' should be used. If none of the price is subscription, then mode='payment' can be used

charred leafBOT
solid jay
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

solid swan
#

Thank you.
I have an issue from this.
So far, my code worked with the PAYMENT mode.
However, when I changed to subscription, the paymentIntent is no longer stored in the session, which causes me a lot of internal issues.
Here is the session object:

#
  "after_expiration": null,
  "allow_promotion_codes": null,
  "amount_subtotal": 3000,
  "amount_total": 3000,
  "automatic_tax": {
    "enabled": true,
    "status": "requires_location_inputs"
  },
  "billing_address_collection": null,
  "cancel_url": "http://localhost:8080/stripe-paiement/cancel.html",
  "client_reference_id": null,
  "consent": null,
  "consent_collection": null,
  "created": 1689927012,
  "currency": "eur",
  "custom_text": {
    "shipping_address": null,
    "submit": null
  },
  "customer": null,
  "customer_creation": "always",
  "customer_details": null,
  "customer_email": null,
  "expires_at": 1690013412,
  "id": "cs_test_b1nYJ6m1iGnL9Sv7mVmDzwqT7dPOeeCW3C4H5Qjz5wVKIJx7SxtewFTIyy",
  "invoice": null,
  "invoice_creation": null,
  "line_items": null,
  "livemode": false,
  "locale": null,
  "metadata": {
    "paiementId": "BQFofqo440"
  },
  "mode": "subscription",
  "object": "checkout.session",
  "payment_intent": null,
  "payment_link": null,
  "payment_method_collection": "always",
  "payment_method_options": null,
  "payment_method_types": [
    "card",
    "link"
  ],
  "payment_status": "unpaid",
  "phone_number_collection": {
    "enabled": false
  },
  "recovered_from": null,
  "setup_intent": null,
  "shipping_address_collection": null,
  "shipping_cost": null,
  "shipping_details": null,
  "shipping_options": [],
  "status": "open",
  "submit_type": null,
  "subscription": null,
  "success_url": "http://localhost:8080/stripe-paiement/success.html",
  "tax_id_collection": null,
  "total_details": {
    "amount_discount": 0,
    "amount_shipping": 0,
    "amount_tax": 0,
    "breakdown": null
  }
solid jay
#

yes this is normal

#

when you create a subscription mode Checkout Session, once the Checkout Session completes, the subscription field will be filled and not the payment_intent

solid swan
#

but then which webhook tells me that the client has successfully paid ?

solid jay
#

invoice.paid

solid swan
#

So far with PAYMENT mode I used the payment_intent.suceeded event to update my database and change the status of payment to 'success'

#

Oh

solid jay
solid swan
#

That makes sense. Thank you

#

One last question

#

Is there a way to access the payment mode from the id_prices ?

#

I mean, telling if they are a subscription or a one-time-payment kind of product

solid jay
#

but you need to ensures that the payment_intent.succeeded will be ignored

#

so you need to add a check to that event handler

#

something like this if(payment_intent.invoice) { return; } to shortcircuit and ignore

solid swan
#

Oh in the event payment_intent.succeeded I guess ?

solid jay
#

yes

solid swan
#

Hello, before I can test this, I have an issue. I had stored a variable called 'paiementID' corresponding to my internal database payment Id. Originally, I stored it in the metadata of the session, but obviously, since the session is created after the checkout is completed, I can't do this here.
Do you know where I could store this data and recuperate it in another servlet ?

solid jay
#

I'm not sure I fully understand

solid swan
#

Sorry...
At first, I was storing a variable in the metadata of the session. Then, I could retrieve it from the webhooks I received, enabling me to update my own database.
However, things are different now since I can't access the session (as it is created after checkout.session.completed)

solid jay
#

However, things are different now since I can't access the session (as it is created after checkout.session.completed)
It's that part that I'm having trouble understanding

#

once you create the Checkout Session, if you've passed in metadata on creation you would always have it