2.0.0 • Published 4 months ago

@bankofgeorgia/bog-payments-web-sdk v2.0.0

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

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:

  1. An order ID, created on your backend using our API (See: https://api.bog.ge/docs/en/payments/introduction).
  2. BogPaymentSession class, which is exported by this package. An instance of this class is associated with one order, though an order ID.
  3. Once the payment is complete, either successfully or with failure. The same order id or the same BogPaymentSession
  4. 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:

  1. 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'
  1. 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.');
});
  1. 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.');
});
  1. 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
}
  1. 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.

2.0.0

4 months ago

0.0.31

4 months ago

0.0.30

6 months ago

0.0.29

6 months ago

0.0.28

6 months ago

0.0.27

6 months ago

0.0.26

7 months ago

0.0.25

7 months ago

0.0.24

7 months ago

0.0.23

7 months ago

0.0.22

9 months ago

0.0.21

9 months ago

0.0.20

9 months ago

0.0.19

9 months ago

0.0.18

9 months ago

0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago