Skip to content

Commit af226d6

Browse files
authored
feat(payment-stipe): update tests and endpoints (#55)
* feat(http-requests): cleanup * feat(content): add tests for factory * feat(content): update tests * feat(content): add default payment method endpoint * feat(content): update permissions * feat(content): update payment method validation * feat(content): update payment method tests * feat(content): remove redundant model transactions * feat(payment-stripe): card service * feat(payment-stripe): card subscriber * feat(payment-stripe): remove redundant card set default endpoint * feat(payment-stripe): update set default card flow * feat(payment-stripe): remove redundant auth models and methods * feat(payment-stripe): update config local webhook keys example * feat(payment-stripe): update payment stripe readme * feat(payment-stripe): update migration * feat(payment-stripe): update card and bank account entities * feat(payment-stripe): update card service handle create * feat(payment-stripe): add update card http request examples * feat(payment-stripe): cleanup readme * feat(payment-stripe): update migration * feat(payment-stripe): update card and bank account constraints * feat(payment-stripe): update config local * feat(payment-stripe): update migration on delete action * feat(payment-stripe): update http requests * feat(payment-stripe): update tests and mocks * feat(payment-stripe): update customer create input * feat(payment-stripe): update customer create input * feat(payment-stripe): update jsdocs * feat(payment-stripe): handle webhook types * feat(payment-stripe): update readme
1 parent 4b833f5 commit af226d6

File tree

15 files changed

+685
-95
lines changed

15 files changed

+685
-95
lines changed

configs/config.local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@
122122
"apiVersion": "2022-11-15"
123123
},
124124
"payoutCoeff": 0.3,
125-
"webhookKey": "your test webhook key from stripe or other service",
125+
"webhookKeys": {
126+
"connect": "your test webhook key from stripe or other service for connect account"
127+
},
126128
"fees": { "stableUnit": 30, "paymentPercent": 2.9 }
127129
}
128130
}

http-requests/payment-stripe/requests.http

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Content-Type: application/json
99
"id": "1",
1010
"method": "customer.create",
1111
"params": {
12-
"userId": "userf8f1-17f8-4501-9de2-a6e775ea39f3"
12+
"userId": "userf8f1-17f8-4501-9de2-a6e775ea39f3",
13+
"name": "John",
14+
"email": "[email protected]"
1315
}
1416
}
1517

@@ -22,7 +24,9 @@ Content-Type: application/json
2224
"id": "1",
2325
"method": "customer.create",
2426
"params": {
25-
"userId": "admif8f1-17f8-4501-9de2-a6e775ea39f3"
27+
"userId": "admif8f1-17f8-4501-9de2-a6e775ea39f3",
28+
"name": "mike",
29+
"email": "[email protected]"
2630
}
2731
}
2832

@@ -49,7 +53,7 @@ Content-Type: application/json
4953
"method": "stripe.connect-account",
5054
"params": {
5155
"userId": "admif8f1-17f8-4501-9de2-a6e775ea39f3",
52-
"email": "receiver@gmail.com",
56+
"email": "r111eceiver@gmail.com",
5357
"accountType": "standard",
5458
"refreshUrl": "https://example.com",
5559
"returnUrl": "https://example.com"
@@ -263,3 +267,36 @@ Content-Type: application/json
263267
"holderName": "Mike"
264268
}
265269
}
270+
271+
### Update default payment method (card)
272+
POST http://127.0.0.1:8001/ms/payment-stripe
273+
Accept: application/json
274+
Content-Type: application/json
275+
276+
{
277+
"id": "1",
278+
"method": "card.update",
279+
"params": {
280+
"fields": {
281+
"isDefault": true
282+
},
283+
"query": {
284+
"where": {
285+
"id": "8fb91f11-db33-4054-80f4-d10e966e9d75"
286+
}
287+
}
288+
}
289+
}
290+
291+
### Remove customer
292+
POST http://127.0.0.1:8001/ms/payment-stripe
293+
Accept: application/json
294+
Content-Type: application/json
295+
296+
{
297+
"id": "1",
298+
"method": "customer.remove",
299+
"params": {
300+
"userId": "userf8f1-17f8-4501-9de2-a6e775ea39f3"
301+
}
302+
}

microservices/authorization/migrations/permissions/list/models/payment-stripe.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@
4747
"user": "allow"
4848
}
4949
},
50+
"createdAt": {
51+
"in": {
52+
"admin": "allow"
53+
},
54+
"out": {
55+
"admin": "allow"
56+
}
57+
},
58+
"updatedAt": {
59+
"in": {
60+
"admin": "allow"
61+
},
62+
"out": {
63+
"admin": "allow"
64+
}
65+
},
5066
"product": "payment-stripe.Product"
5167
},
5268
"createdAt": "2023-05-26T15:01:39.186Z"
@@ -83,6 +99,22 @@
8399
"user": "allow"
84100
}
85101
},
102+
"createdAt": {
103+
"in": {
104+
"admin": "allow"
105+
},
106+
"out": {
107+
"admin": "allow"
108+
}
109+
},
110+
"updatedAt": {
111+
"in": {
112+
"admin": "allow"
113+
},
114+
"out": {
115+
"admin": "allow"
116+
}
117+
},
86118
"price": "payment-stripe.Price",
87119
"transactions": "payment-stripe.Transaction"
88120
},
@@ -208,6 +240,22 @@
208240
"user": "allow"
209241
}
210242
},
243+
"createdAt": {
244+
"in": {
245+
"admin": "allow"
246+
},
247+
"out": {
248+
"admin": "allow"
249+
}
250+
},
251+
"updatedAt": {
252+
"in": {
253+
"admin": "allow"
254+
},
255+
"out": {
256+
"admin": "allow"
257+
}
258+
},
211259
"customer": "payment-stripe.Customer",
212260
"product": "payment-stripe.Product"
213261
},
@@ -340,6 +388,22 @@
340388
"user": "allow"
341389
}
342390
},
391+
"createdAt": {
392+
"in": {
393+
"admin": "allow"
394+
},
395+
"out": {
396+
"admin": "allow"
397+
}
398+
},
399+
"updatedAt": {
400+
"in": {
401+
"admin": "allow"
402+
},
403+
"out": {
404+
"admin": "allow"
405+
}
406+
},
343407
"transactions": "payment-stripe.Transaction",
344408
"cards": "payment-stripe.Card",
345409
"bankAccounts": "payment-stripe.BankAccount"
@@ -883,6 +947,22 @@
883947
"out": {
884948
"user": "allow"
885949
}
950+
},
951+
"name": {
952+
"in": {
953+
"user": "allow"
954+
},
955+
"out": {
956+
"user": "allow"
957+
}
958+
},
959+
"email": {
960+
"in": {
961+
"user": "allow"
962+
},
963+
"out": {
964+
"user": "allow"
965+
}
886966
}
887967
},
888968
"createdAt": "2023-05-26T15:01:39.186Z"

microservices/payment-stripe/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,12 @@ That is all. **Don't forget install npm dependencies**
7676
__Run on typescript__: ~200 MB PEAK / ~160 MB
7777
__Run on JS__: ~110 MB PEAK / ~80 MB
7878

79+
### <a id="memory-usage"></a>STRIPE:
80+
81+
Run stripe cli for test dev env:
82+
83+
```bash
84+
stripe listen --forward-to 'http://localhost:3005/webhook/payment-stripe.stripe.webhook/webhooktokenoooooooooooooooooooo?id=connect'
85+
```
86+
7987
Rebuild: 1

microservices/payment-stripe/__mocks__/stripe.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const customerMock = {
88
id: 'cus_NshmwHkITU8Egm',
99
object: 'customer',
1010
description: 'Mike',
11-
};
11+
// eslint-disable-next-line camelcase
12+
invoice_settings: {
13+
// eslint-disable-next-line camelcase
14+
default_payment_method: null,
15+
},
16+
} as StripeSdk.Customer;
1217

1318
const accountMock = {
1419
id: accountIdMock,
@@ -30,4 +35,13 @@ const balancesMock: StripeSdk.Balance = {
3035
available: [{ currency: 'usd', amount: 1000 }],
3136
};
3237

33-
export { customerMock, clientSecretMock, accountMock, accountLinkMock, balancesMock };
38+
const paymentMethodId = 'payment-method-id';
39+
40+
export {
41+
customerMock,
42+
clientSecretMock,
43+
accountMock,
44+
accountLinkMock,
45+
balancesMock,
46+
paymentMethodId,
47+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { TypeormMock } from '@lomray/microservice-helpers/mocks';
2+
import { waitResult } from '@lomray/microservice-helpers/test-helpers';
3+
import { expect } from 'chai';
4+
import sinon from 'sinon';
5+
import * as remoteConfig from '@config/remote';
6+
import Factory from '@services/payment-gateway/factory';
7+
import Stripe from '@services/payment-gateway/stripe';
8+
9+
describe('services/payment-gateway/factory', () => {
10+
const remoteConfigMock = {
11+
config: {
12+
apiVersion: '2022-11-15',
13+
},
14+
paymentMethods: ['bancontact', 'card'],
15+
apiKey: 'fake-api-key',
16+
};
17+
18+
afterEach(() => {
19+
sinon.restore();
20+
});
21+
22+
it('should create a Stripe instance with the provided parameters', async () => {
23+
const remoteConfigStub = sinon.stub().resolves(remoteConfigMock);
24+
25+
sinon.replace(remoteConfig, 'default', remoteConfigStub);
26+
27+
const stripeInstance = await Factory.create(TypeormMock.entityManager);
28+
29+
expect(stripeInstance).to.be.an.instanceOf(Stripe);
30+
});
31+
32+
it('should create a Stripe instance with the provided parameters', async () => {
33+
const configs = [
34+
{},
35+
{ apikey: remoteConfigMock.apiKey },
36+
{ config: remoteConfigMock.config },
37+
{ paymentMethods: remoteConfigMock.paymentMethods },
38+
];
39+
40+
for (const config of configs) {
41+
const remoteConfigStub = sinon.stub().resolves(config);
42+
43+
sinon.replace(remoteConfig, 'default', remoteConfigStub);
44+
sinon.restore();
45+
46+
expect(await waitResult(Factory.create(TypeormMock.entityManager))).to.throw(
47+
'Payment options or api key or payment methods for stripe are not provided',
48+
);
49+
}
50+
});
51+
});

0 commit comments

Comments
 (0)