Apple Pay Button on Web with React Js doesn't works because onvalidatemerchant doesn't make anything

755 Views Asked by At

I have a persistent issue. When i make a GET to the endpoint, this is my response:

 "epochTimestamp": 1689705258191,
    "expiresAt": 1689708858191,
    "merchantSessionIdentifier": "SSH8907CA4E29424A14969C5450CA01D99E_C23A0D3024FAB8B12CBB67660B4C1B48ABF1272EC8B61399E3A647290C8BE67A",
    "nonce": "6e127ad6",
    "merchantIdentifier": "B06C8CE272C72F8CC8C496721B5AB7904427AC91188AB4F711A54FEC31B5CDE5",
    "domainName": "ecommerce.bckd.co",
    "displayName": "Bucked Up",
    "signature": "308006092a864886f7005073001862a687474703a2f2f6f6373702e6170706c652e636f6d2f6f63737030342d6170706c65726f6f74636167333235e7658b5f6e1101e22641614cb96e1d702205b156449d1e5573006889f18800f7fca2d5326cfeeb7cfb2ca59fb1e57eb25b2000000000000",
    "operationalAnalyticsIdentifier": "BuckedUp:B06C8CE272C72F8CC8C496721B5AB7904427AC91188AB4F711A54FEC31B5CDE5",
    "retries": 0,
    "pspId": "B06C8CE272C72F8CC8C496721B5AB7904427AC91188AB4F711A54FEC31B5CDE5"
}

and this is the that I use to display the payment sheets. But nothing happen, is like session.onvalidatemerchant doesn't make anything:

export default function ApplePayButton() {

  // Constants

  const startApplePaySession = async () => {

    if (window.ApplePaySession) {

      const appleSession = window.ApplePaySession

      // Define ApplePayPaymentRequest
      const request = {
        'countryCode': 'US',
        'currencyCode': 'USD',
        'merchantCapabilities': [
          'supports3DS'
        ],
        'supportedNetworks': [
          'visa',
          'masterCard',
          'amex',
          'discover'
        ],
        'total': {
          'label': 'Demo (Card is not charged)',
          'type': 'final',
          'amount': '2.00' // harcoded amount
        }
      }

      const session = new appleSession(6, request)

      session.onvalidatemerchant = async function(event) {

        try {

          const {data} = await getApplePay()

          session.completeMerchantValidation(data)

        } catch (error) {

          console.log(error)

        }

      }

      session.begin()

    }

  }

  return (
    <button
      className='apple-pay-btn'
      id='apple-btn'
      onClick={startApplePaySession}
    >
      Button here
    </button>
  )

}

Please what I'. making wrong??!!!

I tried a lot of things, I need to display the payment sheets of Apple when the customer clicks in our checkout, like with Paypal or another similar craps. But nothing happens with this onvalidatemerchant, in fact I can console ANYTHING inside this function, is like never works.

Please help me guys!

0

There are 0 best solutions below