@cafebazaar/payment-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Bazaar Payment SDK

Bazaar Payment SDK is a Javascript Library to Deal with Bazaar Payment Process in Client.


Install

npm i @cafebazaar/payment-sdk
# or
yarn add @cafebazaar/payment-sdk

ESM, CommonJS

script.js

// ESM
import { startPaymentProcess } from '@cafebazaar/payment-sdk';

// CommonJS
const { startPaymentProcess } = require('@cafebazaar/payment-sdk');

IIFE

index.html

<script src="https://unpkg.com/@cafebazaar/payment-sdk@x.x.x"></script>
<script>
  const { startPaymentProcess } = window.cafeBazaarPaymentSdk;
</script>

Usage

Start Payment Process

Start Payment Process. Based on Current Javascript Runtime, It May Shows a Popup to User and Redirect Current Window to 'callbackUrl' When Popup is Closed Or Redirect the Whole Document To Payment Page and Come Back to 'callbackUrl' After The Job is Done.

type CheckoutToken = string | number;

interface CallbackUrl {
  url?: string; // default to current window location
  method?: 'post' | 'get'; // default to 'get'
  data?: {
    [propName: string]: string;
  }; // default to empty object {}
}

function startPaymentProcess(checkoutToken: CheckoutToken, callbackUrl?: CallbackUrl): Promise<void>

Examples

startPaymentProcess(12345678, {
  url: 'https://divar.ir/payment/12345678/callback',
  method: 'post',
  data: {
    felan: 'bahman',
  },
}); // will update current document location to via post request to 'https://divar.ir/payment/callback' with 'felan=bahman' body.
startPaymentProcess(87654321, {
  url: 'https://divar.ir/payment/87654321/callback',
  method: 'get',
  data: {
    felan: 'bahman',
  },
}); // will update current document location to via get request to 'https://divar.ir/payment/callback?felan=bahman'.

Readme

Keywords

none

Package Sidebar

Install

npm i @cafebazaar/payment-sdk

Weekly Downloads

43

Version

2.1.0

License

ISC

Unpacked Size

18.3 kB

Total Files

7

Last publish

Collaborators

  • _mahdude
  • amir_mousavi
  • nainemom