@vulog/aima-payment 1.1.88 → 1.1.89

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.d.mts CHANGED
@@ -33,9 +33,32 @@ type PaymentDetail = {
33
33
  paymentMethod: 'SEPA' | 'IDEAL' | 'PAYPAL' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'EXTERNAL';
34
34
  mopStatus: 'MOP_VALID' | 'MOP_MISSING' | 'MOP_EXPIRED' | 'MOP_INVALID' | 'MOP_UPDATING' | 'MOP_UPDATE_FAILED' | 'MOP_UNKNOWN';
35
35
  paymentCurrency: string;
36
- paymentType: 'CARD' | 'BANK' | 'PAYPAL' | 'SEPA' | 'EXTERNAL';
37
36
  cardFunding: 'credit' | 'debit' | 'prepaid' | 'unknown';
38
- };
37
+ } & ({
38
+ paymentType: 'CARD';
39
+ cardSummary?: string;
40
+ cardType?: string;
41
+ expiryDate?: number;
42
+ expiryMonth?: string;
43
+ expiryYear?: string;
44
+ } | {
45
+ paymentType: 'SEPA';
46
+ bankCode: string;
47
+ branchCode: string;
48
+ country: string;
49
+ fingerprint: string;
50
+ last4: string;
51
+ } | {
52
+ paymentType: 'BANK';
53
+ bankName: string;
54
+ bankAccountNumber: string;
55
+ iban: string;
56
+ bic: string;
57
+ } | {
58
+ paymentType: 'PAYPAL';
59
+ } | {
60
+ paymentType: 'EXTERNAL';
61
+ });
39
62
  type SynchronizeResponse = {
40
63
  status: 'SUCCEEDED' | 'REQUIRES_CAPTURE' | 'FAILED';
41
64
  };
package/dist/index.d.ts CHANGED
@@ -33,9 +33,32 @@ type PaymentDetail = {
33
33
  paymentMethod: 'SEPA' | 'IDEAL' | 'PAYPAL' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'EXTERNAL';
34
34
  mopStatus: 'MOP_VALID' | 'MOP_MISSING' | 'MOP_EXPIRED' | 'MOP_INVALID' | 'MOP_UPDATING' | 'MOP_UPDATE_FAILED' | 'MOP_UNKNOWN';
35
35
  paymentCurrency: string;
36
- paymentType: 'CARD' | 'BANK' | 'PAYPAL' | 'SEPA' | 'EXTERNAL';
37
36
  cardFunding: 'credit' | 'debit' | 'prepaid' | 'unknown';
38
- };
37
+ } & ({
38
+ paymentType: 'CARD';
39
+ cardSummary?: string;
40
+ cardType?: string;
41
+ expiryDate?: number;
42
+ expiryMonth?: string;
43
+ expiryYear?: string;
44
+ } | {
45
+ paymentType: 'SEPA';
46
+ bankCode: string;
47
+ branchCode: string;
48
+ country: string;
49
+ fingerprint: string;
50
+ last4: string;
51
+ } | {
52
+ paymentType: 'BANK';
53
+ bankName: string;
54
+ bankAccountNumber: string;
55
+ iban: string;
56
+ bic: string;
57
+ } | {
58
+ paymentType: 'PAYPAL';
59
+ } | {
60
+ paymentType: 'EXTERNAL';
61
+ });
39
62
  type SynchronizeResponse = {
40
63
  status: 'SUCCEEDED' | 'REQUIRES_CAPTURE' | 'FAILED';
41
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-payment",
3
- "version": "1.1.88",
3
+ "version": "1.1.89",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.1.88",
23
- "@vulog/aima-core": "1.1.88"
22
+ "@vulog/aima-client": "1.1.89",
23
+ "@vulog/aima-core": "1.1.89"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "zod": "^3.25.76"
@@ -0,0 +1,253 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { getPaymentMethodDetailsForUser } from './getPaymentMethodDetailsForUser';
4
+ import { randomUUID } from 'crypto';
5
+
6
+ describe('getPaymentMethodDetailsForUser', () => {
7
+ const userId = randomUUID();
8
+ const getMock = vi.fn();
9
+ const client = {
10
+ get: getMock,
11
+ clientOptions: {
12
+ fleetId: 'FLEET_ID',
13
+ },
14
+ } as unknown as Client;
15
+ beforeEach(() => {
16
+ getMock.mockReset();
17
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
18
+ });
19
+
20
+ afterEach(() => {
21
+ vi.useRealTimers();
22
+ });
23
+
24
+ test('call OK visa', async () => {
25
+ const mockData = {
26
+ token: 'pm_1RqA47HGgb8lFOFDpTeFe16C',
27
+ holderName: 'John Doe',
28
+ fleetId: client.clientOptions.fleetId,
29
+ entityId: '2f16423b-2b75-4a6e-a82e-5087f98a4df8',
30
+ pspName: 'STRIPE',
31
+ customerPspReference: 'cus_ScgfSAgJ6rmaNo',
32
+ entityStatus: 'APPROVED',
33
+ profileId: '7ca3b51c-3ada-4fe0-8e36-0030940dfde1',
34
+ profileName: 'default',
35
+ profileType: 'Single',
36
+ paymentMethod: 'CREDIT_CARD',
37
+ mopStatus: 'MOP_VALID',
38
+ cardSummary: '0817',
39
+ cardType: 'visa',
40
+ cardFunding: 'credit',
41
+ expiryDate: 1856563200000,
42
+ expiryMonth: '10',
43
+ expiryYear: '2028',
44
+ paymentType: 'CARD',
45
+ };
46
+ getMock.mockResolvedValueOnce({ data: [
47
+ mockData,
48
+ ]});
49
+
50
+ const result = await getPaymentMethodDetailsForUser(client, userId);
51
+
52
+ expect(getMock).toBeCalled();
53
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
54
+ expect(result).toBeTruthy();
55
+ expect(result?.token).toEqual(mockData.token);
56
+ expect(result?.holderName).toEqual(mockData.holderName);
57
+ expect(result?.fleetId).toEqual(mockData.fleetId);
58
+ expect(result?.entityId).toEqual(mockData.entityId);
59
+ expect(result?.pspName).toEqual(mockData.pspName);
60
+ expect(result?.customerPspReference).toEqual(mockData.customerPspReference);
61
+ expect(result?.entityStatus).toEqual(mockData.entityStatus);
62
+ expect(result?.profileId).toEqual(mockData.profileId);
63
+ expect(result?.profileName).toEqual(mockData.profileName);
64
+ expect(result?.profileType).toEqual(mockData.profileType);
65
+ expect(result?.paymentMethod).toEqual(mockData.paymentMethod);
66
+ expect(result?.mopStatus).toEqual(mockData.mopStatus);
67
+ expect(result?.paymentCurrency).toBeUndefined();
68
+ expect(result?.paymentType).toEqual(mockData.paymentType);
69
+ expect(result?.cardFunding).toEqual(mockData.cardFunding);
70
+ expect(result?.paymentType).toEqual('CARD');
71
+ if (result?.paymentType === 'CARD') {
72
+ expect(result?.cardSummary).toEqual(mockData.cardSummary);
73
+ expect(result?.cardType).toEqual(mockData.cardType);
74
+ expect(result?.expiryDate).toEqual(mockData.expiryDate);
75
+ expect(result?.expiryMonth).toEqual(mockData.expiryMonth);
76
+ expect(result?.expiryYear).toEqual(mockData.expiryYear);
77
+ }
78
+ });
79
+
80
+ test('call OK SEPA', async () => {
81
+ const mockData = {
82
+ token: 'pm_1Kb5WdCOd50lRjiu9tPH3r5i',
83
+ holderName: 'Thomas Durant',
84
+ fleetId: client.clientOptions.fleetId,
85
+ entityId: '2330f5d0-91a3-49fb-8f85-4133384bc02c',
86
+ pspName: 'STRIPE',
87
+ customerPspReference: 'cus_LHcyYpiF7A2he3',
88
+ entityStatus: 'PENDING',
89
+ profileId: 'ec94adb1-98e8-48ec-952a-dddc6cba8464',
90
+ profileName: 'default',
91
+ profileType: 'Single',
92
+ paymentMethod: 'SEPA',
93
+ mopStatus: 'MOP_INVALID',
94
+ bankCode: '20041',
95
+ branchCode: '01005',
96
+ country: 'FR',
97
+ fingerprint: 'SPFArCDNSB9TvZuS',
98
+ last4: '2606',
99
+ paymentType: 'SEPA',
100
+ };
101
+ getMock.mockResolvedValueOnce({ data: [
102
+ mockData,
103
+ ]});
104
+
105
+ const result = await getPaymentMethodDetailsForUser(client, userId);
106
+
107
+ expect(getMock).toBeCalled();
108
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
109
+ expect(result).toBeTruthy();
110
+ expect(result?.token).toEqual(mockData.token);
111
+ expect(result?.holderName).toEqual(mockData.holderName);
112
+ expect(result?.fleetId).toEqual(mockData.fleetId);
113
+ expect(result?.entityId).toEqual(mockData.entityId);
114
+ expect(result?.pspName).toEqual(mockData.pspName);
115
+ expect(result?.customerPspReference).toEqual(mockData.customerPspReference);
116
+ expect(result?.entityStatus).toEqual(mockData.entityStatus);
117
+ expect(result?.profileId).toEqual(mockData.profileId);
118
+ expect(result?.profileName).toEqual(mockData.profileName);
119
+ expect(result?.profileType).toEqual(mockData.profileType);
120
+ expect(result?.paymentMethod).toEqual(mockData.paymentMethod);
121
+ expect(result?.mopStatus).toEqual(mockData.mopStatus);
122
+ expect(result?.paymentCurrency).toBeUndefined();
123
+ expect(result?.paymentType).toEqual(mockData.paymentType);
124
+ expect(result?.cardFunding).toBeUndefined;
125
+ expect(result?.paymentType).toEqual('SEPA');
126
+ if (result?.paymentType === 'SEPA') {
127
+ expect(result?.bankCode).toEqual(mockData.bankCode);
128
+ expect(result?.branchCode).toEqual(mockData.branchCode);
129
+ expect(result?.country).toEqual(mockData.country);
130
+ expect(result?.fingerprint).toEqual(mockData.fingerprint);
131
+ expect(result?.last4).toEqual(mockData.last4);
132
+ }
133
+ });
134
+
135
+ test('call OK BANK', async () => {
136
+ const mockData = {
137
+ token: '8416227869543125',
138
+ holderName: 'Jack Dalton',
139
+ fleetId: client.clientOptions.fleetId,
140
+ entityId: '2330f5d0-91a3-49fb-8f85-4133384bc02d',
141
+ pspName: null,
142
+ customerPspReference: null,
143
+ entityStatus: 'APPROVED',
144
+ profileId: 'ec94adb1-98e8-48ec-952a-dddc6cba8465',
145
+ profileName: 'default',
146
+ profileType: 'Single',
147
+ paymentMethod: 'IDEAL',
148
+ mopStatus: 'MOP_INVALID',
149
+ paymentCurrency: null,
150
+ bankName: 'Test Issuer',
151
+ bankAccountNumber: '951',
152
+ iban: 'NL13TEST0123456789',
153
+ bic: 'TESTNL01',
154
+ paymentType: 'BANK',
155
+ };
156
+ getMock.mockResolvedValueOnce({ data: [
157
+ mockData,
158
+ ]});
159
+
160
+ const result = await getPaymentMethodDetailsForUser(client, userId);
161
+
162
+ expect(getMock).toBeCalled();
163
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
164
+ expect(result).toBeTruthy();
165
+ expect(result?.token).toEqual(mockData.token);
166
+ expect(result?.holderName).toEqual(mockData.holderName);
167
+ expect(result?.fleetId).toEqual(mockData.fleetId);
168
+ expect(result?.entityId).toEqual(mockData.entityId);
169
+ expect(result?.pspName).toEqual(mockData.pspName);
170
+ expect(result?.customerPspReference).toEqual(mockData.customerPspReference);
171
+ expect(result?.entityStatus).toEqual(mockData.entityStatus);
172
+ expect(result?.profileId).toEqual(mockData.profileId);
173
+ expect(result?.profileName).toEqual(mockData.profileName);
174
+ expect(result?.profileType).toEqual(mockData.profileType);
175
+ expect(result?.paymentMethod).toEqual(mockData.paymentMethod);
176
+ expect(result?.mopStatus).toEqual(mockData.mopStatus);
177
+ expect(result?.paymentCurrency).toBeFalsy();
178
+ expect(result?.paymentType).toEqual(mockData.paymentType);
179
+ expect(result?.cardFunding).toBeUndefined;
180
+ expect(result?.paymentType).toEqual('BANK');
181
+ if (result?.paymentType === 'BANK') {
182
+ expect(result?.bankName).toEqual(mockData.bankName);
183
+ expect(result?.bankAccountNumber).toEqual(mockData.bankAccountNumber);
184
+ expect(result?.iban).toEqual(mockData.iban);
185
+ expect(result?.bic).toEqual(mockData.bic);
186
+ }
187
+ });
188
+
189
+ test('call OK missing + business', async () => {
190
+ const mockData = [
191
+ {
192
+ token: null,
193
+ holderName: null,
194
+ fleetId: 'KINTOEU-ESSHARE',
195
+ entityId: 'cc42a4ca-2881-4ea3-af0e-1d8b15599243',
196
+ pspName: null,
197
+ customerPspReference: null,
198
+ entityStatus: 'APPROVED',
199
+ profileId: '2dfd07c3-cb97-4df0-a496-48a1c6c7eed4',
200
+ profileName: 'default',
201
+ profileType: 'Business',
202
+ paymentMethod: 'WIRE_TRANSFER',
203
+ mopStatus: 'MOP_VALID',
204
+ paymentCurrency: null,
205
+ bankName: null,
206
+ bankAccountNumber: null,
207
+ iban: 'FR0000000000000000',
208
+ bic: null,
209
+ paymentType: 'BANK',
210
+ },
211
+ {
212
+ entityStatus: 'APPROVED',
213
+ profileId: 'd392469a-484e-4b86-b9f7-498c2e27e3e0',
214
+ profileName: 'default',
215
+ profileType: 'Single',
216
+ paymentMethod: 'CREDIT_CARD',
217
+ mopStatus: 'MOP_MISSING',
218
+ paymentType: 'CARD',
219
+ }
220
+ ];
221
+ getMock.mockResolvedValueOnce({ data: mockData });
222
+
223
+ const result = await getPaymentMethodDetailsForUser(client, userId);
224
+
225
+ expect(getMock).toBeCalled();
226
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/users/${userId}/paymentMethodDetails`);
227
+ expect(result).toBeTruthy();
228
+ expect(result?.token).toBeUndefined();
229
+ expect(result?.holderName).toBeUndefined();
230
+ expect(result?.fleetId).toBeUndefined();
231
+ expect(result?.entityId).toBeUndefined();
232
+ expect(result?.pspName).toBeUndefined();
233
+ expect(result?.customerPspReference).toBeUndefined();
234
+ expect(result?.entityStatus).toEqual(mockData[1].entityStatus);
235
+ expect(result?.profileId).toEqual(mockData[1].profileId);
236
+ expect(result?.profileName).toEqual(mockData[1].profileName);
237
+ expect(result?.profileType).toEqual(mockData[1].profileType);
238
+ expect(result?.paymentMethod).toEqual(mockData[1].paymentMethod);
239
+ expect(result?.mopStatus).toEqual(mockData[1].mopStatus);
240
+ expect(result?.paymentCurrency).toBeUndefined();
241
+ expect(result?.paymentType).toEqual(mockData[1].paymentType);
242
+ expect(result?.cardFunding).toBeUndefined;
243
+ expect(result?.paymentType).toEqual('CARD');
244
+ expect(result?.mopStatus).toEqual('MOP_MISSING');
245
+ if (result?.paymentType === 'CARD') {
246
+ expect(result?.cardSummary).toBeUndefined();
247
+ expect(result?.cardType).toBeUndefined();
248
+ expect(result?.expiryDate).toBeUndefined();
249
+ expect(result?.expiryMonth).toBeUndefined();
250
+ expect(result?.expiryYear).toBeUndefined();
251
+ }
252
+ });
253
+ });
package/src/types.ts CHANGED
@@ -38,9 +38,40 @@ export type PaymentDetail = {
38
38
  | 'MOP_UPDATE_FAILED'
39
39
  | 'MOP_UNKNOWN';
40
40
  paymentCurrency: string;
41
- paymentType: 'CARD' | 'BANK' | 'PAYPAL' | 'SEPA' | 'EXTERNAL';
42
41
  cardFunding: 'credit' | 'debit' | 'prepaid' | 'unknown';
43
- };
42
+ } & (
43
+ | {
44
+ paymentType: 'CARD'; // CARD is also the type used when there is no MoP ... hence all are optional.
45
+ cardSummary?: string;
46
+ cardType?: string;
47
+ expiryDate?: number;
48
+ expiryMonth?: string;
49
+ expiryYear?: string;
50
+ }
51
+ | {
52
+ paymentType: 'SEPA';
53
+ bankCode: string;
54
+ branchCode: string;
55
+ country: string;
56
+ fingerprint: string;
57
+ last4: string;
58
+ }
59
+ | {
60
+ paymentType: 'BANK';
61
+ bankName: string;
62
+ bankAccountNumber: string;
63
+ iban: string;
64
+ bic: string;
65
+ }
66
+ | {
67
+ paymentType: 'PAYPAL';
68
+ // ??
69
+ }
70
+ | {
71
+ paymentType: 'EXTERNAL';
72
+ // nothing more
73
+ }
74
+ );
44
75
 
45
76
  export type SynchronizeResponse = {
46
77
  status: 'SUCCEEDED' | 'REQUIRES_CAPTURE' | 'FAILED';