6

I am integrating stripe using php by following this tutorial: https://phppot.com/php/manage-recurring-payments-using-stripe-billing-in-php/ (my website has some subscription plans and redirects to the stripe checkout form ) . however, for the last step, I decided not to use webhooks, I chose to store the info like in this tutorial https://www.codexworld.com/stripe-checkout-payment-gateway-integration-php/ (I know it is not for subscription but I just use the success.php code from this tutorial to collect the customer info and payment intent details). I tested it, gone throught the stripe checkout form , and on success I printed the checkout session object and noticed that the payment_intent field of that object is empty ! so i cannot load the payment intent object and get its info although the payment is successfully made and it is showing on the dashboard . any idea why ??

EDIT : According to the documenttaion of a checkout session (https://stripe.com/docs/api/checkout/sessions/object), the payment_intent field stores the ID of the PaymentIntent for Checkout Sessions in payment mode. In my case I have a subscription mode not a payment one. however,if I still want to get the $intent->status , can I use the payment_status field of the session object $checkout_session->payment_status? And if subcription payments really don't have paymentintents , then why did the payment appear in the payments section on the dashboard?

1 Answer 1

9

Based on the mode you passed in, either one of payment_intent, subscription or setup_intent will be populated, the rest will be null.

When a Subscription is made, your user is invoiced so it is considered a payment and will appear in the Payments dashboard. You can retrieve the Subscription and access the latest_invoice field to obtain the Invoice object. The Invoice object contains the payment_intent field. This is likely what you're looking for.

Using webhook would simplify the process, since you could listen to invoice.payment_suceeded to retrieve the PaymentIntent ID.

15
  • Thank you so much ! I would like to use webhooks but should i simply put invoice.payment_succeeded instead of the list mentioned here ? phppot.com/php/… .. I avoided using webhooks, because all the sending processes fail (probably beacuse of the test mode) so i couldn't test my code and the second problem is that subscription_updated event is appearing instead of subscription_created. Commented Mar 9, 2021 at 12:04
  • You do not have to listen to all the webhook events. It really depends on your business flow. But yes, the list mentioned is the full list of Subscription life cycle events that Stripe will send to your webhook URL. Test mode doesn't have an effect on webhook. You need to have an server endpoint that the Stripe server can reach. Alternatively, you can redirect webhook to your localhost web server stripe.com/docs/webhooks/test
    – Zhi Kai
    Commented Mar 9, 2021 at 13:56
  • subscription_updated because there's likely already an existing Subscription, and details of it has changed, e.g. new start/end period, invoice, etc. subscription_created only ever happens once for every new Subscription.
    – Zhi Kai
    Commented Mar 9, 2021 at 13:57
  • Thnk you for your answers, no in fact it is a new user subscribing for the first time and passing through the stripe payment form , so it is not updated ,it must be created .. Commented Mar 9, 2021 at 14:31
  • 1
    I did but i have less than 15 reputations so it doesn't show up. :) Commented Mar 12, 2021 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.