UNPKG

tonb-merchant-api-client

Version:

Merchant API client is a library to interact with TONB Merchant API.

64 lines (63 loc) 2.35 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvoiceManager = void 0; /** InvoiceManager is used to manipulate invoices. */ class InvoiceManager { constructor(provider) { this._provider = provider; } /** Create new Invoice. */ create(data) { return __awaiter(this, void 0, void 0, function* () { return this._provider.createInvoice(data); }); } /** Cancel existing Invoice. */ cancel(invoiceId) { return __awaiter(this, void 0, void 0, function* () { return this._provider.cancelInvoice(invoiceId); }); } /** Get information about Invoice. */ info(invoiceId) { return __awaiter(this, void 0, void 0, function* () { return this._provider.getInvoiceInfo(invoiceId); }); } /** Get Merchant statistics. */ stats() { return __awaiter(this, void 0, void 0, function* () { return this._provider.getInvoiceStats(); }); } /** Process WebHook data. */ processUpdate(update) { const isValid = this._provider.isUpdateValid(update); if (!isValid) { return { data: null, isValid: false, error: new Error('Invalid data received'), }; } return { data: { status: update.data.status, code: update.data.code, amount: BigInt(update.data.amount), order_id: BigInt(update.data.order_id), }, isValid: true, }; } } exports.InvoiceManager = InvoiceManager;