@bankofgeorgia/bog-payments-web-sdk
v2.0.1-beta.0
Published
We have prepared a JavaScript library to help handle payment inputs and processes on your website.
Downloads
1,805
Keywords
Readme
Integrating BOG Card Payment Form on Your Page
We have prepared a JavaScript library to help handle payment inputs and processes on your website.
Concepts:
- An order ID, created on your backend using our API (See: https://api.bog.ge/docs/en/payments/introduction).
- BogPaymentSession class, which is exported by this package. An instance of this class is associated with one order, though an order ID.
- Once the payment is complete, either successfully or with failure. The same order id or the same BogPaymentSession
- should not be used.
Usage:
const orderId = ''; // create order and get order-id
Creating a BogPaymentSession Instance
To create a new BogPaymentSession instance, follow these steps:
const session = new BogPaymentSession(orderId, RenderOptions)
type RenderOptions = {
/** width of the iframe */
width: string,
/** height of the payment frame */
height: string,
/** default is 'en' (English) */
lang?: 'ka' | 'en',
/** default is 'light' */
theme?: 'light' | 'dark',
style?: {
/** background color of the frame */
backgroundColor?: string,
/** vertical gap between elements (px) **/
verticalGap: number,
/** style of card info and cardholder inputs */
inputs?: {
focusedBorderColor?: string,
focusedLabelColor?: string,
focusedValueColor?: string,
borderRadius?: number,
},
/** styles of the submit button. Applicable if the submitButton.display property is true */
submitButton: {
backgroundColor?: string,
hoverBackgroundColor?: string,
activeBackgroundColor?: string,
borderRadius?: number,
}
},
submitButton?: {
/** if false, the submit button will not be displayed */
display: boolean,
},
}
You can fill the renderOptions parameter, to apply custom styling to the payment frame and form elements. Displaying the submit button is optional, you can alternatively use 'triggerPayment' method to initiate payment submission.
Render the payment form:
const target = document.querySelector('#payment-form-contianer');
session.render(target);
Configuration
The BogPaymentSession class instance has "on" method to observe events occurring within the frame:
payment_complete
Event is triggered when the payment process is completed. having "error" object within the payload indicates unsuccessful payment Callback Function Example:
session.on('payment_complete', (data) => {
if (data && data.error) {
console.error(`Payment error: ${data.error.message}`);
} else {
console.log('Payment completed successfully.');
}
});
type data = {
error?: {
message: ErrorMessage,
}
}
type ErrorMessage =
/** default general error, payment failed after start */
'PAYMENT_ERROR' |
/** loaded order is already rejected */
'ORDER_REJECTED' |
/** failed to load order data */
'ORDER_NOT_FOUND' |
/** failed 3ds authorization */
'3DS_FAILURE'
payment_begin
The payment has been started. Will be redirected to 3ds Authorization or completed shortly. After this event you can not change order ID of the same session instance. Callback Function Example:
session.on('payment_begin', () => {
console.log('Payment process has started.');
});
3ds_redirect
Payment process requires a 3D Secure (3DS) authorization and the frame will be redirected shortly.. Callback Function Example:
session.on('3ds_redirect', () => {
console.log('Redirecting for 3D Secure authentication.');
});
submit_available_changed
User's input card information changes. Payload contains whether the input is valid and can be submitted. Callback Function Example:
session.on('submit_available_changed', (data) => {
if (data.canPay) {
console.log('Payment submission is available.');
} else {
console.log('Payment submission is not available.');
}
});
Event Data:
{
canPay: boolean
}
form_layout_changed
the page state has updated that might require a different height when displayed. Callback Function Example:
session.on('form_layout_changed', (data) => {
// 'initial' | 'resize' | '3ds_page_displayed'
const reason = data.reason;
// height in pixels
const preferredMinHeight = data.preferredMinHeight;
});
Event Data:
type data = {
reason: 'initial' | 'resize' | '3ds_page_displayed',
preferredMinHeight: number
}
methods
session.disconnect();
Call necessary to clear listeners when discarding the session without it being complete (such as navigation within SPA).
session.triggerPayment();
Trigger payment submission. equivalent to clicking on the pay button.