#estani.p - payment_method

1 messages · Page 1 of 1 (latest)

barren laurel
#

Hi 👋

#

You can get the ID as an attribute, i.e. paymentIntent.payment_method

#

Or you can expand it if you need more information.

cunning crescent
#

Thanks!

barren laurel
cunning crescent
#

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.

barren laurel
#

Okay so you are not seeing the 'status' property on the paymentIntent? Or it isn't updating?

cunning crescent
#

Is not updating

barren laurel
#

Is there a reason you want to fetch synchronously and not use the webhook?

cunning crescent
#

after call confirmPayment i call the retrieve in back and its not update

barren laurel
#

Can you share the code you are using?

cunning crescent
#

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
})

#

But after confirmPayment i want to get the payment status in back to save the status payment in DB

barren laurel
#

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.

cunning crescent
#

OK, how can I use webhooks in this case?

barren laurel
#

I now it's a whole other thing to construct

#

but it's pretty useful once you get it built out

opaque spire
#

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

cunning crescent
#

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
}

opaque spire
#

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

cunning crescent
#

This i get after from retrieve, after confirPayment, the status stay requires payment method

opaque spire
#

no I can tell you 100% it's not what's happening

#

you have never confirmed that payment intent yet

cunning crescent
opaque spire
#

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?

cunning crescent
cunning crescent
cunning crescent
opaque spire
#

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.

cunning crescent
opaque spire
#

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

cunning crescent
#

Okk thanks

opaque spire
#

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

cunning crescent
#

Thanks, ill try it

opaque spire
#

Cool, if you can add logs before after retrieve and confirmPayment you should see the confirmPayment is not happening

cunning crescent
#

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?

opaque spire
#

let's ignore webhooks entirely for now

cunning crescent
#

Ok, thanks!!!