
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-uiTo properly display the component, you need to import the styles globally:
import '@paykka/card-checkout-ui/style.css'Parameters and events that can be passed when creating a PayKKaCheckout instance:
Required parameters are marked with *.
| Name | Description | Type |
|---|---|---|
| *sessionId | Checkout ID, used to create the checkout. | string |
| *clientKey | Client key. | string |
| *env | Environment configuration.
| |
| locale | Checkout text display language.
| string |
| hidePaymentButton | Whether to hide the payment button, defaults to false.
| boolean |
| threeDSFrame | 3DS configuration object, containing the following parameters:
| ThreeDSFrameConfig |
| onPaymentMethodsReady | Triggered when the checkout has obtained available payment methods.
| (methods: PaymentMethod[]) => void |
| onInitError | Triggered when checkout initialization fails.
| (error: PayKKaError) => void |
| onSubmit | Global event triggered when submitting the form.
| (formValidateError?: Record<string, FormValidateError[]>) => void |
| onSuccess | Global event triggered after successful payment.
| ({returnUrl?: string}) => void |
| onTimeout | Global event triggered when payment times out.
| () => void |
| onExpired | Global event triggered when the session expires or becomes invalid, or when the component is called again after successful payment.
| () => void |
| onError | Global event triggered after payment failure.
| (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')
}
})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:
<button onclick="handleClickPayment()">Pay</button>// 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()
}For fraud detection (FraudDetection) configuration, please refer to Fraud Detection SDK.
After creating the checkout instance, you can create components. For example, let's say we need to import the Card component:
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.
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
})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.
If you want to integrate the checkout in a sandbox environment, follow these steps.
- 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>- When creating the checkout, set
envtosandbox:
const paykkaCheckout = new PayKKaCheckout({
sessionId: 'xxx',
clientKey: 'xxx',
env: 'sandbox'
// ...other options
})