Bazaar Payment SDK
Bazaar Payment SDK is a Javascript Library to Deal with Bazaar Payment Process in Client.
Install
npm i @cafebazaar/payment-sdk
yarn add @cafebazaar/payment-sdk
ESM, CommonJS
script.js
import { observePaymentStatus, startPaymentProcess } from '@cafebazaar/payment-sdk';
const { observePaymentStatus, startPaymentProcess } = require('@cafebazaar/payment-sdk');
IIFE
index.html
<script src="https://unpkg.com/@cafebazaar/payment-sdk@x.x.x/dist/index.browser.js"></script>
<script>
const { observePaymentStatus, startPaymentProcess } = window.cafeBazaarPaymentSdk;
</script>
Usage
Get Payment Status
Get Status of a Payment.
getPaymentStatus(checkoutToken: CheckoutToken): Promise<PaymentStatus>
Example
getPaymentStatus(12345678).then((paymentStatus) => {
console.log(paymentStatus);
});
Get Payment Url
Get Url of Payment for Manual Actions
function getPaymentUrl(checkoutToken: CheckoutToken, addRedirectQuery: boolean): string
Example
getPaymentUrl(12345678, true);
getPaymentUrl(12345678, false);
Observe Payment Status
Observe Payment Status.
It Will Register a Listener to the Payment Status and Fire the callback Param When It's Changed.
It's Also Fire the callback on Initiation.
observePaymentStatus(checkoutToken: CheckoutToken, callback: PaymentStatusListenerCallback): void
Example
observePaymentStatus(12345678, (paymentStatus) => {
console.log(paymentStatus);
});
UnObserve Payment Status
Un-Observe Payment Status.
It Will UnRegister the Previous Listener of the Payment Status.
unobservePaymentStatus(checkoutToken: CheckoutToken, callback: PaymentStatusListenerCallback): void
Example
const callback = (paymentStatus) => {
console.log(paymentStatus);
};
observePaymentStatus(12345678, callback);
unobservePaymentStatus(12345678, callback);
Start Payment Process
Start Payment Process.
Based on Current Javascript Runtime, It May Shows a Popup to User and Resolves When Popup is Closed Or Redirect the Whole Document To Popup Url and Go Back to Current Url After Jobs Done (So Never Resolves In This Situation).
To Understand What's Happening on the Payment, Register a Listener to Payment via observePaymentStatus Before Calling This.
function startPaymentProcess(checkoutToken: CheckoutToken): Promise<void>
Example
startPaymentProcess(12345678);