Closed holahoon closed 1 week ago
@holahoon PaymentIntent doesn't have the property payment_method_details
anywhere (and never did). That property lives on the Charge object which is a completely separate API resource.
A PaymentIntent has the property latest_charge
which is set to the id of the latest Charge associated with it, if any. It's an id but you can use our Expand feature (see this video) to get the full Charge object.
Note that on older API versions before 2022-11-15, a PaymentIntent had the charges
property which was a sub-list with the most recent Charge object on it. That might be what made you think that it has the property. This was deprecated 2 years ago and it still confirms that this property was on the Charge object.
If you use an old API version then you would see that charges
property but the types in stripe-node always match the latest version of our API. So if you are looking for that information, you need to look at the types for Charge and you can see it defined in our code here
Yeah, you are right. I must've had a long week 🤦🏻
I was asserting Stripe.PaymentIntent
type to the data object for charge.succeeded
event type. This data type should've been of type Stripe.Charge
try(event.type)
...
case 'charge.succeeded':
data = object as Stripe.PaymentIntent // <-- this should be of type `Stripe.Charge`
console.log(`💰 Charge status: ${data.status}`)
// cannot access data.payment_method_details
// even though the data is actually being returned
break
Thanks for clarifying 👍
Describe the bug
Using NextJS 14. I'm trying to get the last 4 digits of the card on payment success event. I set up my code to create a payment intent from the server with
confirm: true
and allow the stripe webhook to listen forcharge.succeeded
type and process other database related logics within the block. So I checked the console to see what type of data I get back and I noticed thepayment_method_details
object which includes the card information, very similar to whatstripe.paymentMethods.retrieve()
would return. I was trying to use this card info, but quickly realized that thispayment_method_details
property type doesn't exist in thePaymentIntent
type. I'm curious if this field was never intended to be included inside thePaymentIntent
object or it's just missing a type?To Reproduce
Submit element and create confirmation token on the frontend (with
useElements()
anduseStripe()
React hooks).Take the
confirmation_token
from the frontend and create a payment intent from the server.Allow webhook to listen and for
charge.succeeded
event type, trigger db logics.Expected behavior
Expect
payment_method_details
object type to be included in thePaymentIntent
object type.Code snippets
No response
OS
macOS
Node version
Node v20.12.2
Library version
stripe v16.1.0
API version
2023-10-16
Additional context
No response