npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@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

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:

  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.