tonb-merchant-api-client
Version:
Merchant API client is a library to interact with TONB Merchant API.
36 lines (28 loc) • 1.14 kB
text/typescript
import MerchantAPIClient from '../src/client/client';
import { InvoiceManager } from '../src/client/invoice-manager';
import { HttpProvider } from '../src/providers/http/provider';
async function main() {
/* Create HTTP Provider that manager all request/responses
* In example, the full base URL will be: https://merchant2.tonb.io/m/11/
*/
const provider = new HttpProvider({
apiKey: 'EXAMPLE-API-KEY',
url: 'https://merchant-app-api2.tonb.io/',
merchantId: 16,
});
// Create Invoice Manager with HTTP provider inside
const manager = new InvoiceManager(provider);
// Create Merchant API client
const client = new MerchantAPIClient(manager);
// Manage invoices through the Merchant API client
const stats = await client.invoiceManager.stats();
// Check that received data is correct.
// It is needed because library handles all errors
// and returns only the result. In case of failure - empty result.
if (stats.isValid) {
console.log(`Count: ${stats.data?.count}, Sum: ${stats.data?.invoice_sum}`);
} else {
console.log(`Cannot retrieve data, Error: ${stats.error}`);
}
}
main();