UNPKG

omnipay-savings-sdk

Version:

Omnipay Savings SDK

247 lines (246 loc) 7.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLockedSavingsInterestRateTiers = exports.getInterestBreakdownBySavingsId = exports.withdrawFromSavingsAccount = exports.fundSavingsAccount = exports.getWalletBalance = exports.getSavingsTransactionHistory = exports.getSavingsTransactionsList = exports.getTotalAccountTransactionsByCustomerId = exports.getSavingsDetailsBySavingsId = exports.getSavingsListByCustomerId = exports.updateSavingsAccount = exports.createSavingsAccount = exports.createPlan = exports.getAllPlans = exports.getAllSavingsCategories = void 0; const _1 = require("./"); const env_json_1 = require("../env.json"); const getAllSavingsCategories = async (apiKey) => { try { const response = await (0, _1.GET)({ requestUrl: 'SavingsCategory/GetAllSavingsCategories', apiKey, }); return response; } catch (error) { return error; } }; exports.getAllSavingsCategories = getAllSavingsCategories; const getAllPlans = async (apiKey) => { try { const response = await (0, _1.GET)({ requestUrl: 'Plans/GetAllPlans', apiKey, }); return response; } catch (error) { return error; } }; exports.getAllPlans = getAllPlans; const createPlan = async (apiKey, planName) => { try { const response = await (0, _1.POST)({ requestUrl: 'Plans/AddPlans', apiKey, requestData: { name: planName }, }); return response; } catch (error) { return error; } }; exports.createPlan = createPlan; const createSavingsAccount = async (apiKey, params) => { try { const response = await (0, _1.POST)({ requestUrl: 'Savings/CreateSavingsAccount', apiKey, requestData: params, }); return response; } catch (error) { return error; } }; exports.createSavingsAccount = createSavingsAccount; const updateSavingsAccount = async (apiKey, params) => { try { const response = await (0, _1.PUT)({ requestUrl: 'Savings/UpdateSavingsAccount', apiKey, requestData: params, }); return response; } catch (error) { return error; } }; exports.updateSavingsAccount = updateSavingsAccount; const getSavingsListByCustomerId = async (apiKey) => { try { const response = await (0, _1.GET)({ requestUrl: 'Savings/GetSavingsListByCustomerId', apiKey, }); return response; } catch (error) { return error; } }; exports.getSavingsListByCustomerId = getSavingsListByCustomerId; const getSavingsDetailsBySavingsId = async (apiKey, savingsId) => { try { const response = await (0, _1.GET)({ requestUrl: `Savings/GetSavingsDetailsBySavingsId/${savingsId}`, apiKey, }); return response; } catch (error) { return error; } }; exports.getSavingsDetailsBySavingsId = getSavingsDetailsBySavingsId; const getTotalAccountTransactionsByCustomerId = async (apiKey) => { try { const response = await (0, _1.GET)({ requestUrl: 'SavingsTransaction/GetTotalAccountTransactionsByCustomerId', apiKey, }); return response; } catch (error) { return error; } }; exports.getTotalAccountTransactionsByCustomerId = getTotalAccountTransactionsByCustomerId; const getSavingsTransactionsList = async (apiKey, params) => { try { const queryParams = new URLSearchParams(); Object.entries(params).forEach(([key, value]) => { if (value !== undefined && value !== null) { queryParams.append(key, value.toString()); } }); const response = await (0, _1.GET)({ requestUrl: `SavingsTransaction/TransactionsList?${queryParams.toString()}`, apiKey, }); return response; } catch (error) { return error; } }; exports.getSavingsTransactionsList = getSavingsTransactionsList; const getSavingsTransactionHistory = async (apiKey, params) => { try { const queryParams = new URLSearchParams(); Object.entries(params).forEach(([key, value]) => { if (value !== undefined && value !== null) { queryParams.append(key, value.toString()); } }); const response = await (0, _1.GET)({ requestUrl: `SavingsTransaction/History?${queryParams.toString()}`, apiKey, }); return response; } catch (error) { return { error: true, message: 'An error occurred while getting interest breakdown', data: null, }; } }; exports.getSavingsTransactionHistory = getSavingsTransactionHistory; const getWalletBalance = async (apiKey) => { var _a, _b; try { const requestHeaders = { authorization: `Bearer ${apiKey}`, 'content-type': 'application/json', }; const response = await fetch(`${env_json_1.API_GATEWAY_BASE_URL}/wallet/balance`, { method: 'GET', headers: requestHeaders, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const responseData = await response.json(); if (responseData.error === true) { return { error: (_a = responseData.message) !== null && _a !== void 0 ? _a : 'An error occurred while fetching wallet balance', }; } return responseData; } catch (error) { return { error: (_b = error.message) !== null && _b !== void 0 ? _b : 'Failed to fetch wallet balance', }; } }; exports.getWalletBalance = getWalletBalance; const fundSavingsAccount = async (apiKey, params) => { try { const response = await (0, _1.POST)({ requestUrl: 'SavingsTransaction/FundSavingsAccountManually', requestData: params, apiKey, }); return response; } catch (error) { return error; } }; exports.fundSavingsAccount = fundSavingsAccount; const withdrawFromSavingsAccount = async (apiKey, params) => { try { const response = await (0, _1.POST)({ requestUrl: 'SavingsTransaction/WithdrawFromSavingsAccount', requestData: params, apiKey, }); return response; } catch (error) { return error; } }; exports.withdrawFromSavingsAccount = withdrawFromSavingsAccount; const getInterestBreakdownBySavingsId = async (savingsId, apiKey) => { try { const response = await (0, _1.GET)({ requestUrl: `SavingsTransaction/GetInterestBreakdownBySavingsId/${savingsId}`, apiKey, }); return { error: false, message: 'Interest breakdown retrieved successfully', data: response, }; } catch (error) { console.error('Error getting interest breakdown:', error); return { error: true, message: 'An error occurred while getting interest breakdown', data: null, }; } }; exports.getInterestBreakdownBySavingsId = getInterestBreakdownBySavingsId; const getLockedSavingsInterestRateTiers = async (apiKey) => { try { const response = await (0, _1.GET)({ requestUrl: 'SavingsCategory/GetLockedSavingsInterestRateTiers', apiKey, }); return response; } catch (error) { return error; } }; exports.getLockedSavingsInterestRateTiers = getLockedSavingsInterestRateTiers;