@stancer/stancer 1.0.2 → 1.1.0
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/CHANGELOG.md +8 -0
- package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -1
- package/dist/api-endpoint/http/fetch-http-client.js +7 -1
- package/dist/api-endpoint/http/fetch-http-client.js.map +1 -1
- package/dist/core/common/handler/metadata-handler.d.ts +18 -0
- package/dist/core/common/handler/metadata-handler.d.ts.map +1 -0
- package/dist/core/common/handler/metadata-handler.js +19 -0
- package/dist/core/common/handler/metadata-handler.js.map +1 -0
- package/dist/event/model.d.ts +20 -0
- package/dist/event/model.d.ts.map +1 -0
- package/dist/event/model.js +30 -0
- package/dist/event/model.js.map +1 -0
- package/dist/payment-intent/api-endpoint.d.ts +16 -1
- package/dist/payment-intent/api-endpoint.d.ts.map +1 -1
- package/dist/payment-intent/api-endpoint.js +2 -1
- package/dist/payment-intent/api-endpoint.js.map +1 -1
- package/dist/payment-intent/model.d.ts +3 -2
- package/dist/payment-intent/model.d.ts.map +1 -1
- package/dist/payment-intent/model.js +6 -0
- package/dist/payment-intent/model.js.map +1 -1
- package/dist/webhook/api-endpoint.d.ts +16 -0
- package/dist/webhook/api-endpoint.d.ts.map +1 -0
- package/dist/webhook/api-endpoint.js +33 -0
- package/dist/webhook/api-endpoint.js.map +1 -0
- package/dist/webhook/model.d.ts +35 -0
- package/dist/webhook/model.d.ts.map +1 -0
- package/dist/webhook/model.js +110 -0
- package/dist/webhook/model.js.map +1 -0
- package/dist/webhook/repository.d.ts +7 -0
- package/dist/webhook/repository.d.ts.map +1 -0
- package/dist/webhook/repository.js +10 -0
- package/dist/webhook/repository.js.map +1 -0
- package/dist/webhook/validator.d.ts +4 -0
- package/dist/webhook/validator.d.ts.map +1 -0
- package/dist/webhook/validator.js +16 -0
- package/dist/webhook/validator.js.map +1 -0
- package/package.json +4 -2
- package/src/api-endpoint/http/fetch-http-client.ts +8 -1
- package/src/core/common/handler/metadata-handler.ts +19 -0
- package/src/event/model.ts +42 -0
- package/src/payment-intent/api-endpoint.ts +2 -1
- package/src/payment-intent/model.ts +8 -3
- package/src/webhook/api-endpoint.ts +36 -0
- package/src/webhook/model.ts +140 -0
- package/src/webhook/repository.ts +14 -0
- package/src/webhook/validator.ts +18 -0
- package/dist/main.d.ts +0 -2
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -2
- package/dist/main.js.map +0 -1
- package/reports/base.css +0 -362
- package/reports/block-navigation.js +0 -75
- package/reports/cobertura-coverage.xml +0 -18
- package/reports/favicon.png +0 -0
- package/reports/index.html +0 -177
- package/reports/junit.xml +0 -25
- package/reports/prettify.css +0 -101
- package/reports/prettify.js +0 -955
- package/reports/sort-arrow-sprite.png +0 -0
- package/reports/sorter.js +0 -205
- package/test/fixtures/endpoint.stub.ts +0 -22
- package/test/fixtures/list-endpoint.stub.ts +0 -33
- package/test/fixtures/list-model.stub.ts +0 -24
- package/test/fixtures/model.stub.ts +0 -12
- package/test/functional/address.test.ts +0 -126
- package/test/functional/card.test.ts +0 -175
- package/test/functional/customer.test.ts +0 -174
- package/test/functional/payment-intent.test.ts +0 -215
- package/test/functional/payment.test.ts +0 -206
- package/test/functional/refund.test.ts +0 -112
- package/test/functional/sepa.test.ts +0 -136
- package/test/integration/stub-integration.test.ts +0 -88
- package/test/stub/stub-endpoint.ts +0 -42
- package/test/stub/stub-model.ts +0 -82
- package/test/stub/stub-repository.ts +0 -11
- package/test/test-helper.ts +0 -133
- package/test/unit/address/api-endpoint.test.ts +0 -134
- package/test/unit/address/fixtures.ts +0 -60
- package/test/unit/address/model.test.ts +0 -75
- package/test/unit/address/repository.test.ts +0 -148
- package/test/unit/address/validator.test.ts +0 -49
- package/test/unit/api-endpoint/http/fetch-http-client.test.ts +0 -44
- package/test/unit/api-endpoint/http/http.test.ts +0 -152
- package/test/unit/card/api-endpoint.test.ts +0 -170
- package/test/unit/card/card-helper.ts +0 -116
- package/test/unit/card/fixtures.ts +0 -87
- package/test/unit/card/model.test.ts +0 -167
- package/test/unit/card/repository.test.ts +0 -146
- package/test/unit/card/validator.test.ts +0 -96
- package/test/unit/core/common/mutation-tracked-object.test.ts +0 -24
- package/test/unit/customer/api-endpoint.test.ts +0 -143
- package/test/unit/customer/fixtures.ts +0 -73
- package/test/unit/customer/model.test.ts +0 -90
- package/test/unit/customer/repository.test.ts +0 -148
- package/test/unit/customer/validator.test.ts +0 -62
- package/test/unit/payment/api-endpoint.test.ts +0 -188
- package/test/unit/payment/fixtures.ts +0 -116
- package/test/unit/payment/model.test.ts +0 -240
- package/test/unit/payment/repository.test.ts +0 -270
- package/test/unit/payment/validator.test.ts +0 -137
- package/test/unit/payment-intent/api-endpoint.test.ts +0 -142
- package/test/unit/payment-intent/fixtures.ts +0 -94
- package/test/unit/payment-intent/model.test.ts +0 -157
- package/test/unit/payment-intent/repository.test.ts +0 -263
- package/test/unit/payment-intent/validator.test.ts +0 -136
- package/test/unit/refund/api-endpoint.test.ts +0 -129
- package/test/unit/refund/fixtures.ts +0 -58
- package/test/unit/refund/model.test.ts +0 -89
- package/test/unit/refund/repository.test.ts +0 -157
- package/test/unit/refund/validator.test.ts +0 -89
- package/test/unit/sepa/api-endpoint.test.ts +0 -170
- package/test/unit/sepa/fixture.ts +0 -62
- package/test/unit/sepa/model.test.ts +0 -86
- package/test/unit/sepa/repository.test.ts +0 -149
- package/test/unit/sepa/sepa-helper.ts +0 -71
- package/test/unit/sepa/validator.test.ts +0 -58
- package/test/unit/stub/stub-endpoint.test.ts +0 -236
- package/test/unit/stub/stub-list-endpoint.test.ts +0 -86
- package/test/unit/stub/stub-model.test.ts +0 -111
- package/test/unit/stub/stub-repository.test.ts +0 -144
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { getExampleNumber } from 'libphonenumber-js';
|
|
2
|
-
import mobileExamples from 'libphonenumber-js/mobile/examples';
|
|
3
|
-
import { Temporal } from 'temporal-polyfill';
|
|
4
|
-
import 'temporal-polyfill/global';
|
|
5
|
-
import { describe, expect, it } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { idAddress } from '#address/model.ts';
|
|
8
|
-
import { Configuration } from '#api/configuration.js';
|
|
9
|
-
import { IdCustomer } from '#customer/model.js';
|
|
10
|
-
import { CustomerRepository } from '#customer/repository.js';
|
|
11
|
-
import { randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
12
|
-
|
|
13
|
-
const config = Configuration;
|
|
14
|
-
|
|
15
|
-
config.setKey({
|
|
16
|
-
privateLiveKey: null,
|
|
17
|
-
privateTestKey: process.env['API_KEY'] ?? null,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
config._host = process.env['API_HOST'] ?? 'api.stancer.com';
|
|
21
|
-
|
|
22
|
-
describe('customer functional', () => {
|
|
23
|
-
describe('customer creation', () => {
|
|
24
|
-
const email = `stancertstest+${randomString(1, 5)}@example.com`;
|
|
25
|
-
const mobile = getExampleNumber('FR', mobileExamples)?.formatInternational().replaceAll(' ', '');
|
|
26
|
-
|
|
27
|
-
it('create an customer with email ', async () => {
|
|
28
|
-
const repository = new CustomerRepository();
|
|
29
|
-
const customer = await repository.create({ email });
|
|
30
|
-
await repository.send(customer);
|
|
31
|
-
expect(customer.id).toBeTruthy();
|
|
32
|
-
expect(customer.id).toContain('cust_');
|
|
33
|
-
expect(customer.email).toBe(email);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('create an customer with mobile ', async () => {
|
|
37
|
-
const repository = new CustomerRepository();
|
|
38
|
-
const customer = await repository.create({ mobile });
|
|
39
|
-
await repository.send(customer);
|
|
40
|
-
expect(customer.id).toBeTruthy();
|
|
41
|
-
expect(customer.id).toContain('cust_');
|
|
42
|
-
expect(customer.mobile).toBe(mobile);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('create an customer with both ', async () => {
|
|
46
|
-
const repository = new CustomerRepository();
|
|
47
|
-
const customer = await repository.create({ email, mobile });
|
|
48
|
-
await repository.send(customer);
|
|
49
|
-
expect(customer.id).toBeTruthy();
|
|
50
|
-
expect(customer.id).toContain('cust_');
|
|
51
|
-
expect(customer.email).toBe(email);
|
|
52
|
-
expect(customer.mobile).toBe(mobile);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('create a complete flat customer', async () => {
|
|
56
|
-
const repository = new CustomerRepository();
|
|
57
|
-
const mobile = getExampleNumber('FR', mobileExamples)?.formatInternational().replaceAll(' ', '');
|
|
58
|
-
const dateBirth = Temporal.PlainDate.from(
|
|
59
|
-
`${randomNumber(1000, 2025)}-${String(randomMonth()).padStart(2, '0')}-${String(randomNumber(1, 28)).padStart(2, '0')}`,
|
|
60
|
-
);
|
|
61
|
-
const externalId = randomString(1, 36);
|
|
62
|
-
const legalId = randomString(1, 16);
|
|
63
|
-
const name = randomString(3, 64);
|
|
64
|
-
const country = randomString(2);
|
|
65
|
-
|
|
66
|
-
const customer = await repository.create({ mobile, country, dateBirth, email, externalId, legalId, name });
|
|
67
|
-
|
|
68
|
-
await repository.send(customer);
|
|
69
|
-
|
|
70
|
-
expect(customer.id).toBeTruthy();
|
|
71
|
-
|
|
72
|
-
expect(customer.mobile).toBe(mobile);
|
|
73
|
-
|
|
74
|
-
expect(customer._data.mobile).toBe(customer.mobile);
|
|
75
|
-
expect(customer._data.dateBirth).toBe(customer.dateBirth);
|
|
76
|
-
expect(customer._data.externalId).toBe(customer.externalId);
|
|
77
|
-
expect(customer._data.legalId).toBe(customer.legalId);
|
|
78
|
-
expect(customer._data.name).toBe(customer.name);
|
|
79
|
-
expect(customer._data.country).toBe(customer.country);
|
|
80
|
-
});
|
|
81
|
-
it('create a complete customer with addresses', async () => {
|
|
82
|
-
const repository = new CustomerRepository();
|
|
83
|
-
const mobile = getExampleNumber('FR', mobileExamples)?.formatInternational().replaceAll(' ', '');
|
|
84
|
-
const dateBirth = Temporal.PlainDate.from(
|
|
85
|
-
`${randomNumber(1000, 2025)}-${String(randomMonth()).padStart(2, '0')}-${String(randomNumber(1, 28)).padStart(2, '0')}`,
|
|
86
|
-
);
|
|
87
|
-
const externalId = randomString(1, 36);
|
|
88
|
-
const legalId = randomString(0, 16);
|
|
89
|
-
const name = randomString(3, 64);
|
|
90
|
-
const country = randomString(2);
|
|
91
|
-
const billingAddress = idAddress('addr_YHvhVplBRGET3V7Ns4B6pzD2');
|
|
92
|
-
const shippingAddress = idAddress('addr_YHvhVplBRGET3V7Ns4B6pzD2');
|
|
93
|
-
|
|
94
|
-
const customer = await repository.create({
|
|
95
|
-
mobile,
|
|
96
|
-
country,
|
|
97
|
-
dateBirth,
|
|
98
|
-
email,
|
|
99
|
-
externalId,
|
|
100
|
-
legalId,
|
|
101
|
-
name,
|
|
102
|
-
billingAddress,
|
|
103
|
-
shippingAddress,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
await repository.send(customer);
|
|
107
|
-
|
|
108
|
-
expect(customer.id).toBeTruthy();
|
|
109
|
-
|
|
110
|
-
expect(customer.mobile).toBe(mobile);
|
|
111
|
-
|
|
112
|
-
expect(customer._data.mobile).toBe(customer.mobile);
|
|
113
|
-
expect(customer._data.dateBirth).toBe(customer.dateBirth);
|
|
114
|
-
expect(customer._data.externalId).toBe(customer.externalId);
|
|
115
|
-
expect(customer._data.legalId).toBe(customer.legalId);
|
|
116
|
-
expect(customer._data.name).toBe(customer.name);
|
|
117
|
-
expect(customer._data.country).toBe(customer.country);
|
|
118
|
-
expect(customer._data.billingAddress).toBe(customer.billingAddress);
|
|
119
|
-
expect(customer._data.shippingAddress).toBe(customer.shippingAddress);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('need required values', async () => {
|
|
123
|
-
const repository = new CustomerRepository();
|
|
124
|
-
const name = randomString(3, 64);
|
|
125
|
-
|
|
126
|
-
const customerWithoutRequiredValue = await repository.create({ name });
|
|
127
|
-
|
|
128
|
-
await expect(async () => await repository.send(customerWithoutRequiredValue)).rejects.toThrow(
|
|
129
|
-
'one of the partially required data ( email or mobile) is required to send CustomerModel',
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('patch', () => {
|
|
135
|
-
it('is available on customer', async () => {
|
|
136
|
-
const repository = new CustomerRepository();
|
|
137
|
-
|
|
138
|
-
const mobile = getExampleNumber('FR', mobileExamples)?.formatInternational().replaceAll(' ', '');
|
|
139
|
-
|
|
140
|
-
const country = randomString(2);
|
|
141
|
-
|
|
142
|
-
const customer = await repository.create({ mobile, country });
|
|
143
|
-
|
|
144
|
-
await repository.send(customer);
|
|
145
|
-
const id = customer.id;
|
|
146
|
-
const legalId = randomString(1, 16);
|
|
147
|
-
customer.setLegalId(legalId);
|
|
148
|
-
|
|
149
|
-
await repository.send(customer);
|
|
150
|
-
expect(id).toBe(customer.id);
|
|
151
|
-
expect(mobile).toBe(customer.mobile);
|
|
152
|
-
expect(country).toBe(customer.country);
|
|
153
|
-
expect(legalId).toBe(customer.legalId);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('get', () => {
|
|
158
|
-
it('get the correct object', async () => {
|
|
159
|
-
const repository = new CustomerRepository();
|
|
160
|
-
const id = 'cust_SsySBRtGUq3pG9zbSOhJSKCa' as IdCustomer;
|
|
161
|
-
const customer = await repository.create(id);
|
|
162
|
-
expect(customer.id).toBe(id);
|
|
163
|
-
expect(customer.mobile).toBe('+33612345678');
|
|
164
|
-
expect(customer.country).toBe('FR');
|
|
165
|
-
expect(customer.dateBirth).toBeInstanceOf(Temporal.PlainDate);
|
|
166
|
-
expect(customer.dateBirth.toString()).toBe('2008-01-01');
|
|
167
|
-
expect(customer.createdAt).toBeInstanceOf(Temporal.Instant);
|
|
168
|
-
expect(customer.createdAt?.toLocaleString()).toContain('8/19/2026, ');
|
|
169
|
-
expect(customer.createdAt?.toLocaleString()).toContain(':09:15 PM');
|
|
170
|
-
expect(customer.createdAt.epochMilliseconds).toBe(1787141355 * 1000);
|
|
171
|
-
expect(customer.deleted).toBe(false);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import 'temporal-polyfill/global';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Configuration } from '#api/configuration.js';
|
|
6
|
-
import { PaymentIntentModel, idPaymentIntent } from '#payment-intent/model.js';
|
|
7
|
-
import { PaymentIntentRepository } from '#payment-intent/repository.js';
|
|
8
|
-
import { CurrencyEnum } from '#payment/enum/currency.js';
|
|
9
|
-
import { PaymentAmount, paymentAmount } from '#payment/model.js';
|
|
10
|
-
import { RefundModel } from '#refund/model.js';
|
|
11
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
12
|
-
|
|
13
|
-
const config = Configuration;
|
|
14
|
-
describe('paymentIntent functional', () => {
|
|
15
|
-
config.setKey({
|
|
16
|
-
privateLiveKey: null,
|
|
17
|
-
privateTestKey: process.env['API_KEY'] ?? null,
|
|
18
|
-
});
|
|
19
|
-
config._host = process.env['API_HOST'] ?? 'api.stancer.com';
|
|
20
|
-
const amount = randomNumber(50, 5000) as PaymentAmount;
|
|
21
|
-
const currency = CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)];
|
|
22
|
-
describe('paymentIntent creation', () => {
|
|
23
|
-
it('create a paymentIntent with minimum information', async () => {
|
|
24
|
-
const repository = new PaymentIntentRepository();
|
|
25
|
-
|
|
26
|
-
const paymentIntent = await repository.create({ amount, currency });
|
|
27
|
-
await repository.send(paymentIntent);
|
|
28
|
-
expect(paymentIntent.id).toBeTruthy();
|
|
29
|
-
expect(paymentIntent.id).toContain('pi_');
|
|
30
|
-
expect(paymentIntent.amount).toBe(amount);
|
|
31
|
-
expect(paymentIntent.currency).toBe(currency);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('create a complete flat paymentIntent', async () => {
|
|
35
|
-
const repository = new PaymentIntentRepository();
|
|
36
|
-
const amount = paymentAmount(randomNumber(50, 4294967295));
|
|
37
|
-
const capture = true; //false doesn't work we need a proper test just for capture
|
|
38
|
-
const currency = CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)];
|
|
39
|
-
const description = randomString(3, 64);
|
|
40
|
-
const methodsAllowed = ['card']; //because we send all the possible currency
|
|
41
|
-
const orderId = randomString(1, 36);
|
|
42
|
-
const returnUrl = randomString(1, 66);
|
|
43
|
-
const uniqueId = randomString(1, 36);
|
|
44
|
-
const paymentIntentData = {
|
|
45
|
-
amount,
|
|
46
|
-
capture,
|
|
47
|
-
currency,
|
|
48
|
-
description,
|
|
49
|
-
methodsAllowed,
|
|
50
|
-
orderId,
|
|
51
|
-
uniqueId,
|
|
52
|
-
returnUrl: `https://${returnUrl}`,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const paymentIntent = await repository.create(paymentIntentData);
|
|
56
|
-
|
|
57
|
-
await repository.send(paymentIntent);
|
|
58
|
-
|
|
59
|
-
expect(paymentIntent.id).toBeTruthy();
|
|
60
|
-
expect(paymentIntent.uniqueId);
|
|
61
|
-
|
|
62
|
-
expect(paymentIntent._data.id).not.toBeUndefined();
|
|
63
|
-
expect(paymentIntent._data.id).not.toBeNull();
|
|
64
|
-
|
|
65
|
-
expect(paymentIntent._data).toMatchObject(paymentIntentData);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('need required amount', async () => {
|
|
69
|
-
const repository = new PaymentIntentRepository();
|
|
70
|
-
|
|
71
|
-
const paymentintentWithoutRequiredValue = await repository.create({ currency });
|
|
72
|
-
|
|
73
|
-
await expect(async () => await repository.send(paymentintentWithoutRequiredValue)).rejects.toThrow(
|
|
74
|
-
'amount is required to send PaymentIntentModel',
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
it('need required currency', async () => {
|
|
78
|
-
const repository = new PaymentIntentRepository();
|
|
79
|
-
|
|
80
|
-
const paymentintentWithoutRequiredValue = await repository.create({ amount });
|
|
81
|
-
|
|
82
|
-
await expect(async () => await repository.send(paymentintentWithoutRequiredValue)).rejects.toThrow(
|
|
83
|
-
'currency is required to send PaymentIntentModel',
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('patch', () => {
|
|
89
|
-
it('is available on paymentIntent', async () => {
|
|
90
|
-
const repository = new PaymentIntentRepository();
|
|
91
|
-
const paymentIntent = await repository.create({ amount, currency });
|
|
92
|
-
|
|
93
|
-
await repository.send(paymentIntent);
|
|
94
|
-
const id = paymentIntent.id;
|
|
95
|
-
expect(id).toBeTruthy();
|
|
96
|
-
expect(paymentIntent.amount).toBe(amount);
|
|
97
|
-
expect(paymentIntent.currency).toBe(currency);
|
|
98
|
-
|
|
99
|
-
const newAmount = randomNumber(51, 5000);
|
|
100
|
-
paymentIntent.setAmount(newAmount);
|
|
101
|
-
await repository.send(paymentIntent);
|
|
102
|
-
expect(id).toBe(paymentIntent.id);
|
|
103
|
-
expect(paymentIntent.amount).toBe(newAmount);
|
|
104
|
-
expect(paymentIntent.currency).toBe(currency);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('delete', () => {
|
|
108
|
-
it('cannot delete payed paymentIntent', async () => {
|
|
109
|
-
const repository = new PaymentIntentRepository();
|
|
110
|
-
const paymentIntent = await repository.create('pi_iZwj3voYRVsJdfA0IYo1wLJx');
|
|
111
|
-
expect(paymentIntent.id).toBeTruthy();
|
|
112
|
-
await expect(async () => await repository.delete(paymentIntent)).rejects.toThrow();
|
|
113
|
-
});
|
|
114
|
-
it('can delete non processed paymentIntent (cancelling it)', async () => {
|
|
115
|
-
const repository = new PaymentIntentRepository();
|
|
116
|
-
const paymentIntent = await repository.create({ amount, currency });
|
|
117
|
-
await repository.send(paymentIntent);
|
|
118
|
-
expect(paymentIntent.id).toBeTruthy();
|
|
119
|
-
expect(paymentIntent.status).toBe('require_payment_method');
|
|
120
|
-
await repository.delete(paymentIntent);
|
|
121
|
-
expect(paymentIntent.status).toBe('canceled');
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
describe('list', async () => {
|
|
125
|
-
it('should return all paymentIntent with same orderId', async () => {
|
|
126
|
-
const orderId = `${Date.now()}-${randomString(8)}`;
|
|
127
|
-
const expectedAmount = paymentAmount(50);
|
|
128
|
-
const expectedCurrency = 'eur';
|
|
129
|
-
const expectedCount = 3;
|
|
130
|
-
const repository = new PaymentIntentRepository();
|
|
131
|
-
const paymentintents = await Promise.all(
|
|
132
|
-
Array.from({ length: expectedCount }, () =>
|
|
133
|
-
repository
|
|
134
|
-
.create()
|
|
135
|
-
.then((paymentIntent) =>
|
|
136
|
-
repository
|
|
137
|
-
.send(paymentIntent.setAmount(expectedAmount).setCurrency(expectedCurrency).setOrderId(orderId))
|
|
138
|
-
.then((paymentIntent) => expect(paymentIntent).toHaveProperty('id')),
|
|
139
|
-
),
|
|
140
|
-
),
|
|
141
|
-
);
|
|
142
|
-
expect(paymentintents).toHaveLength(expectedCount);
|
|
143
|
-
|
|
144
|
-
const items = repository.list({ limit: expectedCount, filters: { order_id: orderId } });
|
|
145
|
-
let length = 0;
|
|
146
|
-
for await (const item of items) {
|
|
147
|
-
expect(item).toBeInstanceOf(PaymentIntentModel);
|
|
148
|
-
expect(item.amount).toEqual(expectedAmount);
|
|
149
|
-
expect(item.currency).toEqual(expectedCurrency);
|
|
150
|
-
expect(item.orderId).toEqual(orderId);
|
|
151
|
-
length++;
|
|
152
|
-
}
|
|
153
|
-
expect(length).toBe(expectedCount);
|
|
154
|
-
});
|
|
155
|
-
it('should return empty list if no paymentIntent match orderId', async () => {
|
|
156
|
-
const repository = new PaymentIntentRepository();
|
|
157
|
-
|
|
158
|
-
const orderId = `no_matching_order_id`;
|
|
159
|
-
const items = await repository.list({ limit: 10, filters: { order_id: orderId } });
|
|
160
|
-
const item = await items.next();
|
|
161
|
-
expect(item.done).toBeTruthy();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
describe('get', () => {
|
|
165
|
-
it('get the correct object', async () => {
|
|
166
|
-
const repository = new PaymentIntentRepository();
|
|
167
|
-
const id = idPaymentIntent('pi_iZwj3voYRVsJdfA0IYo1wLJx');
|
|
168
|
-
const paymentIntent = await repository.create(id);
|
|
169
|
-
expect(paymentIntent._data.id).toBe(id);
|
|
170
|
-
expect(paymentIntent._data.amount).toBe(50);
|
|
171
|
-
expect(paymentIntent._data.billingAddress).toBeUndefined();
|
|
172
|
-
expect(paymentIntent._data.capture).toBe(true);
|
|
173
|
-
expect(paymentIntent._data.card).toBeUndefined();
|
|
174
|
-
expect(paymentIntent._data.createdAt).toStrictEqual(Temporal.Instant.fromEpochMilliseconds(1789138080 * 1000));
|
|
175
|
-
expect(paymentIntent._data.currency).toBe('eur');
|
|
176
|
-
expect(paymentIntent._data.customer).toBeUndefined();
|
|
177
|
-
expect(paymentIntent._data.dateSettlement).toBeUndefined();
|
|
178
|
-
expect(paymentIntent._data.description).toBeUndefined();
|
|
179
|
-
expect(paymentIntent._data.methodsAllowed).toContain('card');
|
|
180
|
-
expect(paymentIntent._data.methodsAllowed).toContain('sepa');
|
|
181
|
-
expect(paymentIntent._data.orderId).toBe('1789138080518-QR1vpifg');
|
|
182
|
-
expect(paymentIntent._data.origin).toBe('api');
|
|
183
|
-
expect(paymentIntent._data.payment).toBeUndefined();
|
|
184
|
-
expect(paymentIntent._data.returnUrl).toBeUndefined();
|
|
185
|
-
expect(paymentIntent._data.sepa).toBeUndefined();
|
|
186
|
-
expect(paymentIntent._data.shippingAddress).toBeUndefined();
|
|
187
|
-
expect(paymentIntent._data.status).toBe('canceled');
|
|
188
|
-
expect(paymentIntent._data.threeds).toBe('required');
|
|
189
|
-
expect(paymentIntent._data.url).toBe('https://payment.dev.iliad78.net/test_pi_iZwj3voYRVsJdfA0IYo1wLJx');
|
|
190
|
-
});
|
|
191
|
-
it('get a 404 exception if unknown', async () => {
|
|
192
|
-
const id = 'pi_' + randomString(24);
|
|
193
|
-
const repository = new PaymentIntentRepository();
|
|
194
|
-
await expect(() => repository.create(id)).rejects.toThrow();
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('refunds', () => {
|
|
199
|
-
it('get refunds', async () => {
|
|
200
|
-
const repository = new PaymentIntentRepository();
|
|
201
|
-
const id = idPaymentIntent('pi_ulnYUmuUFoqp2yWBy1sgvuA3');
|
|
202
|
-
const paymentIntent = await repository.create(id);
|
|
203
|
-
expect(paymentIntent.id).toBe(id);
|
|
204
|
-
expect(paymentIntent.amount).toBe(612);
|
|
205
|
-
await repository.getRefunds(paymentIntent);
|
|
206
|
-
expect(paymentIntent.refunds).toHaveLength(2);
|
|
207
|
-
expect(paymentIntent.refunds[0]).toBeInstanceOf(RefundModel);
|
|
208
|
-
|
|
209
|
-
expect(paymentIntent.refundableAmount).toBe(612);
|
|
210
|
-
expect(paymentIntent.refundedAmount).toBe(0);
|
|
211
|
-
expect(paymentIntent.amount).toBe(paymentIntent.refundableAmount + paymentIntent.refundedAmount);
|
|
212
|
-
expect(paymentIntent.isRefundPopulated()).toBe(true);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import 'temporal-polyfill/global';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Configuration } from '#api/configuration.js';
|
|
6
|
-
import { PaymentApiEndpoint } from '#payment/api-endpoint.js';
|
|
7
|
-
import { CurrencyEnum } from '#payment/enum/currency.js';
|
|
8
|
-
import { IdPayment, PaymentAmount, PaymentModel, idPayment, paymentAmount } from '#payment/model.js';
|
|
9
|
-
import { PaymentRepository } from '#payment/repository.js';
|
|
10
|
-
import { RefundRepository } from '#refund/repository.ts';
|
|
11
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
12
|
-
|
|
13
|
-
describe('payment functional', () => {
|
|
14
|
-
Configuration.setKey({
|
|
15
|
-
privateLiveKey: null,
|
|
16
|
-
privateTestKey: process.env['API_KEY'] ?? null,
|
|
17
|
-
});
|
|
18
|
-
Configuration._host = process.env['API_HOST'] ?? 'api.stancer.com';
|
|
19
|
-
const amount = randomNumber(50, 5000) as PaymentAmount;
|
|
20
|
-
const currency = CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)];
|
|
21
|
-
describe('payment creation', () => {
|
|
22
|
-
it('create a payment with minimum information', async () => {
|
|
23
|
-
const repository = new PaymentRepository();
|
|
24
|
-
|
|
25
|
-
const payment = await repository.create({ amount, currency });
|
|
26
|
-
await repository.send(payment);
|
|
27
|
-
expect(payment.id).toBeTruthy();
|
|
28
|
-
expect(payment.id).toContain('paym_');
|
|
29
|
-
expect(payment.amount).toBe(amount);
|
|
30
|
-
expect(payment.currency).toBe(currency);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('create a complete flat payment', async () => {
|
|
34
|
-
const repository = new PaymentRepository();
|
|
35
|
-
const amount = paymentAmount(randomNumber(50, 4294967295));
|
|
36
|
-
const capture = true; //false doesn't work we need a proper test just for capture
|
|
37
|
-
const currency = CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)];
|
|
38
|
-
const description = randomString(3, 64);
|
|
39
|
-
const methodsAllowed = ['card']; //because we send all the possible currency
|
|
40
|
-
const orderId = randomString(1, 36);
|
|
41
|
-
const returnUrl = randomString(1, 66);
|
|
42
|
-
const uniqueId = randomString(1, 36);
|
|
43
|
-
const paymentData = {
|
|
44
|
-
amount,
|
|
45
|
-
capture,
|
|
46
|
-
currency,
|
|
47
|
-
description,
|
|
48
|
-
methodsAllowed,
|
|
49
|
-
orderId,
|
|
50
|
-
uniqueId,
|
|
51
|
-
returnUrl: `https://${returnUrl}`,
|
|
52
|
-
};
|
|
53
|
-
const payment = await repository.create(paymentData);
|
|
54
|
-
|
|
55
|
-
await repository.send(payment);
|
|
56
|
-
|
|
57
|
-
expect(payment.id).toBeTruthy();
|
|
58
|
-
|
|
59
|
-
//Check that the value send are the value received
|
|
60
|
-
expect(payment._data).toMatchObject(paymentData);
|
|
61
|
-
|
|
62
|
-
// Check that the API Generated value are populated
|
|
63
|
-
expect(payment._data.id).toBe(payment.id);
|
|
64
|
-
expect(payment._data.id).toBeDefined();
|
|
65
|
-
expect(payment._data.createdAt).toBeDefined();
|
|
66
|
-
expect(payment._data.datePayment).toBeDefined();
|
|
67
|
-
expect(payment._data.fee).toBeDefined();
|
|
68
|
-
expect(payment._data.origin).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('need required amount', async () => {
|
|
72
|
-
const repository = new PaymentRepository();
|
|
73
|
-
|
|
74
|
-
const paymentWithoutRequiredValue = await repository.create({ currency });
|
|
75
|
-
|
|
76
|
-
await expect(async () => await repository.send(paymentWithoutRequiredValue)).rejects.toThrow(
|
|
77
|
-
'amount is required to send PaymentModel',
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
it('need required currency', async () => {
|
|
81
|
-
const repository = new PaymentRepository();
|
|
82
|
-
|
|
83
|
-
const paymentWithoutRequiredValue = await repository.create({ amount });
|
|
84
|
-
|
|
85
|
-
await expect(async () => await repository.send(paymentWithoutRequiredValue)).rejects.toThrow(
|
|
86
|
-
'currency is required to send PaymentModel',
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('patch', () => {
|
|
92
|
-
it('is available on payment', async () => {
|
|
93
|
-
const repository = new PaymentRepository();
|
|
94
|
-
const payment = await repository.create({ amount, currency });
|
|
95
|
-
|
|
96
|
-
await repository.send(payment);
|
|
97
|
-
const id = payment.id;
|
|
98
|
-
expect(id).toBeTruthy();
|
|
99
|
-
expect(payment.amount).toBe(amount);
|
|
100
|
-
expect(payment.currency).toBe(currency);
|
|
101
|
-
|
|
102
|
-
const newAmount = randomNumber(51, 5000);
|
|
103
|
-
payment.setAmount(newAmount);
|
|
104
|
-
await repository.send(payment);
|
|
105
|
-
expect(id).toBe(payment.id);
|
|
106
|
-
expect(payment.amount).toBe(newAmount);
|
|
107
|
-
expect(payment.currency).toBe(currency);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('delete', () => {
|
|
111
|
-
it('cannot delete payment', async () => {
|
|
112
|
-
const repository = new PaymentRepository();
|
|
113
|
-
const payment = await repository.create({ amount, currency });
|
|
114
|
-
await repository.send(payment);
|
|
115
|
-
expect(payment.id).toBeTruthy();
|
|
116
|
-
await expect(async () => await repository.delete(payment)).rejects.toThrow();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
describe('list', async () => {
|
|
120
|
-
it('should return all payment with same orderId', async () => {
|
|
121
|
-
const orderId = `${Date.now()}-${randomString(8)}`;
|
|
122
|
-
const expectedAmount = paymentAmount(50);
|
|
123
|
-
const expectedCurrency = 'eur';
|
|
124
|
-
const expectedCount = 3;
|
|
125
|
-
const repository = new PaymentRepository();
|
|
126
|
-
const payments = await Promise.all(
|
|
127
|
-
Array.from({ length: expectedCount }, () =>
|
|
128
|
-
repository
|
|
129
|
-
.create()
|
|
130
|
-
.then((payment) =>
|
|
131
|
-
repository
|
|
132
|
-
.send(payment.setAmount(expectedAmount).setCurrency(expectedCurrency).setOrderId(orderId))
|
|
133
|
-
.then((payment) => expect(payment).toHaveProperty('id')),
|
|
134
|
-
),
|
|
135
|
-
),
|
|
136
|
-
);
|
|
137
|
-
expect(payments).toHaveLength(expectedCount);
|
|
138
|
-
|
|
139
|
-
const items = repository.list({ limit: expectedCount, filters: { order_id: orderId } });
|
|
140
|
-
let length = 0;
|
|
141
|
-
for await (const item of items) {
|
|
142
|
-
expect(item).toBeInstanceOf(PaymentModel);
|
|
143
|
-
expect(item.amount).toEqual(expectedAmount);
|
|
144
|
-
expect(item.currency).toEqual(expectedCurrency);
|
|
145
|
-
expect(item.orderId).toEqual(orderId);
|
|
146
|
-
length++;
|
|
147
|
-
}
|
|
148
|
-
expect(length).toBe(expectedCount);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should return empty list if no payment match orderId', async () => {
|
|
152
|
-
const repository = new PaymentRepository();
|
|
153
|
-
|
|
154
|
-
const orderId = `no_matching_order_id`;
|
|
155
|
-
const items = await repository.list({ limit: 10, filters: { order_id: orderId } });
|
|
156
|
-
const item = await items.next();
|
|
157
|
-
expect(item.done).toBeTruthy();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe('get', () => {
|
|
161
|
-
it('get the correct object', async () => {
|
|
162
|
-
const repository = new PaymentRepository();
|
|
163
|
-
const id = 'paym_36bmekUuW4IMdJrMC0MCeyDt' as IdPayment;
|
|
164
|
-
const payment = await repository.create(id);
|
|
165
|
-
const returnData = {
|
|
166
|
-
id,
|
|
167
|
-
amount: 500,
|
|
168
|
-
card: 'card_uqY2HrovY2sPm0Ac2xhnBkfU',
|
|
169
|
-
capture: true,
|
|
170
|
-
created: Temporal.Instant.fromEpochMilliseconds(1787844165 * 1000),
|
|
171
|
-
currency: 'eur',
|
|
172
|
-
datePayment: Temporal.Instant.fromEpochMilliseconds(1787844165 * 1000),
|
|
173
|
-
description: 'Automatic test, 5.00 eur',
|
|
174
|
-
method: 'card',
|
|
175
|
-
fee: 18,
|
|
176
|
-
origin: 'api',
|
|
177
|
-
response: '00',
|
|
178
|
-
status: 'to_capture',
|
|
179
|
-
};
|
|
180
|
-
const methodsAllowed = ['sepa', 'card'];
|
|
181
|
-
expect(payment.methodsAllowed).toStrictEqual(methodsAllowed);
|
|
182
|
-
expect(payment).toMatchObject(returnData);
|
|
183
|
-
});
|
|
184
|
-
it('get a 404 exception if unknown', async () => {
|
|
185
|
-
const id = 'paym_' + randomString(24);
|
|
186
|
-
const repository = new PaymentRepository();
|
|
187
|
-
await expect(() => repository.create(id)).rejects.toThrow();
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
describe('refunds', () => {
|
|
191
|
-
it('get refunds', async () => {
|
|
192
|
-
const refundRepository = new RefundRepository();
|
|
193
|
-
const repository = new PaymentRepository(new PaymentApiEndpoint(), refundRepository);
|
|
194
|
-
const id = idPayment('paym_NoUQRyZNLEv6q7H2ZBmffR7h');
|
|
195
|
-
const payment = await repository.create(id);
|
|
196
|
-
expect(payment.id).toBe(id);
|
|
197
|
-
expect(payment.amount).toBe(5521);
|
|
198
|
-
await repository.populateRefunds(payment);
|
|
199
|
-
expect(payment.refunds).toHaveLength(3);
|
|
200
|
-
expect(payment.refundableAmount).toBe(0);
|
|
201
|
-
expect(payment.refundedAmount).toBe(5521);
|
|
202
|
-
expect(payment.amount).toBe(payment.refundedAmount - payment.refundableAmount);
|
|
203
|
-
expect(payment.isRefundPopulated()).toBe(true);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|