#vm1172

1 messages · Page 1 of 1 (latest)

fiery wyvernBOT
analog obsidian
#

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

real magnet
#

what do you mean by fire an AJAX to the backend?

analog obsidian
#

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

real magnet
#

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}
        />
real magnet
real magnet
analog obsidian
#

To clarify, is this your JS code calling your backend?

    const result = await CheckoutSessionAPI.updatePaymentIntent(
      paymentIntentId,
      shippingContact,
      amount + normalizedTax,
      token
    )
analog obsidian
#

While you are already doing that, did it work or get you in another issue?

fiery wyvernBOT
real magnet
#

no i’m still encountering the same errors unfortunately :/

inland sun
#

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

real magnet
#

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?

inland sun
#

Well, correction: it returns a promise, that resolves to a Payment Intent and Payment Method

real magnet
#

right, for some reason it isn't triggering for me

inland sun
#

What do you mean?

real magnet
#

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?

inland sun
#

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?

real magnet
#

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

inland sun
#

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