How can I look up the amount refunded for a given payment intent in Stripe via API call?
Let s say I have a payment intent (pi_3NnXXYKI47gqqtmf0eR178Es
), how can I check if it has been fully or partially refunded and by how much?
Using the stripe cli, I see there is a latest_charge
property:
stripe payment_intents retrieve pi_3NnXXYKI47gqqtmf0eR178Es
{
"id": "pi_3NnXXYKI47gqqtmf0eR178Es",
"object": "payment_intent",
"amount": 2500,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 2500,
"application": null,
"application_fee_amount": 500,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"client_secret": "pi_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"confirmation_method": "automatic",
"created": 1694053104,
"currency": "usd",
"customer": "cus_OTWo2r0gDDcyoj",
"description": null,
"invoice": "in_1NnXn3KI471qqtmftliLpC1g",
"last_payment_error": null,
"latest_charge": "ch_3NuInYKx47gqotmf0Rp7uWyX",
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": "acct_1Nm3Xy2eoonJLRTG",
"payment_method": "pm_10gZ42Kp47gqqtmfT4SWIXKK",
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"processing": null,
"receipt_email": "bob@example.com",
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": {
"destination": "acct_1Nm3r22eNoJJVRTG"
},
"transfer_group": "group_pi_3NnXnkXI47gqqtmf0eRI78Es"
}
I can then look up the "latest charge" via the cli like so:
stripe charges retrieve ch_3NuInYKx47gqotmf0Rp7uWyX
{
"id": "ch_3NuInYKx47gqotmf0Rp7uWyX",
"amount_refunded": 1500,
...
}
Is this approach reliable? Is it possible that the payment intent has a charge that has a refund and is NOT the latest charge? The API documentation was sparse for the latest_chage property.
Any pointers are welcome!