@stancer/stancer 0.0.0-stage → 1.0.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/.editorconfig +14 -0
- package/.gitlab-ci.yml +159 -0
- package/.prettierignore +3 -0
- package/CHANGELOG.md +10 -0
- package/LICENSE +19 -0
- package/README.md +166 -2
- package/eslint.config.js +14 -0
- package/package.json +52 -3
- package/pnpm-workspace.yaml +19 -0
- package/prettier.config.js +3 -0
- package/src/address/api-endpoint.ts +30 -0
- package/src/address/model.ts +79 -0
- package/src/address/repository.ts +18 -0
- package/src/address/validator.ts +34 -0
- package/src/api-endpoint/abstract-api-endpoint.ts +310 -0
- package/src/api-endpoint/configuration.ts +125 -0
- package/src/api-endpoint/http/fetch-http-client.ts +29 -0
- package/src/api-endpoint/http/http.ts +75 -0
- package/src/api-endpoint/http/index.ts +2 -0
- package/src/api-endpoint/version.ts +4 -0
- package/src/card/api-endpoint.ts +39 -0
- package/src/card/enum/funding.ts +11 -0
- package/src/card/enum/nature.ts +7 -0
- package/src/card/enum/network.ts +16 -0
- package/src/card/model.ts +139 -0
- package/src/card/repository.ts +11 -0
- package/src/card/validator.ts +79 -0
- package/src/core/abstract-model.ts +126 -0
- package/src/core/abstract-repository.ts +201 -0
- package/src/core/common/branded-type.ts +15 -0
- package/src/core/common/handler/date-handler.ts +31 -0
- package/src/core/common/handler/enum-handler.ts +18 -0
- package/src/core/common/handler/handler.ts +64 -0
- package/src/core/common/handler/id-handler.ts +27 -0
- package/src/core/common/id-validator.ts +23 -0
- package/src/core/common/mutation-tracked-object.ts +49 -0
- package/src/core/endpoint-interface.ts +43 -0
- package/src/core/error/base-error.ts +1 -0
- package/src/core/error/endpoint/api/api-conflict-error.ts +7 -0
- package/src/core/error/endpoint/api/api-error.ts +10 -0
- package/src/core/error/endpoint/api/api-not-found-error.ts +7 -0
- package/src/core/error/endpoint/api/api-unauthorized-error.ts +7 -0
- package/src/core/error/endpoint/api/api-unknown-error.ts +7 -0
- package/src/core/error/endpoint/api/api-validation-error.ts +13 -0
- package/src/core/error/endpoint/api/index.ts +6 -0
- package/src/core/error/endpoint/route-inaccessible-error.ts +8 -0
- package/src/core/error/unpopulated-error.ts +3 -0
- package/src/core/error/unsendable-error.ts +3 -0
- package/src/core/error/validation-error.ts +3 -0
- package/src/core/validator.ts +129 -0
- package/src/customer/api-endpoint.ts +29 -0
- package/src/customer/model.ts +113 -0
- package/src/customer/repository.ts +14 -0
- package/src/customer/validator.ts +26 -0
- package/src/payment/api-endpoint.ts +118 -0
- package/src/payment/enum/currency.ts +14 -0
- package/src/payment/enum/method.ts +2 -0
- package/src/payment/enum/status.ts +21 -0
- package/src/payment/model.ts +378 -0
- package/src/payment/repository.ts +73 -0
- package/src/payment/validator.ts +96 -0
- package/src/payment-intent/api-endpoint.ts +123 -0
- package/src/payment-intent/enum/status.ts +21 -0
- package/src/payment-intent/enum/threeds.ts +2 -0
- package/src/payment-intent/model.ts +266 -0
- package/src/payment-intent/repository.ts +85 -0
- package/src/payment-intent/validator.ts +45 -0
- package/src/payout/model.ts +8 -0
- package/src/refund/api-endpoint.ts +33 -0
- package/src/refund/enum/refund-status.ts +11 -0
- package/src/refund/model.ts +90 -0
- package/src/refund/repository.ts +14 -0
- package/src/refund/validator.ts +44 -0
- package/src/sepa/api-endpoint.ts +26 -0
- package/src/sepa/model.ts +80 -0
- package/src/sepa/repository.ts +11 -0
- package/src/sepa/validator.ts +56 -0
- package/test/fixtures/endpoint.stub.ts +22 -0
- package/test/fixtures/list-endpoint.stub.ts +33 -0
- package/test/fixtures/list-model.stub.ts +24 -0
- package/test/fixtures/model.stub.ts +12 -0
- package/test/functional/address.test.ts +126 -0
- package/test/functional/card.test.ts +175 -0
- package/test/functional/customer.test.ts +174 -0
- package/test/functional/payment-intent.test.ts +215 -0
- package/test/functional/payment.test.ts +206 -0
- package/test/functional/refund.test.ts +112 -0
- package/test/functional/sepa.test.ts +136 -0
- package/test/integration/stub-integration.test.ts +88 -0
- package/test/stub/stub-endpoint.ts +42 -0
- package/test/stub/stub-model.ts +82 -0
- package/test/stub/stub-repository.ts +11 -0
- package/test/test-helper.ts +133 -0
- package/test/unit/address/api-endpoint.test.ts +134 -0
- package/test/unit/address/fixtures.ts +60 -0
- package/test/unit/address/model.test.ts +75 -0
- package/test/unit/address/repository.test.ts +148 -0
- package/test/unit/address/validator.test.ts +49 -0
- package/test/unit/api-endpoint/http/fetch-http-client.test.ts +44 -0
- package/test/unit/api-endpoint/http/http.test.ts +152 -0
- package/test/unit/card/api-endpoint.test.ts +170 -0
- package/test/unit/card/card-helper.ts +116 -0
- package/test/unit/card/fixtures.ts +87 -0
- package/test/unit/card/model.test.ts +167 -0
- package/test/unit/card/repository.test.ts +146 -0
- package/test/unit/card/validator.test.ts +96 -0
- package/test/unit/core/common/mutation-tracked-object.test.ts +24 -0
- package/test/unit/customer/api-endpoint.test.ts +143 -0
- package/test/unit/customer/fixtures.ts +73 -0
- package/test/unit/customer/model.test.ts +90 -0
- package/test/unit/customer/repository.test.ts +148 -0
- package/test/unit/customer/validator.test.ts +62 -0
- package/test/unit/payment/api-endpoint.test.ts +188 -0
- package/test/unit/payment/fixtures.ts +116 -0
- package/test/unit/payment/model.test.ts +240 -0
- package/test/unit/payment/repository.test.ts +270 -0
- package/test/unit/payment/validator.test.ts +137 -0
- package/test/unit/payment-intent/api-endpoint.test.ts +142 -0
- package/test/unit/payment-intent/fixtures.ts +94 -0
- package/test/unit/payment-intent/model.test.ts +157 -0
- package/test/unit/payment-intent/repository.test.ts +263 -0
- package/test/unit/payment-intent/validator.test.ts +136 -0
- package/test/unit/refund/api-endpoint.test.ts +129 -0
- package/test/unit/refund/fixtures.ts +58 -0
- package/test/unit/refund/model.test.ts +89 -0
- package/test/unit/refund/repository.test.ts +157 -0
- package/test/unit/refund/validator.test.ts +89 -0
- package/test/unit/sepa/api-endpoint.test.ts +170 -0
- package/test/unit/sepa/fixture.ts +62 -0
- package/test/unit/sepa/model.test.ts +86 -0
- package/test/unit/sepa/repository.test.ts +149 -0
- package/test/unit/sepa/sepa-helper.ts +71 -0
- package/test/unit/sepa/validator.test.ts +58 -0
- package/test/unit/stub/stub-endpoint.test.ts +236 -0
- package/test/unit/stub/stub-list-endpoint.test.ts +86 -0
- package/test/unit/stub/stub-model.test.ts +111 -0
- package/test/unit/stub/stub-repository.test.ts +144 -0
- package/tsconfig.json +50 -0
- package/vitest.config.ts +20 -0
package/.editorconfig
ADDED
package/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
spec:
|
|
2
|
+
inputs:
|
|
3
|
+
nodeVersion:
|
|
4
|
+
default: 22
|
|
5
|
+
description: Node version.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
.cache: &cache
|
|
10
|
+
key:
|
|
11
|
+
files:
|
|
12
|
+
- pnpm-lock.yaml
|
|
13
|
+
paths:
|
|
14
|
+
- node_modules/.bin
|
|
15
|
+
- node_modules/.cache/pnpm
|
|
16
|
+
- node_modules/.pnpm
|
|
17
|
+
- node_modules/@**
|
|
18
|
+
- node_modules/[a-z]**
|
|
19
|
+
- node_modules/.modules.yaml
|
|
20
|
+
unprotect: true
|
|
21
|
+
when: always
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
.base:
|
|
25
|
+
image: wearestancer/node:$[[ inputs.nodeVersion ]]
|
|
26
|
+
|
|
27
|
+
before_script:
|
|
28
|
+
- section_start --collapsed node_install "Package install"
|
|
29
|
+
- echo "node $(node --version)"
|
|
30
|
+
- echo "pnpm $(pnpm --version)"
|
|
31
|
+
- pnpm config set store-dir node_modules/.cache/pnpm
|
|
32
|
+
- pnpm install --frozen-lockfile --prefer-offline
|
|
33
|
+
- section_end node_install
|
|
34
|
+
|
|
35
|
+
cache:
|
|
36
|
+
- <<: *cache
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
stages:
|
|
40
|
+
- test
|
|
41
|
+
- build
|
|
42
|
+
- deploy
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
workflow:
|
|
46
|
+
auto_cancel:
|
|
47
|
+
on_job_failure: none
|
|
48
|
+
on_new_commit: interruptible
|
|
49
|
+
rules:
|
|
50
|
+
- if: $CI_COMMIT_REF_PROTECTED == "true"
|
|
51
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
52
|
+
- if: $CI_PIPELINE_SOURCE == "web"
|
|
53
|
+
- if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS"
|
|
54
|
+
when: never
|
|
55
|
+
- when: always
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
variables:
|
|
59
|
+
FF_SCRIPT_SECTIONS: true
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
ESLint:
|
|
63
|
+
extends:
|
|
64
|
+
- .base
|
|
65
|
+
|
|
66
|
+
stage: test
|
|
67
|
+
|
|
68
|
+
script:
|
|
69
|
+
- pnpm exec eslint --cache --cache-location 'node_modules/.cache/eslint' "**/*.{js,ts,vue}" || true
|
|
70
|
+
- pnpm exec eslint --cache --cache-location 'node_modules/.cache/eslint' --max-warnings 0 --format junit "**/*.{js,ts,vue}" > junit.xml
|
|
71
|
+
|
|
72
|
+
cache:
|
|
73
|
+
- <<: *cache
|
|
74
|
+
- key: "${CI_COMMIT_REF_SLUG}-eslint"
|
|
75
|
+
fallback_keys:
|
|
76
|
+
- "${CI_DEFAULT_BRANCH}-eslint"
|
|
77
|
+
paths:
|
|
78
|
+
- node_modules/.cache/eslint
|
|
79
|
+
unprotect: true
|
|
80
|
+
when: always
|
|
81
|
+
|
|
82
|
+
artifacts:
|
|
83
|
+
reports:
|
|
84
|
+
junit:
|
|
85
|
+
- junit.xml
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
Build Node package:
|
|
89
|
+
extends:
|
|
90
|
+
- .base
|
|
91
|
+
|
|
92
|
+
stage: build
|
|
93
|
+
|
|
94
|
+
script:
|
|
95
|
+
- section_start publish "Publish"
|
|
96
|
+
- pnpm publish --dry-run --no-git-check --report-summary
|
|
97
|
+
- section_end publish
|
|
98
|
+
|
|
99
|
+
rules:
|
|
100
|
+
- if: "$CI_COMMIT_TAG"
|
|
101
|
+
when: never
|
|
102
|
+
- when: on_success
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
Prettier check:
|
|
106
|
+
extends:
|
|
107
|
+
- .base
|
|
108
|
+
|
|
109
|
+
stage: test
|
|
110
|
+
|
|
111
|
+
script:
|
|
112
|
+
- section_start --collapsed prettier "Prettier rewrite files"
|
|
113
|
+
- pnpm exec prettier --cache-location node_modules/.cache/prettier --write . || true
|
|
114
|
+
- section_end prettier
|
|
115
|
+
|
|
116
|
+
- if [[ -f .npmrc ]]; then git restore .npmrc; fi
|
|
117
|
+
- git diff
|
|
118
|
+
- if [ -n "$(git status --untracked-files=no --porcelain)" ]; then exit 1; fi
|
|
119
|
+
|
|
120
|
+
cache:
|
|
121
|
+
- <<: *cache
|
|
122
|
+
- key: "${CI_COMMIT_REF_SLUG}-prettier"
|
|
123
|
+
fallback_keys:
|
|
124
|
+
- "${CI_DEFAULT_BRANCH}-prettier"
|
|
125
|
+
paths:
|
|
126
|
+
- node_modules/.cache/prettier
|
|
127
|
+
unprotect: true
|
|
128
|
+
when: always
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
Type check:
|
|
132
|
+
extends:
|
|
133
|
+
- .base
|
|
134
|
+
|
|
135
|
+
stage: test
|
|
136
|
+
|
|
137
|
+
script:
|
|
138
|
+
- pnpm exec tsc
|
|
139
|
+
- pnpm exec tsc --noEmit
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
Vitest:
|
|
143
|
+
extends:
|
|
144
|
+
- .base
|
|
145
|
+
|
|
146
|
+
stage: test
|
|
147
|
+
|
|
148
|
+
script:
|
|
149
|
+
- pnpm exec vitest --reporter=verbose --reporter=junit --outputFile.junit=reports/junit.xml
|
|
150
|
+
|
|
151
|
+
coverage: "/All\\sfiles.*?\\s+(\\d+.\\d+)/"
|
|
152
|
+
|
|
153
|
+
artifacts:
|
|
154
|
+
reports:
|
|
155
|
+
coverage_report:
|
|
156
|
+
coverage_format: cobertura
|
|
157
|
+
path: reports/cobertura-coverage.xml
|
|
158
|
+
junit:
|
|
159
|
+
- reports/junit.xml
|
package/.prettierignore
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] 2026-10-13
|
|
9
|
+
|
|
10
|
+
- Initial release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Iliad78
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,167 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Stancer TypeScript library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Requirement:
|
|
4
|
+
|
|
5
|
+
[Stancer account](https://signup.stancer.com/en/sign-up)
|
|
6
|
+
|
|
7
|
+
Node: 22 or above
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
To use our SDK you will need to have API Keys.
|
|
12
|
+
|
|
13
|
+
### Live
|
|
14
|
+
|
|
15
|
+
Add your key in a secure environment.
|
|
16
|
+
set key in the configuration object:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
Configuration.setKeys({
|
|
20
|
+
privateLiveKey: process.env['API_PROD_KEY'],
|
|
21
|
+
privateTestKey: process.env['API_TEST_KEY'],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Never put your key directly in your code.
|
|
26
|
+
|
|
27
|
+
### Test
|
|
28
|
+
|
|
29
|
+
To test our sdk add your test key as an environment variable:
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
API_KEY="stest_..." npm test
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The functional test get will not pass as it is linked to specific object in the API.
|
|
36
|
+
|
|
37
|
+
## General Concept
|
|
38
|
+
|
|
39
|
+
## Repository Concept
|
|
40
|
+
|
|
41
|
+
To create, get, update, delete or list stancer object you will use Repositories.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const repository = new Repository();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Create
|
|
48
|
+
|
|
49
|
+
- Create an empty object
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const stancerObject = await repository.create();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- Create an object with populated data
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const stancerObject = await repository.create({ foo: 'foo' });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Get an object from the api
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const id = IdObject('obj_...');
|
|
65
|
+
const stancerObjectInOurAPI = await repository.create(id);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Delete
|
|
69
|
+
|
|
70
|
+
Not all the object are deletable.
|
|
71
|
+
|
|
72
|
+
- Delete an object
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const deletedObject = await repository.delete(stancerObject);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Send
|
|
79
|
+
|
|
80
|
+
Not all object are sendable.
|
|
81
|
+
|
|
82
|
+
Our SDK will call patch if we already have an ID.
|
|
83
|
+
It will call post if we don't have one (Object not yet in our API).
|
|
84
|
+
|
|
85
|
+
- patch
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const patchObject = await repository.send(stancerObjectInOurAPI);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- post
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const postObject = await repository.send(stancerObjectNotInOurAPI);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
You cannot send object if you have not modified it. It will result in an error.
|
|
98
|
+
|
|
99
|
+
### List
|
|
100
|
+
|
|
101
|
+
List the object in our API.
|
|
102
|
+
|
|
103
|
+
This will return a generator.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const objectList = await repository.list();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Model Concept
|
|
110
|
+
|
|
111
|
+
You will manipulate models to get data on a specific object and modify their data.
|
|
112
|
+
|
|
113
|
+
Getter and setters are set in a way that let you easily access data that can be modified and data that can be read.
|
|
114
|
+
|
|
115
|
+
All the data modifiable are not necessarily readable.
|
|
116
|
+
All the data readable are not necessarily modifiable.
|
|
117
|
+
|
|
118
|
+
### Example
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const cardRepository = new CardRepository();
|
|
122
|
+
const card = await cardRepository.create();
|
|
123
|
+
// you can set Number and CVC
|
|
124
|
+
card.setNumber('4242424242424242').setCvc('123');
|
|
125
|
+
// But you cannot get Number and cvc
|
|
126
|
+
|
|
127
|
+
// you can get last4
|
|
128
|
+
card.last4;
|
|
129
|
+
// but you cannot set last4
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Create and process a Payment Intent
|
|
133
|
+
|
|
134
|
+
While you can process payment with a payment route we encourage you to use the payment intent route as it facilitate the handling of failed payments (retry).
|
|
135
|
+
|
|
136
|
+
You have two choice when you process Payment Intent either capture it automatically or capture it manually.
|
|
137
|
+
|
|
138
|
+
### Automatic capture
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
//amount and currency come from your context
|
|
142
|
+
const paymentIntentRepository = new PaymentIntentRepository();
|
|
143
|
+
const paymentIntent = new paymentIntentRepository.create({ amount, currency });
|
|
144
|
+
paymentIntentRepository.send(paymentIntent);
|
|
145
|
+
const paymentPageUrl = paymentIntent.url; //embed or redirect to this url to process the payment
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Manual capture
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
//amount and currency come from your context
|
|
152
|
+
const paymentIntentRepository = new PaymentIntentRepository();
|
|
153
|
+
const returnUrl = 'mySite.example.com/handlePayments';
|
|
154
|
+
const paymentIntent = paymentIntentRepository.create({ amount, currency, capture: false, returnUrl });
|
|
155
|
+
paymentIntentRepository.send(paymentIntent);
|
|
156
|
+
const paymentPageUrl = paymentIntent.url; //embed or redirect to this url to process the payment
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Then when the payment is process in the payment page the client will be redirect to `returnUrl` from here:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
// Id come from the payload of the returnUrl
|
|
163
|
+
const paymentIntentRepository = new PaymentIntentRepository();
|
|
164
|
+
const paymentIntent = paymentIntentRepository.create(id);
|
|
165
|
+
// Here you can include business logic like update the order etc...
|
|
166
|
+
paymentIntentRepository.capture(paymentIntent);
|
|
167
|
+
```
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import { defineConfig } from 'eslint/config';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
import tseslint from 'typescript-eslint';
|
|
5
|
+
|
|
6
|
+
export default defineConfig([
|
|
7
|
+
{
|
|
8
|
+
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
|
9
|
+
plugins: { js },
|
|
10
|
+
extends: ['js/recommended'],
|
|
11
|
+
languageOptions: { globals: globals.node },
|
|
12
|
+
},
|
|
13
|
+
tseslint.configs.recommended,
|
|
14
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stancer/stancer",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"temporal-polyfill": "^1.0.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@eslint/js": "^10.0.0",
|
|
14
|
+
"@stancer/prettier": "^3.0.0",
|
|
15
|
+
"@types/node": "^22.0.0",
|
|
16
|
+
"@typescript/native": "npm:typescript@^7.0.0",
|
|
17
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
18
|
+
"eslint": "^10.0.0",
|
|
19
|
+
"eslint-formatter-junit": "^9.0.0",
|
|
20
|
+
"globals": "^17.0.0",
|
|
21
|
+
"libphonenumber-js": "^1.13.10",
|
|
22
|
+
"prettier": "^3.0.0",
|
|
23
|
+
"typescript": "npm:@typescript/typescript6@^6.0.0",
|
|
24
|
+
"typescript-eslint": "^8.0.0",
|
|
25
|
+
"vitest": "^4.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devEngines": {
|
|
28
|
+
"packageManager": {
|
|
29
|
+
"name": "pnpm",
|
|
30
|
+
"version": "^11.0.0",
|
|
31
|
+
"onFail": "download"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"imports": {
|
|
35
|
+
"#api/*": "./src/api-endpoint/*",
|
|
36
|
+
"#address/*": "./src/address/*",
|
|
37
|
+
"#core/*": "./src/core/*",
|
|
38
|
+
"#error/*": "./src/core/error/*",
|
|
39
|
+
"#test/*": "./test/*",
|
|
40
|
+
"#card/*": "./src/card/*",
|
|
41
|
+
"#sepa/*": "./src/sepa/*",
|
|
42
|
+
"#customer/*": "./src/customer/*",
|
|
43
|
+
"#payment/*": "./src/payment/*",
|
|
44
|
+
"#refund/*": "./src/refund/*",
|
|
45
|
+
"#payment-intent/*": "./src/payment-intent/*"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"clean": "rm -rf dist/ node_modules/",
|
|
50
|
+
"format": "prettier --write ./src ./test",
|
|
51
|
+
"fresh": "pnpm run clean && pnpm install && pnpm run build",
|
|
52
|
+
"test": " DEBUG=true vitest",
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
54
|
+
}
|
|
6
55
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
catalogs:
|
|
2
|
+
eslint:
|
|
3
|
+
"@eslint/js": ^10.0.0
|
|
4
|
+
eslint: ^10.0.0
|
|
5
|
+
eslint-formatter-junit: ^9.0.0
|
|
6
|
+
globals: ^17.0.0
|
|
7
|
+
typescript-eslint: ^8.0.0
|
|
8
|
+
|
|
9
|
+
prettier:
|
|
10
|
+
"@stancer/prettier": ^3.0.0
|
|
11
|
+
prettier: ^3.0.0
|
|
12
|
+
|
|
13
|
+
vitest:
|
|
14
|
+
"@vitest/coverage-v8": ^4.0.0
|
|
15
|
+
vitest: ^4.0.0
|
|
16
|
+
|
|
17
|
+
lockfileIncludeTarballUrl: true
|
|
18
|
+
|
|
19
|
+
minimumReleaseAge: 10080 # 7days
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ApiEndpoint, baseHandler } from '#api/abstract-api-endpoint.js';
|
|
2
|
+
import { defaultHandler } from '#core/common/handler/handler.js';
|
|
3
|
+
import { IdHandler } from '#core/common/handler/id-handler.js';
|
|
4
|
+
|
|
5
|
+
import { type AddressData, AddressModel, type IdAddress } from './model.js';
|
|
6
|
+
|
|
7
|
+
export class AddressApiEndpoint extends ApiEndpoint<AddressData> {
|
|
8
|
+
protected override _handler = {
|
|
9
|
+
...baseHandler('created_at'),
|
|
10
|
+
id: IdHandler<IdAddress>(AddressModel.regex),
|
|
11
|
+
city: defaultHandler<AddressData['city']>('string', { postRequired: true }),
|
|
12
|
+
country: defaultHandler<AddressData['country']>('string', { postRequired: true }),
|
|
13
|
+
line1: defaultHandler<AddressData['line1']>('string'),
|
|
14
|
+
line2: defaultHandler<AddressData['line2']>('string'),
|
|
15
|
+
line3: defaultHandler<AddressData['line3']>('string'),
|
|
16
|
+
metadata: defaultHandler<AddressData['metadata']>('string'),
|
|
17
|
+
state: defaultHandler<AddressData['state']>('string'),
|
|
18
|
+
zipCode: defaultHandler<AddressData['zipCode']>('string', { postRequired: true }),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
super({
|
|
23
|
+
name: 'addresses',
|
|
24
|
+
patchable: false,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
endpointUrl(id?: IdAddress) {
|
|
28
|
+
return this._getResourceUri(id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { AbstractModel, type ModelType } from '#core/abstract-model.js';
|
|
2
|
+
import type { IdValue } from '#core/common/branded-type.js';
|
|
3
|
+
import { validateID } from '#core/common/id-validator.js';
|
|
4
|
+
|
|
5
|
+
export type IdAddress = IdValue<`addr_${string}`>;
|
|
6
|
+
export const idAddress = (id: string) => validateID<IdAddress>(id, AddressModel.regex);
|
|
7
|
+
|
|
8
|
+
export interface AddressData extends ModelType {
|
|
9
|
+
city: string;
|
|
10
|
+
country: string;
|
|
11
|
+
id: IdAddress;
|
|
12
|
+
line1: string;
|
|
13
|
+
line2: string;
|
|
14
|
+
line3: string;
|
|
15
|
+
metadata: string;
|
|
16
|
+
state: string;
|
|
17
|
+
zipCode: string;
|
|
18
|
+
}
|
|
19
|
+
export class AddressModel extends AbstractModel<AddressData> {
|
|
20
|
+
static regex = /^addr_[a-zA-Z0-9]{24}$/;
|
|
21
|
+
|
|
22
|
+
get city() {
|
|
23
|
+
return this._data.city;
|
|
24
|
+
}
|
|
25
|
+
get country() {
|
|
26
|
+
return this._data.country;
|
|
27
|
+
}
|
|
28
|
+
get line1() {
|
|
29
|
+
return this._data.line1;
|
|
30
|
+
}
|
|
31
|
+
get line2() {
|
|
32
|
+
return this._data.line2;
|
|
33
|
+
}
|
|
34
|
+
get line3() {
|
|
35
|
+
return this._data.line3;
|
|
36
|
+
}
|
|
37
|
+
get metadata() {
|
|
38
|
+
return this._data.metadata;
|
|
39
|
+
}
|
|
40
|
+
get state() {
|
|
41
|
+
return this._data.state;
|
|
42
|
+
}
|
|
43
|
+
get zipCode() {
|
|
44
|
+
return this._data.zipCode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setCity(value: string) {
|
|
48
|
+
this._data['city'] = value;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
setCountry(value: string) {
|
|
52
|
+
this._data['country'] = value;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
setLine1(value: string) {
|
|
56
|
+
this._data['line1'] = value;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
setLine2(value: string) {
|
|
60
|
+
this._data['line2'] = value;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
setLine3(value: string) {
|
|
64
|
+
this._data['line3'] = value;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
setMetadata(value: string) {
|
|
68
|
+
this._data['metadata'] = value;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
setState(value: string) {
|
|
72
|
+
this._data['state'] = value;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
setZipCode(value: string) {
|
|
76
|
+
this._data['zipCode'] = value;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AddressApiEndpoint } from '#address/api-endpoint.js';
|
|
2
|
+
import { type AddressData, AddressModel } from '#address/model.js';
|
|
3
|
+
import { addressValidator } from '#address/validator.js';
|
|
4
|
+
import { AbstractRepository, type Repository } from '#core/abstract-repository.js';
|
|
5
|
+
import type { EndpointInterface } from '#core/endpoint-interface.js';
|
|
6
|
+
|
|
7
|
+
export class AddressRepository
|
|
8
|
+
extends AbstractRepository<AddressData, AddressModel>
|
|
9
|
+
implements Repository<AddressData, AddressModel>
|
|
10
|
+
{
|
|
11
|
+
constructor(endpoint?: EndpointInterface<AddressData>) {
|
|
12
|
+
super({
|
|
13
|
+
endpoint: endpoint ?? new AddressApiEndpoint(),
|
|
14
|
+
validator: addressValidator,
|
|
15
|
+
model: AddressModel,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type AddressData, AddressModel } from '#address/model.js';
|
|
2
|
+
import { IdValidator } from '#core/common/id-validator.js';
|
|
3
|
+
import { type Validator, createdAtValidator, goldilocksValidator } from '#core/validator.js';
|
|
4
|
+
|
|
5
|
+
const cityMaxLength = 50;
|
|
6
|
+
const cityMinLength = 1;
|
|
7
|
+
const countryLength = 2;
|
|
8
|
+
const lineMaxLength = 50;
|
|
9
|
+
const lineMinLength = 1;
|
|
10
|
+
const stateMaxLength = 3;
|
|
11
|
+
const stateMinLength = 1;
|
|
12
|
+
const zipCodeMaxLength = 16;
|
|
13
|
+
const zipCodeMinLength = 2;
|
|
14
|
+
|
|
15
|
+
const lineValidator = (lineName: string) => {
|
|
16
|
+
return goldilocksValidator(lineName, { max: lineMaxLength, min: lineMinLength });
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const addressValidator: Validator<AddressData> = {
|
|
20
|
+
id: IdValidator(AddressModel.regex),
|
|
21
|
+
city: goldilocksValidator('city', { min: cityMinLength, max: cityMaxLength }),
|
|
22
|
+
// country check for ISO 3166-1 alpha-2 country codes, because API wait for this precise type.
|
|
23
|
+
country: goldilocksValidator('country', { size: countryLength }),
|
|
24
|
+
createdAt: createdAtValidator,
|
|
25
|
+
// Deleted is a system-managed field for soft deletes, not validated on client side.
|
|
26
|
+
deleted: true,
|
|
27
|
+
line1: lineValidator('line1'),
|
|
28
|
+
line2: lineValidator('line2'),
|
|
29
|
+
line3: lineValidator('line3'),
|
|
30
|
+
// Metadata doesn't have strict set value, so we don't validate it, we let the API reject it.
|
|
31
|
+
metadata: true,
|
|
32
|
+
state: goldilocksValidator('state', { max: stateMaxLength, min: stateMinLength }),
|
|
33
|
+
zipCode: goldilocksValidator('zipCode', { min: zipCodeMinLength, max: zipCodeMaxLength }),
|
|
34
|
+
};
|