Home > database >  How to know if Stripe payment intent or session has been refunded?
How to know if Stripe payment intent or session has been refunded?

Time:12-29

When I iterate through sessions or payment intents using stripe, status does not reveal if payment has been refunded.

How to know if Stripe payment intent or session has been refunded?

CodePudding user response:

The PaymentIntent itself will not change when the payment is refunded. In Stripe, refunds are created off of the underlying Charges. You can if a payment intent was refunded by checking its latest_charge's refunded property.

const paymentIntent = await stripe.paymentIntents.retrieve(
  'pi_1234',
  ['expand' => ['latest_charge']]
);
  const refunded = paymentIntent.latest_charge.refunded;
  const amount_refunded = paymentIntent.latest_charge.amount_refunded;
);

[1] https://stripe.com/docs/api/errors?lang=node#errors-payment_intent-latest_charge

[2] https://stripe.com/docs/api/charges/object?lang=node#charge_object-refunded

  • Related