Skip to content

PayKKa Checkout UI Component

How It Works

Description of image

Preparation

You can install the PayKKa Checkout UI npm package, or embed it into HTML via CDN:

Install @paykka/card-checkout-ui:

npm i @paykka/card-checkout-ui

To properly display the component, you need to import the styles globally:

import '@paykka/card-checkout-ui/style.css'

Creating PayKKaCheckout Instance

Parameters and events that can be passed when creating a PayKKaCheckout instance:

Required parameters are marked with *.

Name Description Type
*sessionIdCheckout ID, used to create the checkout.string
*clientKeyClient key.string
*envEnvironment configuration.
  • eu for European merchants.
  • hk for Hong Kong merchants.
  • sandbox for sandbox environment merchants.
localeCheckout text display language.
  • If not provided, browser language will be used. If browser language is not supported, en-GB will be used by default.
  • Currently supports the following 11 international languages, displayed in IETF BCP 47 format:
    • de-DE: German (Germany)
    • en-GB: English (United Kingdom)
    • es-ES: Spanish (Spain)
    • fr-FR: French (France)
    • ja-JP: Japanese (Japan)
    • ko-KR: Korean (South Korea)
    • pt-PT: Portuguese (Portugal)
    • ru-RU: Russian (Russia)
    • zh-CN: Chinese (China)
    • zh-HK: Chinese (Hong Kong)
    • zh-TW: Chinese (Taiwan)
string
hidePaymentButtonWhether to hide the payment button, defaults to false.
  • If the payment button is hidden, you need to manually call the component's payment method to make a payment.
boolean
threeDSFrame3DS configuration object, containing the following parameters:
  • modalWidth: 3DS popup width, defaults to adaptive if not provided. Pass number for units in px, pass string for custom units, minimum width is 350px.
  • modalHeight: 3DS popup height, defaults to adaptive if not provided. Pass number for units in px, pass string for custom units, minimum height is 500px.
ThreeDSFrameConfig
onPaymentMethodsReadyTriggered when the checkout has obtained available payment methods.
  • methods is the list of available payment methods.
  • If an empty array is returned, it means no payment methods are available, and the component will not be displayed.
  • When the checkout status is success or expired, an empty array will also be returned.
  • Currently supports the following 8 payment methods:
    • APPLE_PAY: Apple Pay
    • GOOGLE_PAY: Google Pay
    • VISA: Visa
    • MASTER_CARD: Master Card
    • JCB: JCB
    • AMEX: AMEX
    • DINERS_CLUB: Diners Club
    • DISCOVER: Discover
(methods: PaymentMethod[]) => void
onInitErrorTriggered when checkout initialization fails.
  • 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.
  • This callback will also be triggered when reinitializing after checkout status is success or expired.
(error: PayKKaError) => void
onSubmitGlobal event triggered when submitting the form.
  • formValidateError is the form validation error information.
  • Can be overridden by the same-named event defined in the Component.
(formValidateError?: Record<string, FormValidateError[]>) => void
onSuccessGlobal event triggered after successful payment.
  • returnUrl is the link to redirect to after payment is completed.
  • Can be overridden by the same-named event defined in the Component.
({returnUrl?: string}) => void
onTimeoutGlobal event triggered when payment times out.
  • Users can resubmit the form to make a payment.
  • Can be overridden by the same-named event defined in the Component.
() => void
onExpiredGlobal event triggered when the session expires or becomes invalid, or when the component is called again after successful payment.
  • Can be overridden by the same-named event defined in the Component.
() => void
onErrorGlobal event triggered after payment failure.
  • 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.
  • Users can resubmit the form to make a payment.
  • Can be overridden by the same-named event defined in the Component.
(error: PayKKaError) => void

Here's an example of usage:

import { PayKKaCheckout } from '@paykka/card-checkout-ui'
// Create PayKKaCheckout instance
const paykkaCheckout = new PayKKaCheckout({
  sessionId: 'xxx',
  clientKey: 'xxx',
  env: 'eu',
  locale: 'en-GB',
  hidePaymentButton: false,
  threeDSFrame: {
    modalWidth: '350px',
    modalHeight: '500px',
  },
  onPaymentMethodsReady: (methods) => {
    console.log('Supported payment methods', methods)
  },
  onInitError: (error) => {
    console.log('Initialization error', error)
  },
  onSubmit: (formValidateError) => {
    console.log('Form submission global event', formValidateError)
  },
  onSuccess: ({ returnUrl }) => {
    console.log('Payment success global event', returnUrl)
  },
  onTimeout: () => {
    console.log('Payment timeout global event')
  },
  onExpired: () => {
    console.log('Session expired or invalid global event')
  },
  onError: () => {
    console.log('Payment failure global event')
  }
})

Detailed Explanation

Custom Payment Button

hidePaymentButton is used to configure whether to hide PayKKa's built-in payment button.

If you want to use your own payment button, you can set hidePaymentButton to true to hide PayKKa's payment button. After users click your payment button, you can call the payment method exposed by the component instance to process the payment.

Here's an example using the Card component:

html
<button onclick="handleClickPayment()">Pay</button>
javascript
// Assuming we have initialized the checkout and set hidePaymentButton to true
import { Card } from '@paykka/card-checkout-ui'

// Create Card component
const CheckoutCard = paykkaCheckout.create(Card, {
  // card configuration
})

const handleClickPayment = () => {
  // After clicking the payment button, call the payment method to process payment
  CheckoutCard.ref.payment()
}

Fraud Detection

For fraud detection (FraudDetection) configuration, please refer to Fraud Detection SDK.

Error Codes

See Transaction Error Codes

Creating Component Instance

After creating the checkout instance, you can create components. For example, let's say we need to import the Card component:

Step 1: Create DOM Element

Create a DOM element in your checkout page that will be used to render the Component.

<div id="card-container"></div>

It is strongly recommended not to create this DOM element inside an iframe element, as it may prevent the checkout from functioning properly.

Step 2: Import Component and Build Instance

import { PayKKaCheckout, Card } from '@paykka/card-checkout-ui'

// Steps to create PayKKaCheckout instance omitted here

const checkoutCard = paykkaCheckout.create(Card, {
  // Parameters required for Card component
})

Step 3: Mount Component

const container = document.querySelector('#card-container')
checkoutCard.mount(container)

If you are using JavaScript frameworks like Angular, Vue, React, etc., please ensure that the DOM has been rendered before mounting, and do not re-render the element.

Using Sandbox Environment

If you want to integrate the checkout in a sandbox environment, follow these steps.

  1. If using CDN import, you need to use the sandbox environment link (for npm method, proceed to the next step):
<link href="https://checkout-sandbox.aq.paykka.com/cp/style.css" rel="stylesheet" />
<script src="https://checkout-sandbox.aq.paykka.com/cp/card-checkout-ui.js"></script>
  1. When creating the checkout, set env to sandbox:
const paykkaCheckout = new PayKKaCheckout({
  sessionId: 'xxx',
  clientKey: 'xxx',
  env: 'sandbox'
  // ...other options
})