diff --git a/examples/acquiring.ts b/examples/acquiring.ts index a1f46ff..b152ba5 100644 --- a/examples/acquiring.ts +++ b/examples/acquiring.ts @@ -1,6 +1,10 @@ import { createClientMonoAcquiring } from '../lib/index.js'; console.log('You can provide X_TOKEN and WEBHOOK_URL as environment variables'); +console.log( + 'For storing webhook you can use: https://webhook-test.com/ or similar service' +); +console.log('Test token you can find here: https://api.monobank.ua/'); const client = createClientMonoAcquiring({ headers: { @@ -10,17 +14,51 @@ const client = createClientMonoAcquiring({ const webHookUrl = process.env.WEBHOOK_URL; -{ +const logResult = (result: any) => + console.log({ + url: result?.response?.url, + status: result?.response?.status, + data: result?.data, + statusText: result?.response?.statusText, + }); + +const createInvoice = async () => { console.log('Create invoice'); - const { data, response } = await client.POST('/api/merchant/invoice/create', { + const result = await client.POST('/api/merchant/invoice/create', { + body: { + amount: 100, + ccy: 840, + webHookUrl, + saveCardData: { + saveCard: true, + walletId: '6dd576d5-4798-4984-9bac-aae3d866a151', + merchantPaymInfo: { + // Can be custom id stored in your database + reference: 'example_of_custom_id', + }, + }, + }, + }); + logResult(result); +}; + +const chargeByToken = async () => { + console.log('Charge by token'); + const result = await client.POST('/api/merchant/wallet/payment', { body: { amount: 1000, ccy: 840, webHookUrl, + cardToken: '240508D4FhxLTV68i5T6', + initiationKind: 'merchant', merchantPaymInfo: { - reference: 'your_custom_id_stored_in_DB', + // Can be custom id stored in your database + reference: 'example_of_custom_id', }, }, }); - console.log(response.url, response.status, data, response.statusText); -} + logResult(result); +}; + +await createInvoice(); +await chargeByToken(); diff --git a/examples/personal.ts b/examples/personal.ts index 8d27157..78f1e73 100644 --- a/examples/personal.ts +++ b/examples/personal.ts @@ -2,5 +2,18 @@ import { createClientMonoPersonal } from '../lib'; const client = createClientMonoPersonal(); -const { data, response } = await client.GET('/bank/currency'); -console.log(data, response.status, response.statusText); +const getCurrencies = async () => { + console.log('Get currencies'); + const { + data, + response: { url, status }, + } = await client.GET('/bank/currency'); + console.log({ + url, + status, + currenciesLength: data?.length, + firstCurrency: data?.[0], + }); +}; + +await getCurrencies();