#dixzzer-pi

1 messages ยท Page 1 of 1 (latest)

dusk knoll
#

Hi there, please give me a moment to digest your code.

rocky star
#

OK, but this is not my code is from the Stripe docs, and types.ts files

dusk knoll
#

I was wondering if I could clarify your question, you are looking for the type of the payment_intent variable?

rocky star
#

In this condition when the payment intent is falsy ?```paymentIntent && paymentIntent.status === 'succeeded'``

#

the left side of the &&

#

if the paimentIntent object exist is true always right?

dusk knoll
#

If you have passed the PaymentIntent's client secret in correctly on the following line:

#

stripe.confirmCardPayment(clientSecret);

#

Then, yes, the PaymentIntent object should be returned, therefore the first check on the conditional block is true.

rocky star
#

So this check is unnecessary?, is enough with
the right side of the expression ?
bad-
paymentIntent && paymentIntent.status === 'succeeded'
good-
paymentIntent.status === 'succeeded'

dusk knoll
#

I am not the most familiar with typescript, if paymentIntent is null, would this right conditional check throw a null pointer exception?

rocky star
#

in JS/TS exist truthy/falsy value and in this check taken from the docs

    // Handle error here
  } else if (paymentIntent && paymentIntent.status === 'succeeded') {
    // Handle successful payment here
  }```
if the paymentIntent in the else if part can't be falsy there is no reason to put it the expression
#

the original question is, When this value can be falsy?

#

Falsy values

if (false)
if (null)
if (undefined)
if (0)
if (-0)
if (0n)
if (NaN)
if ("")```
#

So my question is, if I need this check to handle the successful payment status

#

Or just with this one is ok,

  // Handle error here
} else if (paymentIntent.status === 'succeeded') {
  // Handle successful payment here
}```
dusk knoll
#

I recommend having both conditional statements, in case the PaymentIntent's client secret is not passed correctly, the PaymentIntent object will be null.
I will definitely include the left side of the conditional statement to filter out the nulls, and prevent running into null exceptions.

nocturne flickerBOT
#

This thread has been archived. If you need help with anything else please ask in #dev-help or contact Stripe Support: https://support.stripe.com/contact

drowsy harness
#

copying this here for context

about the paymentIntent condition question in the docs , you tell me this

"in case the PaymentIntent's client secret is not passed correctly, the PaymentIntent object will be null"

My question is, what scenario this can happen, because if the API request give me some error the upper if handle it, and otherwise the paymentIntent will always exist unless I'm misinterpreting the flow, that's why my insistence, I want to be sure that the logic of the integration with Stripe is correct since payments are a very serious issue. Thanks for the previous answers

this is the full code of the docs
(async () => {
const {paymentIntent, error} = await stripe.confirmCardPayment(clientSecret);
if (error) {
// Handle error here
} else if (paymentIntent && paymentIntent.status === 'succeeded') {
// Handle successful payment here
}
})();

#

Give me a moment to catch up on the context here

#

If you're super confident about your flow, you can omit it but just in-case if there's a situation where the paymentIntent ends up being {} an empty object, that would be a truthy value

#

and paymentIntent.status would trigger an error

rocky star
#

if the pyamentIntent is {}, is truthy, hence the other check is necessary paymentIntent.status === status

#

I just trying to understand the logic behind this decision in a way that I'm do not make a mistake

drowsy harness
#

gotcha.
the conditional logic is to make sure that we don't call .status on something that may throw an exception
if you're confident about your flow, you don't need it

rocky star
#

OK, thanks you very much. ๐Ÿ‘

drowsy harness
#

NP! ๐Ÿ™‚