UNPKG

@nkhind/vivawallet-sdk

Version:
86 lines (85 loc) 3.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const axiosInstance_ts_1 = require("../utils/axiosInstance.ts"); const VivaAuth_class_1 = require("../vivabases/VivaAuth.class"); class IsvWebhook extends VivaAuth_class_1.VivaAuthISV { constructor(datas) { super(datas); } /** * Generate a webhook verification key to be used in the response of your webhook endpoints for verification purposes. */ async getWebhookKey() { try { const vivaToken = (await this.getVivaToken()).data; const r = await axiosInstance_ts_1.useAxios.get(this.endpoints.isv.webhook.getKey.url, { headers: { Authorization: 'Bearer ' + vivaToken, }, }); if (!r.data) { if (this.errorLogs) console.error('VivaWallet returned no webhook key data', r.data); return { success: false, message: 'VivaWallet returned no webhook key data', code: 'nodatas', data: null, }; } return { success: true, message: 'Webhook key fetched successfully', data: r.data, }; } catch (e) { if (this.errorLogs) console.error('IsvWebhook.getWebhookKey', e); return { success: false, message: 'Failed to get webhook key', code: 'error', data: null, }; } } /** * Provide your webhook endpoint URL to set up webhooks for your [desired events](https://developer.viva.com/webhooks-for-payments/#webhook-events): * * - **1802** - Transaction POS Ecr Session Created * - **1803** - Transaction POS Ecr Session Failed * - **1796** - Transaction Payment Created * - **1797** - Transaction Reversal Created * - **1798** - Transaction Failed * - **1799** - Transaction Price Calculated * - **8193** - Account Connected * - **8194** - Account Verification Status Changed */ async create(options) { try { const vivaToken = (await this.getVivaToken()).data; await axiosInstance_ts_1.useAxios.post(this.endpoints.isv.webhook.create.url, options, { headers: { Authorization: 'Bearer ' + vivaToken, }, }); return { success: true, message: 'Webhook created successfully', data: null, }; } catch (e) { if (this.errorLogs) console.error('IsvWebhook.create', e); return { success: false, message: 'Failed to create webhook', code: 'error', data: null, }; } } } exports.default = IsvWebhook;