@vulog/aima-billing 1.2.48 → 1.2.49
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/dist/index.cjs +24 -12
- package/dist/index.d.cts +7 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.mjs +24 -13
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/retry-payment.test.ts +41 -0
- package/src/retry-payment.ts +27 -0
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let zod = require("zod");
|
|
3
3
|
//#region src/chargeProduct.ts
|
|
4
|
-
const schema$
|
|
4
|
+
const schema$6 = zod.z.object({
|
|
5
5
|
productId: zod.z.string().trim().min(1).uuid(),
|
|
6
6
|
serviceId: zod.z.string().trim().min(1).uuid().nullable().optional(),
|
|
7
7
|
amount: zod.z.number().min(0),
|
|
@@ -14,7 +14,7 @@ const schema$5 = zod.z.object({
|
|
|
14
14
|
additionalInfo: zod.z.object({ manualPayment: zod.z.boolean().optional() }).optional()
|
|
15
15
|
});
|
|
16
16
|
const chargeProduct = async (client, info) => {
|
|
17
|
-
const result = schema$
|
|
17
|
+
const result = schema$6.safeParse(info);
|
|
18
18
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
19
19
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/product`, info).then(({ data }) => data);
|
|
20
20
|
};
|
|
@@ -27,7 +27,7 @@ const getUserCreditsByEntityId = async (client, id) => {
|
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/addCredits.ts
|
|
30
|
-
const schema$
|
|
30
|
+
const schema$5 = zod.z.object({
|
|
31
31
|
initialAmount: zod.z.number().min(0),
|
|
32
32
|
validityStartDate: zod.z.string().datetime(),
|
|
33
33
|
validityEndDate: zod.z.string().datetime(),
|
|
@@ -48,7 +48,7 @@ const schema$4 = zod.z.object({
|
|
|
48
48
|
])
|
|
49
49
|
});
|
|
50
50
|
const addCredits = async (client, payload) => {
|
|
51
|
-
const result = schema$
|
|
51
|
+
const result = schema$5.safeParse(payload);
|
|
52
52
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
53
53
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/entities/${payload.entityId}/wallets`, result.data).then(({ data }) => data);
|
|
54
54
|
};
|
|
@@ -75,21 +75,21 @@ const getInvoicesByTripId = async (client, tripId) => {
|
|
|
75
75
|
};
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region src/getRefundableAmount.ts
|
|
78
|
-
const schema$
|
|
78
|
+
const schema$4 = zod.z.string().trim().min(1);
|
|
79
79
|
const getRefundableAmount = async (client, invoiceId) => {
|
|
80
|
-
const result = schema$
|
|
80
|
+
const result = schema$4.safeParse(invoiceId);
|
|
81
81
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
82
82
|
return client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/refundableAmount`).then(({ data }) => data);
|
|
83
83
|
};
|
|
84
84
|
//#endregion
|
|
85
85
|
//#region src/refund.ts
|
|
86
|
-
const schema$
|
|
86
|
+
const schema$3 = zod.z.object({
|
|
87
87
|
amount: zod.z.number().min(0).optional(),
|
|
88
88
|
note: zod.z.string().trim().nullable().optional(),
|
|
89
89
|
paymentIntentPspReference: zod.z.string().trim().min(1).optional()
|
|
90
90
|
});
|
|
91
91
|
const refund = async (client, payload) => {
|
|
92
|
-
const result = schema$
|
|
92
|
+
const result = schema$3.safeParse(payload);
|
|
93
93
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
94
94
|
const filteredData = Object.fromEntries(Object.entries(result.data).filter(([_, value]) => value !== void 0 && value !== null));
|
|
95
95
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${payload.invoiceId}/refund`, filteredData).then(({ data }) => data);
|
|
@@ -103,7 +103,7 @@ const getWalletsByEntity = async (client, entityId) => {
|
|
|
103
103
|
};
|
|
104
104
|
//#endregion
|
|
105
105
|
//#region src/updateWallet.ts
|
|
106
|
-
const schema$
|
|
106
|
+
const schema$2 = zod.z.object({
|
|
107
107
|
walletId: zod.z.string().trim().min(1).uuid(),
|
|
108
108
|
actions: zod.z.array(zod.z.object({
|
|
109
109
|
op: zod.z.enum(["replace"]),
|
|
@@ -112,7 +112,7 @@ const schema$1 = zod.z.object({
|
|
|
112
112
|
})).min(1).max(1)
|
|
113
113
|
});
|
|
114
114
|
const updateWallet = async (client, walletId, actions) => {
|
|
115
|
-
const result = schema$
|
|
115
|
+
const result = schema$2.safeParse({
|
|
116
116
|
walletId,
|
|
117
117
|
actions
|
|
118
118
|
});
|
|
@@ -121,7 +121,7 @@ const updateWallet = async (client, walletId, actions) => {
|
|
|
121
121
|
};
|
|
122
122
|
//#endregion
|
|
123
123
|
//#region src/payInvoice.ts
|
|
124
|
-
const schema = zod.z.object({
|
|
124
|
+
const schema$1 = zod.z.object({
|
|
125
125
|
invoiceId: zod.z.string().trim().min(1).uuid(),
|
|
126
126
|
manualPayment: zod.z.object({
|
|
127
127
|
requiresActionReturnUrl: zod.z.string().default(""),
|
|
@@ -130,7 +130,7 @@ const schema = zod.z.object({
|
|
|
130
130
|
})
|
|
131
131
|
});
|
|
132
132
|
const payInvoice = async (client, invoiceId, manualPayment) => {
|
|
133
|
-
const result = schema.safeParse({
|
|
133
|
+
const result = schema$1.safeParse({
|
|
134
134
|
invoiceId,
|
|
135
135
|
manualPayment
|
|
136
136
|
});
|
|
@@ -138,6 +138,17 @@ const payInvoice = async (client, invoiceId, manualPayment) => {
|
|
|
138
138
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/payment`, result.data.manualPayment).then(({ data }) => data);
|
|
139
139
|
};
|
|
140
140
|
//#endregion
|
|
141
|
+
//#region src/retry-payment.ts
|
|
142
|
+
const schema = zod.z.object({ invoiceId: zod.z.string().trim().min(1).uuid() });
|
|
143
|
+
/**
|
|
144
|
+
* Retry an invoices payment stuck in REFUSED and ERROR status, move the status to PENDING or PENDING_MANUAL_PAYMENT
|
|
145
|
+
*/
|
|
146
|
+
const retryPayment = async (client, invoiceId) => {
|
|
147
|
+
const result = schema.safeParse({ invoiceId });
|
|
148
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
149
|
+
return client.post(`/boapi/proxy/user/billing/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/retry-payment`, {}).then(({ data }) => data);
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
|
141
152
|
exports.addCredits = addCredits;
|
|
142
153
|
exports.chargeProduct = chargeProduct;
|
|
143
154
|
exports.getInvoiceById = getInvoiceById;
|
|
@@ -148,4 +159,5 @@ exports.getUserCreditsByEntityId = getUserCreditsByEntityId;
|
|
|
148
159
|
exports.getWalletsByEntity = getWalletsByEntity;
|
|
149
160
|
exports.payInvoice = payInvoice;
|
|
150
161
|
exports.refund = refund;
|
|
162
|
+
exports.retryPayment = retryPayment;
|
|
151
163
|
exports.updateWallet = updateWallet;
|
package/dist/index.d.cts
CHANGED
|
@@ -260,4 +260,10 @@ declare const updateWallet: (client: Client, walletId: string, actions: PatchAct
|
|
|
260
260
|
//#region src/payInvoice.d.ts
|
|
261
261
|
declare const payInvoice: (client: Client, invoiceId: string, manualPayment: ManualPayment) => Promise<Invoice>;
|
|
262
262
|
//#endregion
|
|
263
|
-
|
|
263
|
+
//#region src/retry-payment.d.ts
|
|
264
|
+
/**
|
|
265
|
+
* Retry an invoices payment stuck in REFUSED and ERROR status, move the status to PENDING or PENDING_MANUAL_PAYMENT
|
|
266
|
+
*/
|
|
267
|
+
declare const retryPayment: (client: Client, invoiceId: string) => Promise<Invoice>;
|
|
268
|
+
//#endregion
|
|
269
|
+
export { ChargeProductInfo, Credit, Invoice, InvoicesByTripIdResponse, ManualPayment, Paths, Receipt, RefundableAmount, TripBillingItem, Wallet, addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, retryPayment, updateWallet };
|
package/dist/index.d.mts
CHANGED
|
@@ -260,4 +260,10 @@ declare const updateWallet: (client: Client, walletId: string, actions: PatchAct
|
|
|
260
260
|
//#region src/payInvoice.d.ts
|
|
261
261
|
declare const payInvoice: (client: Client, invoiceId: string, manualPayment: ManualPayment) => Promise<Invoice>;
|
|
262
262
|
//#endregion
|
|
263
|
-
|
|
263
|
+
//#region src/retry-payment.d.ts
|
|
264
|
+
/**
|
|
265
|
+
* Retry an invoices payment stuck in REFUSED and ERROR status, move the status to PENDING or PENDING_MANUAL_PAYMENT
|
|
266
|
+
*/
|
|
267
|
+
declare const retryPayment: (client: Client, invoiceId: string) => Promise<Invoice>;
|
|
268
|
+
//#endregion
|
|
269
|
+
export { ChargeProductInfo, Credit, Invoice, InvoicesByTripIdResponse, ManualPayment, Paths, Receipt, RefundableAmount, TripBillingItem, Wallet, addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, retryPayment, updateWallet };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region src/chargeProduct.ts
|
|
3
|
-
const schema$
|
|
3
|
+
const schema$6 = z.object({
|
|
4
4
|
productId: z.string().trim().min(1).uuid(),
|
|
5
5
|
serviceId: z.string().trim().min(1).uuid().nullable().optional(),
|
|
6
6
|
amount: z.number().min(0),
|
|
@@ -13,7 +13,7 @@ const schema$5 = z.object({
|
|
|
13
13
|
additionalInfo: z.object({ manualPayment: z.boolean().optional() }).optional()
|
|
14
14
|
});
|
|
15
15
|
const chargeProduct = async (client, info) => {
|
|
16
|
-
const result = schema$
|
|
16
|
+
const result = schema$6.safeParse(info);
|
|
17
17
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
18
18
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/product`, info).then(({ data }) => data);
|
|
19
19
|
};
|
|
@@ -26,7 +26,7 @@ const getUserCreditsByEntityId = async (client, id) => {
|
|
|
26
26
|
};
|
|
27
27
|
//#endregion
|
|
28
28
|
//#region src/addCredits.ts
|
|
29
|
-
const schema$
|
|
29
|
+
const schema$5 = z.object({
|
|
30
30
|
initialAmount: z.number().min(0),
|
|
31
31
|
validityStartDate: z.string().datetime(),
|
|
32
32
|
validityEndDate: z.string().datetime(),
|
|
@@ -47,7 +47,7 @@ const schema$4 = z.object({
|
|
|
47
47
|
])
|
|
48
48
|
});
|
|
49
49
|
const addCredits = async (client, payload) => {
|
|
50
|
-
const result = schema$
|
|
50
|
+
const result = schema$5.safeParse(payload);
|
|
51
51
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
52
52
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/entities/${payload.entityId}/wallets`, result.data).then(({ data }) => data);
|
|
53
53
|
};
|
|
@@ -74,21 +74,21 @@ const getInvoicesByTripId = async (client, tripId) => {
|
|
|
74
74
|
};
|
|
75
75
|
//#endregion
|
|
76
76
|
//#region src/getRefundableAmount.ts
|
|
77
|
-
const schema$
|
|
77
|
+
const schema$4 = z.string().trim().min(1);
|
|
78
78
|
const getRefundableAmount = async (client, invoiceId) => {
|
|
79
|
-
const result = schema$
|
|
79
|
+
const result = schema$4.safeParse(invoiceId);
|
|
80
80
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
81
81
|
return client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/refundableAmount`).then(({ data }) => data);
|
|
82
82
|
};
|
|
83
83
|
//#endregion
|
|
84
84
|
//#region src/refund.ts
|
|
85
|
-
const schema$
|
|
85
|
+
const schema$3 = z.object({
|
|
86
86
|
amount: z.number().min(0).optional(),
|
|
87
87
|
note: z.string().trim().nullable().optional(),
|
|
88
88
|
paymentIntentPspReference: z.string().trim().min(1).optional()
|
|
89
89
|
});
|
|
90
90
|
const refund = async (client, payload) => {
|
|
91
|
-
const result = schema$
|
|
91
|
+
const result = schema$3.safeParse(payload);
|
|
92
92
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
93
93
|
const filteredData = Object.fromEntries(Object.entries(result.data).filter(([_, value]) => value !== void 0 && value !== null));
|
|
94
94
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${payload.invoiceId}/refund`, filteredData).then(({ data }) => data);
|
|
@@ -102,7 +102,7 @@ const getWalletsByEntity = async (client, entityId) => {
|
|
|
102
102
|
};
|
|
103
103
|
//#endregion
|
|
104
104
|
//#region src/updateWallet.ts
|
|
105
|
-
const schema$
|
|
105
|
+
const schema$2 = z.object({
|
|
106
106
|
walletId: z.string().trim().min(1).uuid(),
|
|
107
107
|
actions: z.array(z.object({
|
|
108
108
|
op: z.enum(["replace"]),
|
|
@@ -111,7 +111,7 @@ const schema$1 = z.object({
|
|
|
111
111
|
})).min(1).max(1)
|
|
112
112
|
});
|
|
113
113
|
const updateWallet = async (client, walletId, actions) => {
|
|
114
|
-
const result = schema$
|
|
114
|
+
const result = schema$2.safeParse({
|
|
115
115
|
walletId,
|
|
116
116
|
actions
|
|
117
117
|
});
|
|
@@ -120,7 +120,7 @@ const updateWallet = async (client, walletId, actions) => {
|
|
|
120
120
|
};
|
|
121
121
|
//#endregion
|
|
122
122
|
//#region src/payInvoice.ts
|
|
123
|
-
const schema = z.object({
|
|
123
|
+
const schema$1 = z.object({
|
|
124
124
|
invoiceId: z.string().trim().min(1).uuid(),
|
|
125
125
|
manualPayment: z.object({
|
|
126
126
|
requiresActionReturnUrl: z.string().default(""),
|
|
@@ -129,7 +129,7 @@ const schema = z.object({
|
|
|
129
129
|
})
|
|
130
130
|
});
|
|
131
131
|
const payInvoice = async (client, invoiceId, manualPayment) => {
|
|
132
|
-
const result = schema.safeParse({
|
|
132
|
+
const result = schema$1.safeParse({
|
|
133
133
|
invoiceId,
|
|
134
134
|
manualPayment
|
|
135
135
|
});
|
|
@@ -137,4 +137,15 @@ const payInvoice = async (client, invoiceId, manualPayment) => {
|
|
|
137
137
|
return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/payment`, result.data.manualPayment).then(({ data }) => data);
|
|
138
138
|
};
|
|
139
139
|
//#endregion
|
|
140
|
-
|
|
140
|
+
//#region src/retry-payment.ts
|
|
141
|
+
const schema = z.object({ invoiceId: z.string().trim().min(1).uuid() });
|
|
142
|
+
/**
|
|
143
|
+
* Retry an invoices payment stuck in REFUSED and ERROR status, move the status to PENDING or PENDING_MANUAL_PAYMENT
|
|
144
|
+
*/
|
|
145
|
+
const retryPayment = async (client, invoiceId) => {
|
|
146
|
+
const result = schema.safeParse({ invoiceId });
|
|
147
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
148
|
+
return client.post(`/boapi/proxy/user/billing/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/retry-payment`, {}).then(({ data }) => data);
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, retryPayment, updateWallet };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-billing",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.49",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"author": "Vulog",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vulog/aima-client": "1.2.
|
|
36
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.49",
|
|
36
|
+
"@vulog/aima-core": "1.2.49"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^4.3.6"
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
|
|
4
|
+
import { retryPayment } from './retry-payment';
|
|
5
|
+
import { Invoice } from './types';
|
|
6
|
+
|
|
7
|
+
describe('retryPayment', () => {
|
|
8
|
+
const postMock = vi.fn();
|
|
9
|
+
const client = {
|
|
10
|
+
post: postMock,
|
|
11
|
+
clientOptions: {
|
|
12
|
+
fleetId: 'FLEET_ID',
|
|
13
|
+
},
|
|
14
|
+
} as unknown as Client;
|
|
15
|
+
|
|
16
|
+
const invoiceId = '550e8400-e29b-41d4-a716-446655440000';
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('should return invalid args', async () => {
|
|
23
|
+
await expect(retryPayment(client, 'invalid-invoice-id')).rejects.toThrow('Invalid args');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should retry payment successfully', async () => {
|
|
27
|
+
const invoice = { id: invoiceId, invoicesStatus: 'PENDING' } as Invoice;
|
|
28
|
+
|
|
29
|
+
postMock.mockResolvedValueOnce({
|
|
30
|
+
data: invoice,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const result = await retryPayment(client, invoiceId);
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual(invoice);
|
|
36
|
+
expect(postMock).toHaveBeenCalledWith(
|
|
37
|
+
`/boapi/proxy/user/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/retry-payment`,
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Invoice } from './types';
|
|
5
|
+
|
|
6
|
+
const schema = z.object({
|
|
7
|
+
invoiceId: z.string().trim().min(1).uuid(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Retry an invoices payment stuck in REFUSED and ERROR status, move the status to PENDING or PENDING_MANUAL_PAYMENT
|
|
12
|
+
*/
|
|
13
|
+
export const retryPayment = async (client: Client, invoiceId: string): Promise<Invoice> => {
|
|
14
|
+
const result = schema.safeParse({ invoiceId });
|
|
15
|
+
if (!result.success) {
|
|
16
|
+
throw new TypeError('Invalid args', {
|
|
17
|
+
cause: result.error.issues,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return client
|
|
22
|
+
.post<Invoice>(
|
|
23
|
+
`/boapi/proxy/user/billing/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/retry-payment`,
|
|
24
|
+
{}
|
|
25
|
+
)
|
|
26
|
+
.then(({ data }) => data);
|
|
27
|
+
};
|