#vm1172
1 messages · Page 1 of 1 (latest)
Hi, I think this doesn't really return the PaymentIntent https://stripe.dev/stripe-react-native/api-reference/index.html#confirmPlatformPayPayment
Documentation for @stripe/stripe-react-native
It returns a promise of PlatformPay.ConfirmPaymentResult
But anw, if you want to update the PaymentIntent, it's easier to fire an AJAX to backend, then update from backend
but PlatformPay.ConfirmPaymentResult is of type { paymentIntent: PaymentIntent.Result; error?: StripeError<PlatformPayError> } | { paymentIntent?: undefined; error: StripeError<PlatformPayError> }
ref: https://stripe.dev/stripe-react-native/api-reference/modules/PlatformPay.html#ConfirmPaymentResult
what do you mean by fire an AJAX to the backend?
Sorry you were right that a PaymentIntent should be returned there. If you do
console.log(JSON.stringify(paymentIntent, null, 2));
wouldn't it log anything?
By AJAX request I mean send a request to your backend, and let the backend do the update work
yeah so thats actually what we want (and need) to do
this is what is triggered onPress
const pay = async () => {
const token = await getItem("token")
const clientSecret = await CheckoutSessionAPI.createPaymentIntent(productId, token)
const { error, paymentIntent } = await confirmPlatformPayPayment(clientSecret, params)
console.log('paymentIntent', paymentIntent)
setPaymentIntentId(paymentIntent.id)
if (error) {
console.error('Stripe Apple Pay Error', error)
} else {
console.log(JSON.stringify(paymentIntent, null, 2))
}
}
const onShippingContactSelected = async (shippingContact: ShippingContact) => {
const token = await getItem("token")
const amount = props.price
const postalCode = shippingContact.postalAddress.postalCode
const tax = await CheckoutSessionAPI.calculateTax(amount, productId, postalCode, token)
const normalizedTax = tax / 100
const params: {
applePay: {
cartItems: PlatformPay.CartSummaryItem[]
shippingMethods: PlatformPay.ShippingMethod[]
errors: PlatformPay.ApplePaySheetError[]
}
} = {
applePay: {
cartItems: [
{
label: 'Subtotal',
amount: amount.toString(),
paymentType: PlatformPay.PaymentType.Immediate
},
{
label: 'Tax',
amount: normalizedTax.toString(),
isPending: false,
paymentType: PlatformPay.PaymentType.Immediate
},
{
label: 'Shipping',
amount: '0.00',
isPending: false,
paymentType: PlatformPay.PaymentType.Immediate
},
{
label: 'Total',
amount: (amount + normalizedTax).toString(),
isPending: false,
paymentType: PlatformPay.PaymentType.Immediate
}
],
shippingMethods: [
{
identifier: 'free-shipping',
label: 'Free shipping',
detail: 'Arrives in 15 to 30 days',
amount: '0.00'
}
],
errors: []
}
}
const { error } = await updatePlatformPaySheet(params)
console.error('error', error)
const result = await CheckoutSessionAPI.updatePaymentIntent(
paymentIntentId,
shippingContact,
amount + normalizedTax,
token
)
console.log(order, order)
console.log('result', result)
}
and this is the PlatformPayButton
<PlatformPayButton
onPress={pay} // triggered first
onShippingContactSelected={async (contact) =>
onShippingContactSelected(contact.shippingContact) // triggered after shipping contact information available or selected
}
onCouponCodeEntered={(code) => console.log('code', code)}}
type={PlatformPay.ButtonType.Order}
appearance={PlatformPay.ButtonStyle.Automatic}
/>
no it does not log anything, i’ve shared the code we have above
yes, that’s what we do already, since that’s the only way we can update the stripe metadata for our internal use and update the price with tax information after calculating it
To clarify, is this your JS code calling your backend?
const result = await CheckoutSessionAPI.updatePaymentIntent(
paymentIntentId,
shippingContact,
amount + normalizedTax,
token
)
While you are already doing that, did it work or get you in another issue?
correct, this calls and updates the payment intent from the BE
no i’m still encountering the same errors unfortunately :/
Hi there 👋 taking over, as my colleague needs to step away
Give me a few minutes to get caught up.
You mentioned you're getting an error, but I don't see an error message in the thread. What error are you getting? Where is it coming from (client or server)?
yeah one second, let me share the errors
actually lets step back a second. what is the best way to return the paymentIntent id from confirmPlatformPayPayment?
That should just return the Payment Intent: https://stripe.dev/stripe-react-native/api-reference/index.html#confirmPlatformPayPayment
Documentation for @stripe/stripe-react-native
Well, correction: it returns a promise, that resolves to a Payment Intent and Payment Method
right, for some reason it isn't triggering for me
What do you mean?
My logs are pretty empty on the FE
ERROR error undefined
ERROR error {}
WARN Sentry Logger [warn]: [SdkInfo] Native SDK Info retrieval failed...something could be wrong with your Sentry installation:
WARN Sentry Logger [warn]: [SentryError: Native is disabled]
WARN Possible Unhandled Promise Rejection (id: 1):
SyntaxError: JSON Parse error: Unexpected character: <
LOG Sentry Logger [log]: Not capturing exception because it's already been captured.
I have console logs for paymentIntent and paymentIntent.id but its not showing up in my console.log(). Am I not triggering the function correctly or should I put it in some place else?
It sounds like you're getting an error, which means that it's returning an error instead of the promise.
Are you able to step through the code and fix the errors?
Unfortunately cannot debug it since this is RN + Expo. I have my BE so I'll try and go through the logs there and see if the updatePaymentIntent endpoint is erroring out. give me a couple of minutes to try and see if I can share any additional details
Okay, sounds good. Yeah, based on my limited understanding at this point, I would assume that the errors need to be rectified before this request is going to resolve as the Promise you would expect