#estani.p - payment_method
1 messages · Page 1 of 1 (latest)
Hi 👋
If you take a look here: https://stripe.com/docs/api/payment_intents/object
You can get the ID as an attribute, i.e. paymentIntent.payment_method
Or you can expand it if you need more information.
Thanks!
FYI, heres a useful doc for when you want to expand some of those properties that return other object IDs:
https://stripe.com/docs/expand
The problem I have is that I am calling stripe.paymentIntents.retrieve after stripe.confirmPayment({
elements,
confirmParams. And the retrieve is not bringing me the updated status of the payment. I'm calling the confirmPayment on the front end, and the retrieve on the back end.
Okay so you are not seeing the 'status' property on the paymentIntent? Or it isn't updating?
Is not updating
Is there a reason you want to fetch synchronously and not use the webhook?
after call confirmPayment i call the retrieve in back and its not update
Can you share the code you are using?
No
Yes
I create the paymentIntent
fetch('http://localhost:4000/shoppingCart/create-payment-intent', {
body : JSON.stringify({ shoppingCart }),
headers: { 'Content-Type': 'application/json' },
method : 'POST'
})
.then((res) => res.json())
.then((data) => {
setPi(data.paymentIntent.id)
setClientSecret(data.clientSecret)
})
then the onClick on pay button its doing this:
const { error } = await stripe.confirmPayment({
confirmParams: {
return_url: 'http://localhost:3000/checkout/info'
},
elements
})
and the useEffect is listen to stripe change and do this:
fetch('http://localhost:4000/shoppingCart/confirmStripe', {
body : JSON.stringify({ pi }),
headers: { 'Content-Type': 'application/json' },
method : 'POST'
})
.then((res) => res.json())
.then((data) => {
console.log(data)
})
in back:
const { pi } = req.body
const paymentStatus = await stripe.paymentIntents.retrieve(pi)
res.send({
status: paymentStatus.charges.data
})
I am guided by this documentation https://stripe.com/docs/payments/quickstart
But after confirmPayment i want to get the payment status in back to save the status payment in DB
Well you may be retrieving this value before it has a chance to update. This is why we recommend using webhooks, since the payment transactions.
OK, how can I use webhooks in this case?
Here are the docs: https://stripe.com/docs/webhooks
I now it's a whole other thing to construct
but it's pretty useful once you get it built out
Lurk: I don't think you want to go deep in webhook right now while you haven't fully grasped the basics of the integration
I think what's important here is to log exactly what you are getting back from the PaymentIntent Retrieve API Request, because if this happens after the redirect the status should have updated for cards already
PAYMENTSTATUS {
id: 'pi_3KGsSfLTMnGV6Q0F0f9B6014',
object: 'payment_intent',
amount: 39047,
amount_capturable: 0,
amount_received: 0,
application: null,
application_fee_amount: null,
automatic_payment_methods: { enabled: true },
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic',
charges: {
object: 'list',
data: [],
has_more: false,
total_count: 0,
url: '/v1/charges?payment_intent=pi_3KGsSfLTMnGV6Q0F0f9B6014'
},
client_secret: 'pi_3KGsSfLTMnGV6Q0F0f9B6014_secret_B9QvubTU5chgzIDS9UwSF3Mvd',
confirmation_method: 'automatic',
created: 1641938701,
currency: 'eur',
customer: null,
description: 'Actividades de Vipealo',
invoice: null,
last_payment_error: null,
livemode: false,
metadata: {},
next_action: null,
on_behalf_of: null,
payment_method: null,
payment_method_options: {
card: {
installments: null,
network: null,
request_three_d_secure: 'automatic'
}
},
payment_method_types: [ 'card' ],
processing: null,
receipt_email: 'carlos@carlos.com',
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'requires_payment_method',
transfer_data: null,
transfer_group: null
}
yeah so I don't think you are doing what you think you are. This Retrieve isnot happening after the redirect
you've never confirmed that PaymentIntent yet, you just created it and nothing else
This i get after from retrieve, after confirPayment, the status stay requires payment method
no I can tell you 100% it's not what's happening
you have never confirmed that payment intent yet
Yes, because when I test retrieve with the pi in postman, after the code has been executed, I am getting the updated payment.
Just to clarify, I work for Stripe, I have access to a lot of data, that PaymentIntent you shared above has never been confirmed
maybe you retrieve the wrong PaymentIntent id?
this is my code
Of course, I'm not doubting that. I just can't figure it out.
I know you shared it above, that doesn't really help me much, it says ~nothing about when you run what and you seem to mix up multiple concepts unfortunately
but the code you have in the first picture does not run after the confirmation.
i take it from https://stripe.com/docs/payments/quickstart
yeah I know but most of that doesn't really matter, beyond taking it from the doc there's a step of understanding each thing that matters here
Okk thanks
I think you really need to add a log line before/after each call and you should confirm you never see the log lines for the confirmPayment call
Thanks, ill try it
Cool, if you can add logs before after retrieve and confirmPayment you should see the confirmPayment is not happening
Yes, I'll try. If a test the retrieve endpoint after that is returning the data updated. I have to look how resolve it
Or check the retrieve in another component
This flow is ok o you recommended me use webhooks?
let's ignore webhooks entirely for now
Ok, thanks!!!