@cafebazaar/payment-sdk
v2.1.0
Published
Cafebazaar Payment SDK for Javascript
Downloads
467
Readme
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/[email protected]"></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'.