Midtrans / midtrans-nodejs-client

Official Midtrans Payment API Client for Node JS | https://midtrans.com
MIT License
174 stars 56 forks source link

iOS 12 Error: snap.pay is not allowed to be called in this state #67

Open rafonzoo opened 6 months ago

rafonzoo commented 6 months ago

Hi, thanks for great snapjs payment to ease us doing a payment! disclaimer: Im using https://app.sandbox.midtrans.com/snap/snap.js, am i put this issue in the correct place? I can't find the repo regarding this snap js to put an issue.

This issue only happened in iOS 12, but it is fine in latest iOS. Here full log:

Error: snap.pay is not allowed to be called in this state. Invalid state transition from PopupInView to PopupInView (anonymous function) — snap.js:232
  ex — 8967.304662da3cf90d03.js:148
  onSuccess — 8967.304662da3cf90d03.js:144
  promiseReactionJob

I call the window snap like:

if (!('snap' in window)) {
  const script = document.createElement('script')
  script.type = 'text/javascript'
  script.dataset.clientKey = process.env.NEXT_PUBLIC_MIDTRANS_CLIENT_KEY ?? '' // prettier-ignore
  script.src = midtrans('/snap/snap.js')
  script.onload = () => onCallback(token, payload)

  document.head.append(script)
  return
}

onCallback(token, payload)

where onCallback is:

window.snap.pay(token, {
  onSuccess: (result: unknown) => {
    const { transaction: trx } = paymentType.shape
    const transaction = trx.parse(result)

    checkout([...detail.payment, { ...payload, transaction }])
  },
})

Help to explain why the error happened, or snap.js not supported in iOS 12 ? Thankyou! snap.js: https://app.sandbox.midtrans.com/snap/snap.js