monime-package 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +277 -77
- package/dist/index.d.mts +575 -71
- package/dist/index.d.ts +575 -71
- package/dist/index.js +332 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +325 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +39 -37
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/modules/financialAccount/financialAccount.ts","../src/modules/internalTransfer/internalTransfer.ts","../src/modules/paymentCode/paymentCode.ts","../src/modules/payout/payout.ts","../src/client.ts"],"sourcesContent":["import { MonimeClient, ClientOptions} from \"./client\"\nexport * from \"./modules/types\"\n\nexport function createClient(options:ClientOptions){\n return new MonimeClient(options)\n}\n\nexport { MonimeClient }\nexport type { ClientOptions}","import axios from \"axios\";\nimport { randomBytes } from \"crypto\"\nimport { CreateFinancialAccount, GetFinancialAccount } from \"./financialAccountTypes\";\nimport { MonimeClient} from \"../../client\"\n\nconst URL = 'https://api.monime.io/v1/financial-accounts'\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface createFinancialAccountReturn {\n data?:CreateFinancialAccount,\n error?:Error\n success:boolean\n}\n\nexport async function createFinancialAccount(accountName:string, client:MonimeClient):Promise<createFinancialAccountReturn>{\n if(accountName.trim() === \"\"){\n return { success:false, error:new Error(\"accountName is required\")}\n }\n\n const body = {\n name:accountName,\n currency:'SLE',\n description:\"\",\n metadata:{}\n }\n\n //getting the accessToken and monime space id\n const { accessToken, monimeSpaceId} = client._getConfig()\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monimeSpaceId}`,\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreateFinancialAccount\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n\n return { error:new Error(\"unknown error\"), success:false}\n }\n}\n\n\n\ninterface GetFinancialAccountReturn {\n data?:GetFinancialAccount\n error?:Error\n success:boolean\n}\n\nexport async function getFinancialAccount(financialAccountId:string, client:MonimeClient):Promise<GetFinancialAccountReturn>{\n if(financialAccountId.trim() === \"\"){\n return { success:false, error:new Error(\"financialAccountId is required\")}\n }\n \n const { monimeSpaceId, accessToken} = client._getConfig()\n try{\n const res = await axios.get(`${URL}/${financialAccountId}`, {\n headers:{\n 'Monime-Space-Id': `${monimeSpaceId}`,\n Authorization: `Bearer ${accessToken}`, \n }\n })\n\n const data = res.data as GetFinancialAccount\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n\n return { error:new Error(\"unknown error\"), success:false}\n }\n}\n\n","import axios from \"axios\";\nimport { randomBytes } from \"crypto\";\nimport { CreateInternalTransfer } from \"./internalTransferTypes\";\nimport { MonimeClient } from \"../../client\";\n\nconst URL = 'https://api.monime.io/v1/internal-transfers';\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface Return {\n data?:CreateInternalTransfer,\n error?:Error\n success:boolean\n}\n\nexport async function createInternalTransfer(sourceAccount:string, destinationAccount:string, client:MonimeClient, value:number):Promise<Return>{\n\n if(value <= 0){\n return { success:false, error:new Error(\"value must be larger that zero\")}\n }\n\n if(sourceAccount.trim() === \"\" || destinationAccount.trim() === \"\"){\n return { success:false, error:new Error(\"sourceAccount or destinationAccount is missing\")}\n }\n \n const body = {\n amount :{\n currency:\"SLE\",\n value:value\n },\n sourceFinancialAccount:{\n id:sourceAccount\n },\n destinationFinancialAccount:{\n id:destinationAccount,\n },\n metadata:{}\n }\n\n const { accessToken, monimeSpaceId } = client._getConfig()\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monimeSpaceId}`,\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreateInternalTransfer\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return {error:error, success:false}\n }\n\n return {error:new Error(\"unkknown error\"), success:false}\n }\n}","import axios from \"axios\";\nimport { randomBytes } from \"crypto\"\nimport { CreatePaymentCode, DeletePaymentCode } from \"./paymentCodeTypes\";\nimport { MonimeClient } from \"../../client\";\nimport { error } from \"console\";\n\nconst value = randomBytes(20).toString(\"hex\")\nconst URL = \"https://api.monime.io/v1/payment-codes\"\n\ninterface Return {\n data?:CreatePaymentCode,\n error?:Error\n success:boolean\n}\n\nexport async function createPaymentCode(paymentName:string, amount:number, financialAccountId:string |null, name:string, phoneNumber:string, client:MonimeClient):Promise<Return>{\n let financialAccount = null\n if(financialAccountId !== \"\"){\n financialAccount = financialAccountId\n }\n\n if(paymentName.trim() === \"\" || name.trim() === \"\" || phoneNumber.trim() === \"\"){\n return {success:false, error:new Error(\"paymentName, name, or phoneNumber is missing\")}\n }\n\n if(amount <= 0){\n return {success:false, error:new Error(\"amonut number be greater than zero\")}\n }\n\n const { accessToken, monimeSpaceId} = client._getConfig()\n\n\n const bodyData = {\n name: `${paymentName}`,\n mode: \"recurrent\",\n enable:true,\n amount: {\n currency: \"SLE\",\n value:(amount) * 100\n },\n duration: \"1h30m\",\n customer: {\n name: `${name}`,\n },\n reference:\"\",\n authorizedPhoneNumber:phoneNumber,\n // authorizedProviders: [\"m17\", \"m18\"],\n recurrentPaymentTarget:{\n expectedPaymentCount: 1,\n expectedPaymentTotal:{\n currency:\"SLE\",\n value:(amount) * 100\n }\n },\n financialAccountId:financialAccount,\n metadata: {}\n };\n\n try{\n const res = await axios.post(URL, bodyData, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monimeSpaceId}`,\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreatePaymentCode\n return { data:data, success:true}\n }catch(error){\n if(axios.isAxiosError(error)){\n return {error:error.response?.data, success:false}\n }\n return {error:new Error(\"unknown error\"), success:false}\n }\n}\n\n\nexport async function deletePaymentCode(paymentCodeId:string, client:MonimeClient):Promise<Return>{\n const { accessToken, monimeSpaceId} = client._getConfig()\n\n if(paymentCodeId.trim() === \"\"){\n return { success:false, error:new Error(\"paymentCodeId is required\")}\n }\n\n try{\n const res = await axios.delete(`${URL}/${paymentCodeId}`, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monimeSpaceId}`,\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as DeletePaymentCode\n if(!data.success){\n return { error:new Error(\"delete failed\"), success:false}\n }\n\n return { success:true }\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n return { error:new Error(\"unknown error\"), success:false}\n }\n}","import axios from \"axios\"\nimport { randomBytes } from \"crypto\"\nimport { CreatePayout } from \"./payoutTypes\"\nimport { MonimeClient } from \"../../client\"\n\nconst URL = \"https://api.monime.io/v1/payouts\"\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface Return {\n data?:CreatePayout,\n error?:Error,\n success:boolean\n}\n\nexport async function CreatePayoutMobileMoney(amount:number,phoneNumber:string, sourceAccount:string, client:MonimeClient):Promise<Return> {\n if(phoneNumber.trim() === \"\"){\n return { success:false, error:new Error(\"phoneNumber is required\")}\n }\n \n let provider = \"m17\"\n const africell = [\"077\", \"033\", \"088\", \"080\",\"090\",\"030\"]\n for (let value of africell){\n if(phoneNumber.startsWith(value)){\n provider = 'm18'\n break;\n }\n }\n\n if(amount <= 0) {\n return { error:new Error(\"amount must be greater than 0\"), success:false}\n }\n\n const { accessToken, monimeSpaceId} = client._getConfig()\n\n const body = {\n amount:{\n currency:'SLE',\n value:amount\n },\n source:{\n financialAccountId:sourceAccount\n },\n destination:{\n type:\"momo\",\n provider:provider,\n phoneNumber:phoneNumber\n },\n metadata:{}\n }\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monimeSpaceId}`,\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreatePayout\n\n return {success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { success:false, error:error}\n }\n\n return { success:false, error: new Error(\"unknown error\")}\n } \n}","import { createFinancialAccount,getFinancialAccount } from \"./modules/financialAccount/financialAccount\"\nimport { CreateFinancialAccount, CreateInternalTransfer, CreatePaymentCode, CreatePayout, GetFinancialAccount } from \"./modules/types\"\nimport { createInternalTransfer } from \"./modules/internalTransfer/internalTransfer\"\nimport { createPaymentCode, deletePaymentCode } from \"./modules/paymentCode/paymentCode\"\nimport { CreatePayoutMobileMoney } from \"./modules/payout/payout\"\n\nexport interface ClientOptions {\n monimeSpaceeId:string,\n accessToken:string\n}\n\nexport class MonimeClient {\n private monimeSpaceId:string\n private accessToken:string\n\n /* Methods */\n\n //method for financial accounts\n createFinancialAccount: (name:string ) => Promise<{success:boolean, data?:CreateFinancialAccount, error?:Error}>\n getFinancialAccount: (financialAccountId: string) => Promise<{ success: boolean; data?: GetFinancialAccount; error?: Error }>\n\n //method for internal transfer\n createInternalTransfer: (sourceAccount:string, destinationAccount:string, amount:number) => Promise<{success:boolean, data?:CreateInternalTransfer, error?:Error}>\n\n //method for payment code\n createPaymentCode: (paymentName:string, amount:number, financialAccount:string, username:string, phoneNumber:string) => Promise<{success:boolean, error?:Error, data?:CreatePaymentCode}>\n deletePaymentCode: (paymentCodeId:string) => Promise<{success:boolean, error?:Error, data?:CreatePaymentCode}>\n\n //method for payout\n createPayout: (amount:number,phoneNumber:string, sourceAccount:string) => Promise<{success:boolean, error?:Error, data?:CreatePayout}>\n\n constructor(options:ClientOptions){\n this.accessToken = options.accessToken\n this.monimeSpaceId = options.monimeSpaceeId\n\n this.createFinancialAccount = (name:string) => createFinancialAccount(name, this)\n this.getFinancialAccount = (financialAccountId:string) => getFinancialAccount(financialAccountId, this)\n this.createInternalTransfer = (sourceAccount:string, destinationAccount:string, amount:number) => createInternalTransfer(sourceAccount, destinationAccount, this, amount)\n this.createPaymentCode = (paymentName:string, amount:number, financialAccount:string, username:string, phoneNumber:string) => createPaymentCode(paymentName, amount, financialAccount, username, phoneNumber,this)\n this.deletePaymentCode = (paymentCodeId:string) => deletePaymentCode(paymentCodeId, this)\n this.createPayout = (amount:number,phoneNumber:string, sourceAccount:string) => CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, this)\n }\n\n /** @internal */\n _getConfig(){\n return {\n monimeSpaceId :this.monimeSpaceId,\n accessToken:this.accessToken\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAmB;AACnB,oBAA4B;AAI5B,IAAM,MAAM;AACZ,IAAM,YAAQ,2BAAY,EAAE,EAAE,SAAS,KAAK;AAQ5C,eAAsB,uBAAuB,aAAoB,QAA0D;AACvH,MAAG,YAAY,KAAK,MAAM,IAAG;AACzB,WAAO,EAAE,SAAQ,OAAO,OAAM,IAAI,MAAM,yBAAyB,EAAC;AAAA,EACtE;AAEA,QAAM,OAAO;AAAA,IACT,MAAK;AAAA,IACL,UAAS;AAAA,IACT,aAAY;AAAA,IACZ,UAAS,CAAC;AAAA,EACd;AAGA,QAAM,EAAE,aAAa,cAAa,IAAI,OAAO,WAAW;AAExD,MAAG;AACC,UAAM,MAAM,MAAM,aAAAA,QAAM,KAAK,KAAK,MAAM;AAAA,MACpC,SAAQ;AAAA,QACJ,mBAAmB,GAAG,KAAK;AAAA,QAC3B,mBAAmB,GAAG,aAAa;AAAA,QACnC,eAAe,UAAU,WAAW;AAAA,QACpC,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAC;AAED,UAAM,OAAO,IAAI;AAEjB,WAAO,EAAE,SAAQ,MAAM,KAAI;AAAA,EAC/B,SAAO,OAAM;AACT,QAAG,aAAAA,QAAM,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AAQ,kBAAkB,UAAU,aAAY,IAAI;AACjN,SAAK,oBAAoB,CAAC,kBAAyB,kBAAkB,eAAe,IAAI;AACxF,SAAK,eAAe,CAAC,QAAc,aAAoB,kBAAyB,wBAAwB,QAAQ,aAAa,eAAe,IAAI;AAAA,EACpJ;AAAA;AAAA,EAGA,aAAY;AACR,WAAO;AAAA,MACH,eAAe,KAAK;AAAA,MACpB,aAAY,KAAK;AAAA,IACrB;AAAA,EACJ;AACJ;;;AL/CO,SAAS,aAAa,SAAsB;AAC/C,SAAO,IAAI,aAAa,OAAO;AACnC;","names":["axios","import_axios","import_crypto","URL","value","axios","import_axios","import_crypto","value","URL","axios","import_axios","import_crypto","URL","value","axios"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/modules/financialAccount/financialAccount.ts","../src/modules/financialAccount/index.ts","../src/modules/financialTransaction/financialTransaction.ts","../src/modules/financialTransaction/index.ts","../src/modules/internalTransfer/internalTransfer.ts","../src/modules/internalTransfer/index.ts","../src/modules/paymentCode/paymentCode.ts","../src/modules/paymentCode/index.ts","../src/modules/payout/payout.ts","../src/modules/payout/index.ts","../src/client.ts"],"sourcesContent":["import { type ClientOptions, MonimeClient } from \"./client\";\n\nexport * from \"./modules/types\";\n\nexport function createClient(options: ClientOptions) {\n\treturn new MonimeClient(options);\n}\n\nexport { MonimeClient };\nexport type { ClientOptions };\n","import { randomBytes } from \"node:crypto\";\nimport axios from \"axios\";\nimport type { MonimeClient } from \"../../client\";\nimport type {\n\tAllFinancialAccount,\n\tCreateFinancialAccount,\n\tGetFinancialAccount,\n} from \"./financialAccountTypes\";\n\nconst URL = \"https://api.monime.io/v1/financial-accounts\";\nconst value = randomBytes(20).toString(\"hex\");\n\ninterface createFinancialAccountReturn {\n\tdata?: CreateFinancialAccount;\n\terror?: Error;\n\tsuccess: boolean;\n}\n\nexport async function createFinancialAccount(\n\taccountName: string,\n\tclient: MonimeClient,\n): Promise<createFinancialAccountReturn> {\n\tif (accountName.trim() === \"\") {\n\t\treturn { success: false, error: new Error(\"accountName is required\") };\n\t}\n\n\tconst body = {\n\t\tname: accountName,\n\t\tcurrency: \"SLE\",\n\t\tdescription: \"\",\n\t\tmetadata: {},\n\t};\n\n\t//getting the accessToken and monime space id\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\n\ttry {\n\t\tconst res = await axios.post(URL, body, {\n\t\t\theaders: {\n\t\t\t\t\"Idempotency-Key\": `${value}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as CreateFinancialAccount;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n\ninterface GetFinancialAccountReturn {\n\tdata?: GetFinancialAccount;\n\terror?: Error;\n\tsuccess: boolean;\n}\n\nexport async function getFinancialAccount(\n\tfinancialAccountId: string,\n\tclient: MonimeClient,\n): Promise<GetFinancialAccountReturn> {\n\tif (financialAccountId.trim() === \"\") {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(\"financialAccountId is required\"),\n\t\t};\n\t}\n\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(`${URL}/${financialAccountId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as GetFinancialAccount;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n\ninterface GetAllFinancialAccount {\n\tsuccess: boolean;\n\terror?: Error;\n\tdata?: AllFinancialAccount;\n}\n\nexport async function getAllFinancialAccount(\n\tclient: MonimeClient,\n): Promise<GetAllFinancialAccount> {\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\n\ttry {\n\t\tconst res = await axios.get(URL, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\t\tconst data = res.data as AllFinancialAccount;\n\n\t\treturn { success: true, data: data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n","import type { MonimeClient } from \"../../client\";\nimport type {\n\tAllFinancialAccount,\n\tCreateFinancialAccount,\n\tGetFinancialAccount,\n} from \"../types\";\nimport {\n\tcreateFinancialAccount,\n\tgetAllFinancialAccount,\n\tgetFinancialAccount,\n} from \"./financialAccount\";\n\nexport function FinancialAccountAPI(client: MonimeClient) {\n\treturn {\n\t\tcreate: (name: string) =>\n\t\t\tcreateFinancialAccount(name, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: CreateFinancialAccount;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\t\tget: (financialAccountId: string) =>\n\t\t\tgetFinancialAccount(financialAccountId, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: GetFinancialAccount;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\t\tgetAll: () =>\n\t\t\tgetAllFinancialAccount(client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: AllFinancialAccount;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\t};\n}\n","import axios from \"axios\";\nimport type { MonimeClient } from \"../../client\";\nimport type {\n\tAllTransaction,\n\tGetTransaction,\n} from \"./financialTransactionTypes\";\n\nconst URL = \"https://api.monime.io/v1/financial-transactions\";\n\ninterface GetAllTransactionReturn {\n\tsuccess: boolean;\n\terror?: Error;\n\tdata?: AllTransaction;\n}\n\nexport async function getAllTransaction(\n\tclient: MonimeClient,\n): Promise<GetAllTransactionReturn> {\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(URL, {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t},\n\t\t});\n\t\tconst data = res.data as AllTransaction;\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n\ninterface GetTransactionReturn {\n\tsuccess: boolean;\n\terror?: Error;\n\tdata?: GetTransaction;\n}\n\nexport async function getTransaction(\n\tclient: MonimeClient,\n\ttransactionId: string,\n): Promise<GetTransactionReturn> {\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\tif (transactionId.trim() === \"\") {\n\t\treturn {\n\t\t\terror: new Error(\"transactionId must not be empty\"),\n\t\t\tsuccess: false,\n\t\t};\n\t}\n\n\ttry {\n\t\tconst res = await axios.get(`${URL}/${transactionId}`, {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t},\n\t\t});\n\t\tconst data = res.data as GetTransaction;\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n","import type { MonimeClient } from \"../../client\";\nimport { getAllTransaction, getTransaction } from \"./financialTransaction\";\nimport type {\n\tAllTransaction,\n\tGetTransaction,\n} from \"./financialTransactionTypes\";\n\nexport function FinancialTransactionAPI(client: MonimeClient) {\n\treturn {\n\t\tget: (transactionId: string) =>\n\t\t\tgetTransaction(client, transactionId) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\terror?: Error;\n\t\t\t\tdata?: GetTransaction;\n\t\t\t}>,\n\n\t\tgetAll: () =>\n\t\t\tgetAllTransaction(client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\terror?: Error;\n\t\t\t\tdata?: AllTransaction;\n\t\t\t}>,\n\t};\n}\n","import { randomBytes } from \"node:crypto\";\nimport axios from \"axios\";\nimport type { MonimeClient } from \"../../client\";\nimport type {\n\tAllInternalTransfers,\n\tCreateInternalTransfer,\n\tInternalTransfer,\n} from \"./internalTransferTypes\";\n\nconst URL = \"https://api.monime.io/v1/internal-transfers\";\nconst value = randomBytes(20).toString(\"hex\");\n\ninterface Return {\n\tdata?: CreateInternalTransfer;\n\terror?: Error;\n\tsuccess: boolean;\n}\n\nexport async function createInternalTransfer(\n\tsourceAccount: string,\n\tdestinationAccount: string,\n\tclient: MonimeClient,\n\tamount: number,\n): Promise<Return> {\n\tif (amount <= 0) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(\"amount must be larger that zero\"),\n\t\t};\n\t}\n\n\tif (sourceAccount.trim() === \"\" || destinationAccount.trim() === \"\") {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(\"sourceAccount or destinationAccount is missing\"),\n\t\t};\n\t}\n\n\tconst body = {\n\t\tamount: {\n\t\t\tcurrency: \"SLE\",\n\t\t\tvalue: amount,\n\t\t},\n\t\tsourceFinancialAccount: {\n\t\t\tid: sourceAccount,\n\t\t},\n\t\tdestinationFinancialAccount: {\n\t\t\tid: destinationAccount,\n\t\t},\n\t\tmetadata: {},\n\t};\n\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\n\ttry {\n\t\tconst res = await axios.post(URL, body, {\n\t\t\theaders: {\n\t\t\t\t\"Idempotency-Key\": `${value}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as CreateInternalTransfer;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\n\t\treturn { error: new Error(\"unkknown error\"), success: false };\n\t}\n}\n\ninterface AllInternalTransfersResult {\n\tsuccess: boolean;\n\terror?: Error;\n\tdata?: AllInternalTransfers;\n}\n\nexport async function getAllInternalTransfers(\n\tclient: MonimeClient,\n): Promise<AllInternalTransfersResult> {\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(URL, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as AllInternalTransfers;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error: error };\n\t\t}\n\n\t\treturn { error: new Error(\"unkknown error\"), success: false };\n\t}\n}\n\ninterface InternalTransferResult {\n\tsuccess: boolean;\n\terror?: Error;\n\tdata?: InternalTransfer;\n}\n\nexport async function getInternalTransfer(\n\tclient: MonimeClient,\n\tinternalTransferId: string,\n): Promise<InternalTransferResult> {\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\n\ttry {\n\t\tconst res = await axios.get(`${URL}/${internalTransferId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as InternalTransfer;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error: error };\n\t\t}\n\n\t\treturn { error: new Error(\"unkknown error\"), success: false };\n\t}\n}\n\ninterface DeleteTransferResult {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\nexport async function deleteInternalTransfer(\n\tclient: MonimeClient,\n\tinternalTransferId: string,\n): Promise<DeleteTransferResult> {\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\n\ttry {\n\t\tawait axios.delete(`${URL}/${internalTransferId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\treturn { success: true };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error };\n\t\t}\n\n\t\treturn { success: false, error: new Error(\"unknown error\") };\n\t}\n}\n","import type { MonimeClient } from \"../../client\";\nimport {\n\tcreateInternalTransfer,\n\tdeleteInternalTransfer,\n\tgetAllInternalTransfers,\n\tgetInternalTransfer,\n} from \"./internalTransfer\";\nimport type {\n\tAllInternalTransfers,\n\tCreateInternalTransfer,\n\tInternalTransfer,\n} from \"./internalTransferTypes\";\n\nexport function InternalTransferAPI(client: MonimeClient) {\n\treturn {\n\t\tcreate: (\n\t\t\tsourceAccount: string,\n\t\t\tdestinationAccount: string,\n\t\t\tamount: number,\n\t\t) =>\n\t\t\tcreateInternalTransfer(\n\t\t\t\tsourceAccount,\n\t\t\t\tdestinationAccount,\n\t\t\t\tclient,\n\t\t\t\tamount,\n\t\t\t) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: CreateInternalTransfer;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tget: (internalTransferId: string) =>\n\t\t\tgetInternalTransfer(client, internalTransferId) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: InternalTransfer;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tgetAll: () =>\n\t\t\tgetAllInternalTransfers(client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\terror?: Error;\n\t\t\t\tdata?: AllInternalTransfers;\n\t\t\t}>,\n\n\t\tdelete: (internalTransferId: string) =>\n\t\t\tdeleteInternalTransfer(client, internalTransferId) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\t};\n}\n","import { randomBytes } from \"node:crypto\";\nimport axios from \"axios\";\nimport type { MonimeClient } from \"../../client\";\nimport type {\n\tCreatePaymentCode,\n\tGetAllPaymentCode,\n\tGetOne,\n} from \"./paymentCodeTypes\";\n\nconst value = randomBytes(20).toString(\"hex\");\nconst URL = \"https://api.monime.io/v1/payment-codes\";\n\ninterface Return {\n\tdata?: CreatePaymentCode;\n\terror?: Error;\n\tsuccess: boolean;\n}\n\nexport async function createPaymentCode(\n\tpaymentName: string,\n\tamount: number,\n\tfinancialAccountId: string | null,\n\tname: string,\n\tphoneNumber: string,\n\tclient: MonimeClient,\n): Promise<Return> {\n\tlet financialAccount = null;\n\tif (financialAccountId !== \"\") {\n\t\tfinancialAccount = financialAccountId;\n\t}\n\n\tif (\n\t\tpaymentName.trim() === \"\" ||\n\t\tname.trim() === \"\" ||\n\t\tphoneNumber.trim() === \"\"\n\t) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(\"paymentName, name, or phoneNumber is missing\"),\n\t\t};\n\t}\n\n\tif (amount <= 0) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(\"amonut number be greater than zero\"),\n\t\t};\n\t}\n\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\n\tconst bodyData = {\n\t\tname: `${paymentName}`,\n\t\tmode: \"recurrent\",\n\t\tenable: true,\n\t\tamount: {\n\t\t\tcurrency: \"SLE\",\n\t\t\tvalue: amount * 100,\n\t\t},\n\t\tduration: \"1h30m\",\n\t\tcustomer: {\n\t\t\tname: `${name}`,\n\t\t},\n\t\treference: \"\",\n\t\tauthorizedPhoneNumber: phoneNumber,\n\t\t// authorizedProviders: [\"m17\", \"m18\"],\n\t\trecurrentPaymentTarget: {\n\t\t\texpectedPaymentCount: 1,\n\t\t\texpectedPaymentTotal: {\n\t\t\t\tcurrency: \"SLE\",\n\t\t\t\tvalue: amount * 100,\n\t\t\t},\n\t\t},\n\t\tfinancialAccountId: financialAccount,\n\t\tmetadata: {},\n\t};\n\n\ttry {\n\t\tconst res = await axios.post(URL, bodyData, {\n\t\t\theaders: {\n\t\t\t\t\"Idempotency-Key\": `${value}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as CreatePaymentCode;\n\t\treturn { data: data, success: true };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error.response?.data, success: false };\n\t\t}\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n\ninterface DeleteReturn {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\nexport async function deletePaymentCode(\n\tpaymentCodeId: string,\n\tclient: MonimeClient,\n): Promise<DeleteReturn> {\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\n\tif (paymentCodeId.trim() === \"\") {\n\t\treturn { success: false, error: new Error(\"paymentCodeId is required\") };\n\t}\n\n\ttry {\n\t\tawait axios.delete(`${URL}/${paymentCodeId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Idempotency-Key\": `${value}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t});\n\n\t\treturn { success: true };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n\ninterface GetAll {\n\tsuccess: boolean;\n\terror?: Error;\n\tdata?: GetAllPaymentCode;\n}\n\nexport async function getAllPaymentCode(client: MonimeClient): Promise<GetAll> {\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(URL, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as GetAllPaymentCode;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n\ninterface GetOneReturn {\n\tsuccess: boolean;\n\tdata?: GetOne;\n\terror?: Error;\n}\n\nexport async function getPaymentCode(\n\tpaymentCodeId: string,\n\tclient: MonimeClient,\n): Promise<GetOneReturn> {\n\tconst { monimeSpaceId, accessToken } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(`${URL}/${paymentCodeId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as GetOne;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { error: error, success: false };\n\t\t}\n\t\treturn { error: new Error(\"unknown error\"), success: false };\n\t}\n}\n","import type { MonimeClient } from \"../../client\";\nimport type { CreatePaymentCode, GetAllPaymentCode, GetOne } from \"../types\";\nimport {\n\tcreatePaymentCode,\n\tdeletePaymentCode,\n\tgetAllPaymentCode,\n\tgetPaymentCode,\n} from \"./paymentCode\";\n\nexport function PaymentCodeAPI(client: MonimeClient) {\n\treturn {\n\t\tcreate: (\n\t\t\tpaymentName: string,\n\t\t\tamount: number,\n\t\t\tfinancialAccount: string,\n\t\t\tusername: string,\n\t\t\tphoneNumber: string,\n\t\t) =>\n\t\t\tcreatePaymentCode(\n\t\t\t\tpaymentName,\n\t\t\t\tamount,\n\t\t\t\tfinancialAccount,\n\t\t\t\tusername,\n\t\t\t\tphoneNumber,\n\t\t\t\tclient,\n\t\t\t) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: CreatePaymentCode;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tdelete: (paymentCodeId: string) =>\n\t\t\tdeletePaymentCode(paymentCodeId, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tgetAll: () =>\n\t\t\tgetAllPaymentCode(client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: GetAllPaymentCode;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tget: (paymentCodeId: string) =>\n\t\t\tgetPaymentCode(paymentCodeId, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: GetOne;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\t};\n}\n","import { randomBytes } from \"node:crypto\";\nimport axios from \"axios\";\nimport type { MonimeClient } from \"../../client\";\nimport type {\n\tCreatePayout,\n\tDestinationOption,\n\tGetAll,\n\tGetOnePayout,\n} from \"./payoutTypes\";\n\nconst URL = \"https://api.monime.io/v1/payouts\";\nconst value = randomBytes(20).toString(\"hex\");\n\ninterface Return {\n\tdata?: CreatePayout;\n\terror?: Error;\n\tsuccess: boolean;\n}\n\nexport async function createPayout(\n\tamount: number,\n\tsourceAccount: string,\n\tdestination: DestinationOption,\n\tclient: MonimeClient,\n): Promise<Return> {\n\tif (sourceAccount.trim() === \"\") {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(\"sourceAccount cannot be empty\"),\n\t\t};\n\t}\n\n\tif (amount <= 0) {\n\t\treturn {\n\t\t\terror: new Error(\"amount must be greater than 0\"),\n\t\t\tsuccess: false,\n\t\t};\n\t}\n\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\n\tconst body = {\n\t\tamount: {\n\t\t\tcurrency: \"SLE\",\n\t\t\tvalue: amount,\n\t\t},\n\t\tsource: {\n\t\t\tfinancialAccountId: sourceAccount,\n\t\t},\n\t\tdestination: destination,\n\t\tmetadata: {},\n\t};\n\n\ttry {\n\t\tconst res = await axios.post(URL, body, {\n\t\t\theaders: {\n\t\t\t\t\"Idempotency-Key\": `${value}`,\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as CreatePayout;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error: error };\n\t\t}\n\n\t\treturn { success: false, error: new Error(\"unknown error\") };\n\t}\n}\n\ninterface AllPayout {\n\tsuccess: boolean;\n\tdata?: GetAll;\n\terror?: Error;\n}\n\nexport async function getAllPayout(client: MonimeClient): Promise<AllPayout> {\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(URL, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as GetAll;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error: error };\n\t\t}\n\n\t\treturn { success: false, error: new Error(\"unknown error\") };\n\t}\n}\n\ninterface OnePayout {\n\tsuccess: boolean;\n\tdata?: GetOnePayout;\n\terror?: Error;\n}\n\nexport async function getPayout(\n\tpayoutId: string,\n\tclient: MonimeClient,\n): Promise<OnePayout> {\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\ttry {\n\t\tconst res = await axios.get(`${URL}/${payoutId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\tconst data = res.data as GetOnePayout;\n\n\t\treturn { success: true, data };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error: error };\n\t\t}\n\n\t\treturn { success: false, error: new Error(\"unknown error\") };\n\t}\n}\n\ninterface Delete {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\nexport async function deletePayout(\n\tpayoutId: string,\n\tclient: MonimeClient,\n): Promise<Delete> {\n\tconst { accessToken, monimeSpaceId } = client._getConfig();\n\ttry {\n\t\tawait axios.delete(`${URL}/${payoutId}`, {\n\t\t\theaders: {\n\t\t\t\t\"Monime-Space-Id\": `${monimeSpaceId}`,\n\t\t\t\tAuthorization: `Bearer ${accessToken}`,\n\t\t\t},\n\t\t});\n\n\t\treturn { success: true };\n\t} catch (error) {\n\t\tif (axios.isAxiosError(error)) {\n\t\t\treturn { success: false, error: error };\n\t\t}\n\n\t\treturn { success: false, error: new Error(\"unknown error\") };\n\t}\n}\n","import type { MonimeClient } from \"../../client\";\nimport type {\n\tCreatePayout,\n\tDestinationOption,\n\tGetAll,\n\tGetOnePayout,\n} from \"../types\";\nimport { createPayout, deletePayout, getAllPayout, getPayout } from \"./payout\";\n\nexport function PayoutAPI(client: MonimeClient) {\n\treturn {\n\t\tcreate: (\n\t\t\tamount: number,\n\t\t\tdestination: DestinationOption,\n\t\t\tsourceAccount: string,\n\t\t) =>\n\t\t\tcreatePayout(amount, sourceAccount, destination, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: CreatePayout;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tget: () =>\n\t\t\tgetAllPayout(client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: GetAll;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tgetOne: (payoutId: string) =>\n\t\t\tgetPayout(payoutId, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\tdata?: GetOnePayout;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\n\t\tdelete: (payoutId: string) =>\n\t\t\tdeletePayout(payoutId, client) as Promise<{\n\t\t\t\tsuccess: boolean;\n\t\t\t\terror?: Error;\n\t\t\t}>,\n\t};\n}\n","import { FinancialAccountAPI } from \"./modules/financialAccount\";\nimport { FinancialTransactionAPI } from \"./modules/financialTransaction\";\nimport { InternalTransferAPI } from \"./modules/internalTransfer\";\nimport { PaymentCodeAPI } from \"./modules/paymentCode\";\nimport { PayoutAPI } from \"./modules/payout\";\n\nexport interface ClientOptions {\n\tmonimeSpaceId: string;\n\taccessToken: string;\n}\n\nexport class MonimeClient {\n\tprivate monimeSpaceId: string;\n\tprivate accessToken: string;\n\n\tpublic financialAccount: ReturnType<typeof FinancialAccountAPI>;\n\tpublic internalTransfer: ReturnType<typeof InternalTransferAPI>;\n\tpublic paymentCode: ReturnType<typeof PaymentCodeAPI>;\n\tpublic payout: ReturnType<typeof PayoutAPI>;\n\tpublic financialTransaction: ReturnType<typeof FinancialTransactionAPI>;\n\n\tconstructor(options: ClientOptions) {\n\t\tthis.accessToken = options.accessToken;\n\t\tthis.monimeSpaceId = options.monimeSpaceId;\n\n\t\tthis.financialAccount = FinancialAccountAPI(this);\n\t\tthis.internalTransfer = InternalTransferAPI(this);\n\t\tthis.paymentCode = PaymentCodeAPI(this);\n\t\tthis.payout = PayoutAPI(this);\n\t\tthis.financialTransaction = FinancialTransactionAPI(this);\n\t}\n\n\t/** @internal */\n\t_getConfig() {\n\t\treturn {\n\t\t\tmonimeSpaceId: this.monimeSpaceId,\n\t\t\taccessToken: this.accessToken,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAA4B;AAC5B,mBAAkB;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ios","URL","axios","import_node_crypto","import_axios","URL","value","axios","import_node_crypto","import_axios","value","URL","axios","import_node_crypto","import_axios","URL","value","axios"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/modules/financialAccount/financialAccount.ts
|
|
2
|
-
import axios from "axios";
|
|
3
2
|
import { randomBytes } from "crypto";
|
|
3
|
+
import axios from "axios";
|
|
4
4
|
var URL = "https://api.monime.io/v1/financial-accounts";
|
|
5
5
|
var value = randomBytes(20).toString("hex");
|
|
6
6
|
async function createFinancialAccount(accountName, client) {
|
|
@@ -34,7 +34,10 @@ async function createFinancialAccount(accountName, client) {
|
|
|
34
34
|
}
|
|
35
35
|
async function getFinancialAccount(financialAccountId, client) {
|
|
36
36
|
if (financialAccountId.trim() === "") {
|
|
37
|
-
return {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
error: new Error("financialAccountId is required")
|
|
40
|
+
};
|
|
38
41
|
}
|
|
39
42
|
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
40
43
|
try {
|
|
@@ -53,23 +56,110 @@ async function getFinancialAccount(financialAccountId, client) {
|
|
|
53
56
|
return { error: new Error("unknown error"), success: false };
|
|
54
57
|
}
|
|
55
58
|
}
|
|
59
|
+
async function getAllFinancialAccount(client) {
|
|
60
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
61
|
+
try {
|
|
62
|
+
const res = await axios.get(URL, {
|
|
63
|
+
headers: {
|
|
64
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
65
|
+
Authorization: `Bearer ${accessToken}`
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const data = res.data;
|
|
69
|
+
return { success: true, data };
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (axios.isAxiosError(error)) {
|
|
72
|
+
return { error, success: false };
|
|
73
|
+
}
|
|
74
|
+
return { error: new Error("unknown error"), success: false };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
56
77
|
|
|
57
|
-
// src/modules/
|
|
78
|
+
// src/modules/financialAccount/index.ts
|
|
79
|
+
function FinancialAccountAPI(client) {
|
|
80
|
+
return {
|
|
81
|
+
create: (name) => createFinancialAccount(name, client),
|
|
82
|
+
get: (financialAccountId) => getFinancialAccount(financialAccountId, client),
|
|
83
|
+
getAll: () => getAllFinancialAccount(client)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/modules/financialTransaction/financialTransaction.ts
|
|
58
88
|
import axios2 from "axios";
|
|
89
|
+
var URL2 = "https://api.monime.io/v1/financial-transactions";
|
|
90
|
+
async function getAllTransaction(client) {
|
|
91
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
92
|
+
try {
|
|
93
|
+
const res = await axios2.get(URL2, {
|
|
94
|
+
headers: {
|
|
95
|
+
Authorization: `Bearer ${accessToken}`,
|
|
96
|
+
"Monime-Space-Id": `${monimeSpaceId}`
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const data = res.data;
|
|
100
|
+
return { success: true, data };
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (axios2.isAxiosError(error)) {
|
|
103
|
+
return { error, success: false };
|
|
104
|
+
}
|
|
105
|
+
return { error: new Error("unknown error"), success: false };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function getTransaction(client, transactionId) {
|
|
109
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
110
|
+
if (transactionId.trim() === "") {
|
|
111
|
+
return {
|
|
112
|
+
error: new Error("transactionId must not be empty"),
|
|
113
|
+
success: false
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const res = await axios2.get(`${URL2}/${transactionId}`, {
|
|
118
|
+
headers: {
|
|
119
|
+
Authorization: `Bearer ${accessToken}`,
|
|
120
|
+
"Monime-Space-Id": `${monimeSpaceId}`
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const data = res.data;
|
|
124
|
+
return { success: true, data };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (axios2.isAxiosError(error)) {
|
|
127
|
+
return { error, success: false };
|
|
128
|
+
}
|
|
129
|
+
return { error: new Error("unknown error"), success: false };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/modules/financialTransaction/index.ts
|
|
134
|
+
function FinancialTransactionAPI(client) {
|
|
135
|
+
return {
|
|
136
|
+
get: (transactionId) => getTransaction(client, transactionId),
|
|
137
|
+
getAll: () => getAllTransaction(client)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/modules/internalTransfer/internalTransfer.ts
|
|
59
142
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
60
|
-
|
|
143
|
+
import axios3 from "axios";
|
|
144
|
+
var URL3 = "https://api.monime.io/v1/internal-transfers";
|
|
61
145
|
var value2 = randomBytes2(20).toString("hex");
|
|
62
|
-
async function createInternalTransfer(sourceAccount, destinationAccount, client,
|
|
63
|
-
if (
|
|
64
|
-
return {
|
|
146
|
+
async function createInternalTransfer(sourceAccount, destinationAccount, client, amount) {
|
|
147
|
+
if (amount <= 0) {
|
|
148
|
+
return {
|
|
149
|
+
success: false,
|
|
150
|
+
error: new Error("amount must be larger that zero")
|
|
151
|
+
};
|
|
65
152
|
}
|
|
66
153
|
if (sourceAccount.trim() === "" || destinationAccount.trim() === "") {
|
|
67
|
-
return {
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
error: new Error("sourceAccount or destinationAccount is missing")
|
|
157
|
+
};
|
|
68
158
|
}
|
|
69
159
|
const body = {
|
|
70
160
|
amount: {
|
|
71
161
|
currency: "SLE",
|
|
72
|
-
value:
|
|
162
|
+
value: amount
|
|
73
163
|
},
|
|
74
164
|
sourceFinancialAccount: {
|
|
75
165
|
id: sourceAccount
|
|
@@ -81,9 +171,9 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
|
|
|
81
171
|
};
|
|
82
172
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
83
173
|
try {
|
|
84
|
-
const res = await
|
|
174
|
+
const res = await axios3.post(URL3, body, {
|
|
85
175
|
headers: {
|
|
86
|
-
"Idempotency-Key": `${
|
|
176
|
+
"Idempotency-Key": `${value2}`,
|
|
87
177
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
88
178
|
Authorization: `Bearer ${accessToken}`,
|
|
89
179
|
"Content-Type": "application/json"
|
|
@@ -92,28 +182,102 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
|
|
|
92
182
|
const data = res.data;
|
|
93
183
|
return { success: true, data };
|
|
94
184
|
} catch (error) {
|
|
95
|
-
if (
|
|
185
|
+
if (axios3.isAxiosError(error)) {
|
|
96
186
|
return { error, success: false };
|
|
97
187
|
}
|
|
98
188
|
return { error: new Error("unkknown error"), success: false };
|
|
99
189
|
}
|
|
100
190
|
}
|
|
191
|
+
async function getAllInternalTransfers(client) {
|
|
192
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
193
|
+
try {
|
|
194
|
+
const res = await axios3.get(URL3, {
|
|
195
|
+
headers: {
|
|
196
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
197
|
+
Authorization: `Bearer ${accessToken}`
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
const data = res.data;
|
|
201
|
+
return { success: true, data };
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (axios3.isAxiosError(error)) {
|
|
204
|
+
return { success: false, error };
|
|
205
|
+
}
|
|
206
|
+
return { error: new Error("unkknown error"), success: false };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async function getInternalTransfer(client, internalTransferId) {
|
|
210
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
211
|
+
try {
|
|
212
|
+
const res = await axios3.get(`${URL3}/${internalTransferId}`, {
|
|
213
|
+
headers: {
|
|
214
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
215
|
+
Authorization: `Bearer ${accessToken}`
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
const data = res.data;
|
|
219
|
+
return { success: true, data };
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (axios3.isAxiosError(error)) {
|
|
222
|
+
return { success: false, error };
|
|
223
|
+
}
|
|
224
|
+
return { error: new Error("unkknown error"), success: false };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function deleteInternalTransfer(client, internalTransferId) {
|
|
228
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
229
|
+
try {
|
|
230
|
+
await axios3.delete(`${URL3}/${internalTransferId}`, {
|
|
231
|
+
headers: {
|
|
232
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
233
|
+
Authorization: `Bearer ${accessToken}`
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return { success: true };
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (axios3.isAxiosError(error)) {
|
|
239
|
+
return { success: false, error };
|
|
240
|
+
}
|
|
241
|
+
return { success: false, error: new Error("unknown error") };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/modules/internalTransfer/index.ts
|
|
246
|
+
function InternalTransferAPI(client) {
|
|
247
|
+
return {
|
|
248
|
+
create: (sourceAccount, destinationAccount, amount) => createInternalTransfer(
|
|
249
|
+
sourceAccount,
|
|
250
|
+
destinationAccount,
|
|
251
|
+
client,
|
|
252
|
+
amount
|
|
253
|
+
),
|
|
254
|
+
get: (internalTransferId) => getInternalTransfer(client, internalTransferId),
|
|
255
|
+
getAll: () => getAllInternalTransfers(client),
|
|
256
|
+
delete: (internalTransferId) => deleteInternalTransfer(client, internalTransferId)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
101
259
|
|
|
102
260
|
// src/modules/paymentCode/paymentCode.ts
|
|
103
|
-
import axios3 from "axios";
|
|
104
261
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
262
|
+
import axios4 from "axios";
|
|
105
263
|
var value3 = randomBytes3(20).toString("hex");
|
|
106
|
-
var
|
|
264
|
+
var URL4 = "https://api.monime.io/v1/payment-codes";
|
|
107
265
|
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
|
|
108
266
|
let financialAccount = null;
|
|
109
267
|
if (financialAccountId !== "") {
|
|
110
268
|
financialAccount = financialAccountId;
|
|
111
269
|
}
|
|
112
270
|
if (paymentName.trim() === "" || name.trim() === "" || phoneNumber.trim() === "") {
|
|
113
|
-
return {
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
error: new Error("paymentName, name, or phoneNumber is missing")
|
|
274
|
+
};
|
|
114
275
|
}
|
|
115
276
|
if (amount <= 0) {
|
|
116
|
-
return {
|
|
277
|
+
return {
|
|
278
|
+
success: false,
|
|
279
|
+
error: new Error("amonut number be greater than zero")
|
|
280
|
+
};
|
|
117
281
|
}
|
|
118
282
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
119
283
|
const bodyData = {
|
|
@@ -142,7 +306,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
|
|
|
142
306
|
metadata: {}
|
|
143
307
|
};
|
|
144
308
|
try {
|
|
145
|
-
const res = await
|
|
309
|
+
const res = await axios4.post(URL4, bodyData, {
|
|
146
310
|
headers: {
|
|
147
311
|
"Idempotency-Key": `${value3}`,
|
|
148
312
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -153,7 +317,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
|
|
|
153
317
|
const data = res.data;
|
|
154
318
|
return { data, success: true };
|
|
155
319
|
} catch (error) {
|
|
156
|
-
if (
|
|
320
|
+
if (axios4.isAxiosError(error)) {
|
|
157
321
|
return { error: error.response?.data, success: false };
|
|
158
322
|
}
|
|
159
323
|
return { error: new Error("unknown error"), success: false };
|
|
@@ -165,7 +329,7 @@ async function deletePaymentCode(paymentCodeId, client) {
|
|
|
165
329
|
return { success: false, error: new Error("paymentCodeId is required") };
|
|
166
330
|
}
|
|
167
331
|
try {
|
|
168
|
-
|
|
332
|
+
await axios4.delete(`${URL4}/${paymentCodeId}`, {
|
|
169
333
|
headers: {
|
|
170
334
|
"Idempotency-Key": `${value3}`,
|
|
171
335
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -173,38 +337,85 @@ async function deletePaymentCode(paymentCodeId, client) {
|
|
|
173
337
|
"Content-Type": "application/json"
|
|
174
338
|
}
|
|
175
339
|
});
|
|
340
|
+
return { success: true };
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (axios4.isAxiosError(error)) {
|
|
343
|
+
return { error, success: false };
|
|
344
|
+
}
|
|
345
|
+
return { error: new Error("unknown error"), success: false };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async function getAllPaymentCode(client) {
|
|
349
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
350
|
+
try {
|
|
351
|
+
const res = await axios4.get(URL4, {
|
|
352
|
+
headers: {
|
|
353
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
354
|
+
Authorization: `Bearer ${accessToken}`
|
|
355
|
+
}
|
|
356
|
+
});
|
|
176
357
|
const data = res.data;
|
|
177
|
-
|
|
178
|
-
|
|
358
|
+
return { success: true, data };
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (axios4.isAxiosError(error)) {
|
|
361
|
+
return { error, success: false };
|
|
179
362
|
}
|
|
180
|
-
return { success:
|
|
363
|
+
return { error: new Error("unknown error"), success: false };
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function getPaymentCode(paymentCodeId, client) {
|
|
367
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
368
|
+
try {
|
|
369
|
+
const res = await axios4.get(`${URL4}/${paymentCodeId}`, {
|
|
370
|
+
headers: {
|
|
371
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
372
|
+
Authorization: `Bearer ${accessToken}`
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
const data = res.data;
|
|
376
|
+
return { success: true, data };
|
|
181
377
|
} catch (error) {
|
|
182
|
-
if (
|
|
378
|
+
if (axios4.isAxiosError(error)) {
|
|
183
379
|
return { error, success: false };
|
|
184
380
|
}
|
|
185
381
|
return { error: new Error("unknown error"), success: false };
|
|
186
382
|
}
|
|
187
383
|
}
|
|
188
384
|
|
|
385
|
+
// src/modules/paymentCode/index.ts
|
|
386
|
+
function PaymentCodeAPI(client) {
|
|
387
|
+
return {
|
|
388
|
+
create: (paymentName, amount, financialAccount, username, phoneNumber) => createPaymentCode(
|
|
389
|
+
paymentName,
|
|
390
|
+
amount,
|
|
391
|
+
financialAccount,
|
|
392
|
+
username,
|
|
393
|
+
phoneNumber,
|
|
394
|
+
client
|
|
395
|
+
),
|
|
396
|
+
delete: (paymentCodeId) => deletePaymentCode(paymentCodeId, client),
|
|
397
|
+
getAll: () => getAllPaymentCode(client),
|
|
398
|
+
get: (paymentCodeId) => getPaymentCode(paymentCodeId, client)
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
189
402
|
// src/modules/payout/payout.ts
|
|
190
|
-
import axios4 from "axios";
|
|
191
403
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
192
|
-
|
|
404
|
+
import axios5 from "axios";
|
|
405
|
+
var URL5 = "https://api.monime.io/v1/payouts";
|
|
193
406
|
var value4 = randomBytes4(20).toString("hex");
|
|
194
|
-
async function
|
|
195
|
-
if (
|
|
196
|
-
return {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
for (let value5 of africell) {
|
|
201
|
-
if (phoneNumber.startsWith(value5)) {
|
|
202
|
-
provider = "m18";
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
407
|
+
async function createPayout(amount, sourceAccount, destination, client) {
|
|
408
|
+
if (sourceAccount.trim() === "") {
|
|
409
|
+
return {
|
|
410
|
+
success: false,
|
|
411
|
+
error: new Error("sourceAccount cannot be empty")
|
|
412
|
+
};
|
|
205
413
|
}
|
|
206
414
|
if (amount <= 0) {
|
|
207
|
-
return {
|
|
415
|
+
return {
|
|
416
|
+
error: new Error("amount must be greater than 0"),
|
|
417
|
+
success: false
|
|
418
|
+
};
|
|
208
419
|
}
|
|
209
420
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
210
421
|
const body = {
|
|
@@ -215,15 +426,11 @@ async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, clien
|
|
|
215
426
|
source: {
|
|
216
427
|
financialAccountId: sourceAccount
|
|
217
428
|
},
|
|
218
|
-
destination
|
|
219
|
-
type: "momo",
|
|
220
|
-
provider,
|
|
221
|
-
phoneNumber
|
|
222
|
-
},
|
|
429
|
+
destination,
|
|
223
430
|
metadata: {}
|
|
224
431
|
};
|
|
225
432
|
try {
|
|
226
|
-
const res = await
|
|
433
|
+
const res = await axios5.post(URL5, body, {
|
|
227
434
|
headers: {
|
|
228
435
|
"Idempotency-Key": `${value4}`,
|
|
229
436
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -234,37 +441,93 @@ async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, clien
|
|
|
234
441
|
const data = res.data;
|
|
235
442
|
return { success: true, data };
|
|
236
443
|
} catch (error) {
|
|
237
|
-
if (
|
|
444
|
+
if (axios5.isAxiosError(error)) {
|
|
445
|
+
return { success: false, error };
|
|
446
|
+
}
|
|
447
|
+
return { success: false, error: new Error("unknown error") };
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
async function getAllPayout(client) {
|
|
451
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
452
|
+
try {
|
|
453
|
+
const res = await axios5.get(URL5, {
|
|
454
|
+
headers: {
|
|
455
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
456
|
+
Authorization: `Bearer ${accessToken}`
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
const data = res.data;
|
|
460
|
+
return { success: true, data };
|
|
461
|
+
} catch (error) {
|
|
462
|
+
if (axios5.isAxiosError(error)) {
|
|
238
463
|
return { success: false, error };
|
|
239
464
|
}
|
|
240
465
|
return { success: false, error: new Error("unknown error") };
|
|
241
466
|
}
|
|
242
467
|
}
|
|
468
|
+
async function getPayout(payoutId, client) {
|
|
469
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
470
|
+
try {
|
|
471
|
+
const res = await axios5.get(`${URL5}/${payoutId}`, {
|
|
472
|
+
headers: {
|
|
473
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
474
|
+
Authorization: `Bearer ${accessToken}`
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
const data = res.data;
|
|
478
|
+
return { success: true, data };
|
|
479
|
+
} catch (error) {
|
|
480
|
+
if (axios5.isAxiosError(error)) {
|
|
481
|
+
return { success: false, error };
|
|
482
|
+
}
|
|
483
|
+
return { success: false, error: new Error("unknown error") };
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
async function deletePayout(payoutId, client) {
|
|
487
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
488
|
+
try {
|
|
489
|
+
await axios5.delete(`${URL5}/${payoutId}`, {
|
|
490
|
+
headers: {
|
|
491
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
492
|
+
Authorization: `Bearer ${accessToken}`
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
return { success: true };
|
|
496
|
+
} catch (error) {
|
|
497
|
+
if (axios5.isAxiosError(error)) {
|
|
498
|
+
return { success: false, error };
|
|
499
|
+
}
|
|
500
|
+
return { success: false, error: new Error("unknown error") };
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/modules/payout/index.ts
|
|
505
|
+
function PayoutAPI(client) {
|
|
506
|
+
return {
|
|
507
|
+
create: (amount, destination, sourceAccount) => createPayout(amount, sourceAccount, destination, client),
|
|
508
|
+
get: () => getAllPayout(client),
|
|
509
|
+
getOne: (payoutId) => getPayout(payoutId, client),
|
|
510
|
+
delete: (payoutId) => deletePayout(payoutId, client)
|
|
511
|
+
};
|
|
512
|
+
}
|
|
243
513
|
|
|
244
514
|
// src/client.ts
|
|
245
515
|
var MonimeClient = class {
|
|
246
516
|
monimeSpaceId;
|
|
247
517
|
accessToken;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
createInternalTransfer;
|
|
254
|
-
//method for payment code
|
|
255
|
-
createPaymentCode;
|
|
256
|
-
deletePaymentCode;
|
|
257
|
-
//method for payout
|
|
258
|
-
createPayout;
|
|
518
|
+
financialAccount;
|
|
519
|
+
internalTransfer;
|
|
520
|
+
paymentCode;
|
|
521
|
+
payout;
|
|
522
|
+
financialTransaction;
|
|
259
523
|
constructor(options) {
|
|
260
524
|
this.accessToken = options.accessToken;
|
|
261
|
-
this.monimeSpaceId = options.
|
|
262
|
-
this.
|
|
263
|
-
this.
|
|
264
|
-
this.
|
|
265
|
-
this.
|
|
266
|
-
this.
|
|
267
|
-
this.createPayout = (amount, phoneNumber, sourceAccount) => CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, this);
|
|
525
|
+
this.monimeSpaceId = options.monimeSpaceId;
|
|
526
|
+
this.financialAccount = FinancialAccountAPI(this);
|
|
527
|
+
this.internalTransfer = InternalTransferAPI(this);
|
|
528
|
+
this.paymentCode = PaymentCodeAPI(this);
|
|
529
|
+
this.payout = PayoutAPI(this);
|
|
530
|
+
this.financialTransaction = FinancialTransactionAPI(this);
|
|
268
531
|
}
|
|
269
532
|
/** @internal */
|
|
270
533
|
_getConfig() {
|