SDK

Integrate AlphaX Payments into your web application with our flexible and customizable SDK.
View as Markdown

Obtain Public Client Key

Visit AlphaX’s dashboard, go to Developers > Public Clients and create a new Public Client.

Once you have created the Public Client, you will be able to see the Public Client Key. This key is essential for integrating the AlphaX Payments SDK into your web application.

Inject the SDK

https://alphax-payment-sdk.b-cdn.net/main/payment-sdk.js

To integrate the AlphaX Payments SDK into your web application, include the following script tag in your HTML:

1<script src="https://alphax-payment-sdk.b-cdn.net/main/payment-sdk.js"></script>

Please don’t download the SDK and host it on your own server, as we will be updating the SDK regularly to add new features and fix bugs. By using the CDN link, you will always have access to the latest version of the SDK without needing to manually update it.

Initialize the SDK

After including the SDK script in your HTML, you can initialize the SDK using the following code:

1await AlphaXPayment.init({
2 clientId: '<your_client_id_here>',
3 environment: 'production', // available: production, demo
4 onInitialized() {
5 // after SDK is initialized, this function will be triggered
6 console.log('SDK initialized');
7 },
8});

Create a Payment Element

To create a payment element, use the following code:

1await AlphaXPayment.createPaymentElement({
2 // Pass your unique orderID here
3 orderId: 'order' + Date.now(),
4 amount: 10.50,
5 currency: 'USD',
6 mountElement: '#payment',
7 firstName: 'John', // not required
8 lastName: 'Snow', // not required
9 onPaymentSucceeded(res) {
10 console.log('Payment succeeded', res);
11 },
12 onPaymentFailed() {
13 console.log('Payment failed');
14 },
15});

Submit Payment

Note: Only AXOS gateway supports the submitPayment method.

1document.getElementById('submit-btn').addEventListener('click', function () {
2 AlphaXPayment.submitPayment();
3});

Once submitted, you will receive a response in the onPaymentSucceeded or onPaymentFailed callback function, depending on the outcome of the payment process.