@smartsoft001/trans-shell-app-services 2.184.0 → 2.186.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/README.md
CHANGED
|
@@ -30,3 +30,15 @@ Methods:
|
|
|
30
30
|
<td>Retrieves a transaction by its ID from the repository.</td>
|
|
31
31
|
</tr>
|
|
32
32
|
</table>
|
|
33
|
+
|
|
34
|
+
## ⚠️ Internal service, payment amounts and completing payments
|
|
35
|
+
|
|
36
|
+
`TransService.create` charges only the `amount` your internal service approves, and status changes
|
|
37
|
+
go through `ITransInternalService.refreshOnce`, which must be idempotent. Register a provider under
|
|
38
|
+
`TRANS_TOKEN_INTERNAL_SERVICE` whose `create` returns `{ amount }` (a positive integer in minor
|
|
39
|
+
units) and whose `refreshOnce` deduplicates by its idempotency key. Or set `internalApiUrl` to a back
|
|
40
|
+
end whose `POST` response contains `amount` and whose `PUT` honours the `Idempotency-Key` header, and
|
|
41
|
+
set `idempotentInternalApi: true`. Without the flag the built-in fallback rejects every status
|
|
42
|
+
change. With neither a provider nor a url (offline mode), the built-in fallback makes no request:
|
|
43
|
+
`create` rejects with `DomainValidationError` and so does every status change, so no payment can be
|
|
44
|
+
created or completed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartsoft001/trans-shell-app-services",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.186.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"typings": "./src/index.d.ts",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"@nestjs/axios": "^4.0.1",
|
|
23
23
|
"@nestjs/common": "^11.1.5",
|
|
24
24
|
"@nestjs/core": "^11.2.1",
|
|
25
|
-
"@smartsoft001/domain-core": "2.
|
|
26
|
-
"@smartsoft001/paynow": "2.
|
|
27
|
-
"@smartsoft001/paypal": "2.
|
|
28
|
-
"@smartsoft001/payu": "2.
|
|
29
|
-
"@smartsoft001/revolut": "2.
|
|
30
|
-
"@smartsoft001/trans-domain": "2.
|
|
25
|
+
"@smartsoft001/domain-core": "2.186.0",
|
|
26
|
+
"@smartsoft001/paynow": "2.186.0",
|
|
27
|
+
"@smartsoft001/paypal": "2.186.0",
|
|
28
|
+
"@smartsoft001/payu": "2.186.0",
|
|
29
|
+
"@smartsoft001/revolut": "2.186.0",
|
|
30
|
+
"@smartsoft001/trans-domain": "2.186.0",
|
|
31
31
|
"rxjs": "^7.8.1"
|
|
32
32
|
},
|
|
33
33
|
"types": "./src/index.d.ts"
|
|
@@ -34,23 +34,23 @@ let TransService = class TransService {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
_internalService = {
|
|
37
|
+
// Offline (no internalApiUrl) or without a declared idempotent API there
|
|
38
|
+
// is nothing that can fulfil an order exactly once, so refuse. Async, so
|
|
39
|
+
// the refusal is a rejected promise like every other failure.
|
|
40
|
+
refreshOnce: async (trans, idempotencyKey) => {
|
|
41
|
+
if (!this.config.internalApiUrl ||
|
|
42
|
+
this.config.idempotentInternalApi !== true) {
|
|
43
|
+
throw new domain_core_1.DomainValidationError('An idempotent internal API must be configured');
|
|
44
|
+
}
|
|
45
|
+
return (0, rxjs_1.firstValueFrom)(this.httpService.put(this.config.internalApiUrl + '/' + encodeURIComponent(trans.id), trans, { headers: { 'Idempotency-Key': idempotencyKey } })).then((res) => res.data);
|
|
46
|
+
},
|
|
37
47
|
create: (trans) => {
|
|
48
|
+
// Only a back end can price an order. Without one there is no amount
|
|
49
|
+
// to charge, so a payment cannot start.
|
|
38
50
|
if (!this.config.internalApiUrl)
|
|
39
|
-
return Promise.
|
|
40
|
-
date: new Date(),
|
|
41
|
-
req: trans,
|
|
42
|
-
});
|
|
51
|
+
return Promise.reject(new domain_core_1.DomainValidationError('No internal service approves the payment amount: set internalApiUrl or provide TRANS_TOKEN_INTERNAL_SERVICE'));
|
|
43
52
|
return (0, rxjs_1.firstValueFrom)(this.httpService.post(this.config.internalApiUrl, trans)).then((res) => res.data);
|
|
44
53
|
},
|
|
45
|
-
refresh: (trans) => {
|
|
46
|
-
if (!this.config.internalApiUrl)
|
|
47
|
-
return Promise.resolve({
|
|
48
|
-
date: new Date(),
|
|
49
|
-
req: trans,
|
|
50
|
-
id: trans.id,
|
|
51
|
-
});
|
|
52
|
-
return (0, rxjs_1.firstValueFrom)(this.httpService.put(this.config.internalApiUrl + '/' + trans.id, trans)).then((res) => res.data);
|
|
53
|
-
},
|
|
54
54
|
};
|
|
55
55
|
constructor(moduleRef, creatorService, refresherService, refundService, httpService, config, repository, payuService, paynowService, paypalService, revolutService) {
|
|
56
56
|
this.moduleRef = moduleRef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trans.service.js","sourceRoot":"","sources":["../../../../../../../../../packages/trans/shell/app-services/src/lib/services/trans/trans.service.ts"],"names":[],"mappings":";;;;AAAA,yCAA4C;AAC5C,2CAAsD;AACtD,uCAAyC;AACzC,+BAAsC;AAEtC,
|
|
1
|
+
{"version":3,"file":"trans.service.js","sourceRoot":"","sources":["../../../../../../../../../packages/trans/shell/app-services/src/lib/services/trans/trans.service.ts"],"names":[],"mappings":";;;;AAAA,yCAA4C;AAC5C,2CAAsD;AACtD,uCAAyC;AACzC,+BAAsC;AAEtC,2DAGmC;AACnC,iDAAqD;AACrD,iDAAqD;AACrD,6CAAiD;AACjD,mDAAuD;AACvD,6DASoC;AAEpC,mEAA4E;AAGrE,IAAM,YAAY,GAAlB,MAAM,YAAY;IAkDb;IACA;IACA;IACA;IACA;IACA;IACA;IACY;IACA;IACA;IACA;IA3DtB,IAAY,eAAe;QAGzB,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,MAAM,EAAE,IAAI,CAAC,aAAa;YAC1B,MAAM,EAAE,IAAI,CAAC,aAAa;YAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;SAC7B,CAAC;IACJ,CAAC;IAEO,gB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