Skip to content

Google Pay

Example

<div id="checkoutGooglePayField"></div>
import { GooglePay } from '@paykka/card-checkout-ui'

const checkoutGooglePay = paykkaCheckout.create(GooglePay, {
  // GooglePay props
})
checkoutGooglePay.mount('#checkoutGooglePayField')

Environment Detection

When creating the Google Pay component, we first import the official Google Pay SDK. You can use the onload method to determine if the SDK loaded successfully:

const props = {
  onload: status => {
    console.log(status ? 'Load successful' : 'Load failed')
  }
}

If you find that the SDK loaded successfully but the Google Pay button is not visible on the page, it may be due to device environment issues or other reasons preventing payment. We provide the onCanUse callback method to inform you. For specific reasons why it might not be visible, please refer to: Google Pay Official Documentation.

const props = {
  onCanUse: canUse => {
    console.log(canUse ? 'Available' : 'Unavailable')
  }
}

Attributes

GooglePayProps

Passed when calling the create method to create GooglePay.

Name Description TypeDefault
onSubmitTriggered after Google Pay payment authorization is successful.() => voidundefined
onSuccessCallback after successful payment.
  • PaymentSuccessData contains the information returned after successful payment, please refer to.
(data: PaymentSuccessData) => voidundefined
onTimeoutCallback when payment times out, can resubmit the form for payment.() => voidundefined
onExpiredCallback when the checkout counter has expired during payment, cannot pay again.() => voidundefined
onErrorCallback after payment failure, can resubmit the form for payment.
  • error is a PayKKaError instance, typically containing the following properties:
    • type: Error type.
    • message: Error message.
    • code: Error code, when an API error occurs, it will return a specific error code.
(error: PayKKaError) => voidundefined
onLoadGoogle Pay SDK load callback.
  • status indicates whether the load was successful.
(status: boolean) => voidundefined
onCanUseWhether Google Pay payment is available.
  • canUse indicates whether it is available.
(canUse: boolean) => voidundefined

Below is an explanation of some data types:

PaymentSuccessData

Information returned after successful payment.

interface PaymentSuccessData {
  /** URL that can be redirected to after successful payment */
  returnUrl?: string
}