@sonatel-os/juf
Version:
It's an helpful Javascript Utility Framework to ease application development in SONATEL context.
181 lines (180 loc) • 7.04 kB
TypeScript
export default Payment;
/**
* @class Payment
* @classdesc Handles payment operations including initializing payments, generating QR codes, and decoding QR codes.
*/
declare class Payment {
/**
* Factory method to initialize Payment service.
* @method init
* @memberof Service\Payment
* @returns {Payment} An initialized instance of Payment.
*/
static init(): Payment;
/**
* Prepares a payment checkout for the OMPay payment gateway.
* @async
* @method preparePaymentCheckout
* @memberof Service\Payment
* @param {object} paymentDetails - The payment details.
* @param {object} paymentDetails.merchant - Merchant information.
* @param {number} paymentDetails.merchant.code - The merchant code.
* @param {string} paymentDetails.merchant.sitename - The merchant's site name.
* @param {object} paymentDetails.bill - Bill information.
* @param {number} paymentDetails.bill.amount - The amount to be paid.
* @param {string} paymentDetails.bill.reference - The reference for the transaction.
* @param {object} paymentDetails.urls - URLs for payment status.
* @param {string} [paymentDetails.urls.failed] - URL to redirect if payment fails.
* @param {string} [paymentDetails.urls.cancel] - URL to redirect if payment is canceled.
* @param {string} [paymentDetails.urls.success] - URL to redirect upon successful payment.
* @param {string} [paymentDetails.urls.callback] - Callback URL for payment updates.
* @returns {Promise<{link: string, secret: number}>} The checkout link and secret if successful, otherwise an error message.
* @throws {Promise<{ message: string, status: number, detail: string }>} Reject to this in case of Payment link generation failure
*
* @example
* payment.preparePaymentCheckout({
* merchant: {
* code: 123456,
* sitename: 'your-sitename'
* },
* bill: {
* amount: 10,
* reference: '654321'
* },
* urls: {
* failed: 'https://my.site/failed',
* cancel: 'https://my.site/canceled',
* success: 'https://my.site/success'
* }})
* .then(console.log)
* .catch(console.log)
*/
preparePaymentCheckout({ merchant, bill, urls }: {
merchant: {
code: number;
sitename: string;
};
bill: {
amount: number;
reference: string;
};
urls: {
failed?: string | undefined;
cancel?: string | undefined;
success?: string | undefined;
callback?: string | undefined;
};
}): Promise<{
link: string;
secret: number;
}>;
/**
* Creates a QR code for a payment.
* @async
* @method createPaymentQRCode
* @memberof Service\Payment
* @description Generates a QR code for a payment with provided details.
* @param {object} paymentDetails - The details for the QR code.
* @param {object} paymentDetails.merchant - Merchant information.
* @param {number} paymentDetails.merchant.code - The merchant code.
* @param {string} paymentDetails.merchant.sitename - The merchant's site name.
* @param {object} paymentDetails.bill - Bill information.
* @param {number} paymentDetails.bill.amount - The amount to be paid.
* @param {string} paymentDetails.bill.reference - The reference for the transaction.
* @param {object} [paymentDetails.urls] - URLs for payment status.
* @param {string} [paymentDetails.urls.failed] - URL to redirect if payment fails.
* @param {string} [paymentDetails.urls.cancel] - URL to redirect if payment is canceled.
* @param {string} [paymentDetails.urls.success] - URL to redirect upon successful payment.
* @param {string} [paymentDetails.urls.callback] - Callback URL for payment updates.
* @param {object} [paymentDetails.metadata] - Additional metadata for the QR code.
* @param {number} [paymentDetails.validity] - Validity period for the QR code in seconds.
* @returns {Promise<{ deepLink: string, deepLinks: { MAXIT: string, OM: string }, qrCode: string, validity: number, metadata: object, shortLink: string, qrId: string }>} The QR code details if successful.
*
* @throws {Promise<{ message: string, status: number, detail: string }>} Reject to this in case of QR Generation failure
*
* @example
* payment.createPaymentQRCode({
* merchant: {
* code: 123456,
* sitename: 'your-sitename'
* },
* bill: {
* amount: 10,
* reference: '654321'
* },
* urls: {
* failed: 'https://my.site/failed',
* cancel: 'https://my.site/canceled',
* success: 'https://my.site/success'
* },
* metadata: {
* myKey: 'value'
* },
* validity: 300 // 5mns
* })
* .then(console.log)
* .catch(console.log)
*/
createPaymentQRCode({ merchant, bill, urls, metadata, validity }: {
merchant: {
code: number;
sitename: string;
};
bill: {
amount: number;
reference: string;
};
urls?: {
failed?: string | undefined;
cancel?: string | undefined;
success?: string | undefined;
callback?: string | undefined;
} | undefined;
metadata?: object | undefined;
validity?: number | undefined;
}): Promise<{
deepLink: string;
deepLinks: {
MAXIT: string;
OM: string;
};
qrCode: string;
validity: number;
metadata: object;
shortLink: string;
qrId: string;
}>;
/**
* Decodes a QR code.
* @async
* @method decodeQrCode
* @memberof Service\Payment
* @description Retrieves and decodes the content of a QR code by its ID.
* @param {Object} qrDetails - The details required to decode the QR code.
* @param {string} qrDetails.id - The unique identifier of the QR code to be decoded.
* @returns {Promise<{ id: string, content: { merchantCode: string, merchantName: string, amount: number, reference: string, scope: string, type: string, metadata: object } } >} The decoded QR code information or an error message.
* @throws {Promise<{ message: string, status: number, detail: string }>} Reject to this in case of QR Decoding failure
*
* @example
* payment.decodeQrCode({
* id: 'doyaT9sH3rGFph_ZuKIs'
* })
* .then(console.log)
* .catch(console.log)
*/
decodeQrCode({ id }: {
id: string;
}): Promise<{
id: string;
content: {
merchantCode: string;
merchantName: string;
amount: number;
reference: string;
scope: string;
type: string;
metadata: object;
};
}>;
#private;
}