Skip to main content

Step 1: Set up tazapay.js

The Card Embed is automatically available as a feature of tazapay.js. Include the tazapay.js script on your checkout page by adding it to the head of your HTML file. Always load tazapay.js directly from js.tazapay.com to remain PCI compliant. Don’t include the script in a bundle or host a copy of it yourself.
Dynamic InjectionBefore injecting the SDK dynamically, please use the following event listener to determine when the script has finished loading.

Step 2: Initialising tazapay.js

HTML
The above code creates an instance of the Tazapay object inside the merchant’s client-side project. This created object now serves as an entry-point to the rest of Tazapay’s JS SDK.

Step 3: Add the card embed to your payment page

The Card Embed needs a place to live on your payment page. Create an empty DOM node (container) with a unique ID in your payment form:
Javascript

Step 4: Create an instance of the card embed and mount it to the already created DOM containers

Javascript
  • The mount function is a part of the library which attaches the UI component to the DOM container with unique ID.
  • This mounting of the card component does require the existence of a client_token which is a unique reference for the transaction.

Configurations

You can pass the following configurations while instantiating the card embed.

Step 5: Listening to events

Tazapay’s card embed will automatically validate and display any errors as the customers type. You can listen to these events

Step 6: Listen for the click event on the Pay button

You can either choose to use your own pay button or use the pay button of the card embed.

Using the card embed’s inbuilt pay button

  • The SDK provides an easy-to-use event called “payButtonClick” that gets triggered whenever the user clicks on the “Pay” button. You can “listen” for this event and execute your custom code in response.
  • To set up your event listener, you’ll need to attach it to the card object.
    Javascript

Using your custom pay button

  1. First off, let’s make sure the inbuilt pay button isn’t visible, since you’re going to use your own custom button. You can do this by adjusting the customPayButton in your configuration in Step 4.
  2. Enable the pay button to accept clicks by listening to the change event. Show the pay button only if complete is true. And trigger Step 7 when the customer clicks that pay button. Additional Guide: Change event

Step 7: Submitting the payment to Tazapay to create a charge

Disable the Pay Button for further clicks and perform the following actions once the customer clicks on the Pay Button

Fetching the client-token (server-side)

  1. Submitting the payment to create a charge will require a client_token which is the unique identifier for a payin or a customer session on your website/application.
  2. This unique token is generated as a response of the payin created by a server call to Tazapay’s payin API.
    JSON
Idempotent Payin Sessions: It is required for you to make sure that the requests to create payin are idempotent. For the value of the idempotency key, you can pass the unique order number on your system. You can refer to this guide for the implementation. This will ensure only unique payin are created corresponding to a unique customer journey on your website/application.

Call the confirmPayment() method

After you have retrieved the client_token, call the confirmPayment() method from the SDK to submit a payment to Tazapay to create a charge. The function takes the following parameters as input
Javascript

Step 8: Display success / failure message to the customer

tazapay.confirmPayment() will return a Promise which resolves with a result object. The object has either:
  • result.payin
    • This is returned when the charge (payment) is successful.
    • This essentially contains the response of GET /v3/payin
  • result.error
    • This is returned when there is an error during payment processing or when a charge fails.
    • The error object returns the following properties:
In case the customer is redirected to an external site to authenticate, the promise will never resolve and the customer will be redirected to the success_url passed by you. Make sure to display appropriate message on your success and failure URLs.

Step 9: Handle post-payment events

Tazapay sends a payin.succeeded event as soon as the funds are received from the customer. Use the webhook_url field in the payin API to receive these events and run actions (for example, sending an order confirmation email to your customers, logging the sale in a database, starting a shipping workflow, etc.) In case of a failed payment attempt, Tazapay sends a payment_attempt.failed event with the reason of failure.