Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DemianParkhomenko committed May 10, 2024
1 parent 153f41f commit 932048b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
48 changes: 43 additions & 5 deletions examples/acquiring.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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();
17 changes: 15 additions & 2 deletions examples/personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 932048b

Please sign in to comment.