@antelopejs/mollie 0.0.0-stage → 0.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/LICENSE +190 -0
- package/README.md +123 -2
- package/dist/accounts.d.ts +17 -0
- package/dist/accounts.js +41 -0
- package/dist/accounts.js.map +1 -0
- package/dist/implementations/payment/checkout.d.ts +3 -0
- package/dist/implementations/payment/checkout.js +129 -0
- package/dist/implementations/payment/checkout.js.map +1 -0
- package/dist/implementations/payment/customers.d.ts +6 -0
- package/dist/implementations/payment/customers.js +79 -0
- package/dist/implementations/payment/customers.js.map +1 -0
- package/dist/implementations/payment/errors.d.ts +10 -0
- package/dist/implementations/payment/errors.js +71 -0
- package/dist/implementations/payment/errors.js.map +1 -0
- package/dist/implementations/payment/index.d.ts +5 -0
- package/dist/implementations/payment/index.js +27 -0
- package/dist/implementations/payment/index.js.map +1 -0
- package/dist/implementations/payment/instruments.d.ts +19 -0
- package/dist/implementations/payment/instruments.js +138 -0
- package/dist/implementations/payment/instruments.js.map +1 -0
- package/dist/implementations/payment/mapping.d.ts +10 -0
- package/dist/implementations/payment/mapping.js +202 -0
- package/dist/implementations/payment/mapping.js.map +1 -0
- package/dist/implementations/payment/payments.d.ts +12 -0
- package/dist/implementations/payment/payments.js +270 -0
- package/dist/implementations/payment/payments.js.map +1 -0
- package/dist/implementations/payment/refunds.d.ts +3 -0
- package/dist/implementations/payment/refunds.js +76 -0
- package/dist/implementations/payment/refunds.js.map +1 -0
- package/dist/implementations/payment/saved-method.d.ts +5 -0
- package/dist/implementations/payment/saved-method.js +83 -0
- package/dist/implementations/payment/saved-method.js.map +1 -0
- package/dist/implementations/payment/webhooks.d.ts +2 -0
- package/dist/implementations/payment/webhooks.js +72 -0
- package/dist/implementations/payment/webhooks.js.map +1 -0
- package/dist/implementations/shared/subscription-of-payment.d.ts +7 -0
- package/dist/implementations/shared/subscription-of-payment.js +47 -0
- package/dist/implementations/shared/subscription-of-payment.js.map +1 -0
- package/dist/implementations/subscriptions/calendar.d.ts +20 -0
- package/dist/implementations/subscriptions/calendar.js +160 -0
- package/dist/implementations/subscriptions/calendar.js.map +1 -0
- package/dist/implementations/subscriptions/changes.d.ts +5 -0
- package/dist/implementations/subscriptions/changes.js +140 -0
- package/dist/implementations/subscriptions/changes.js.map +1 -0
- package/dist/implementations/subscriptions/creation.d.ts +4 -0
- package/dist/implementations/subscriptions/creation.js +235 -0
- package/dist/implementations/subscriptions/creation.js.map +1 -0
- package/dist/implementations/subscriptions/errors.d.ts +7 -0
- package/dist/implementations/subscriptions/errors.js +42 -0
- package/dist/implementations/subscriptions/errors.js.map +1 -0
- package/dist/implementations/subscriptions/events.d.ts +9 -0
- package/dist/implementations/subscriptions/events.js +74 -0
- package/dist/implementations/subscriptions/events.js.map +1 -0
- package/dist/implementations/subscriptions/index.d.ts +7 -0
- package/dist/implementations/subscriptions/index.js +26 -0
- package/dist/implementations/subscriptions/index.js.map +1 -0
- package/dist/implementations/subscriptions/mapping.d.ts +3 -0
- package/dist/implementations/subscriptions/mapping.js +133 -0
- package/dist/implementations/subscriptions/mapping.js.map +1 -0
- package/dist/implementations/subscriptions/records.d.ts +40 -0
- package/dist/implementations/subscriptions/records.js +225 -0
- package/dist/implementations/subscriptions/records.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/mollie/amounts.d.ts +5 -0
- package/dist/mollie/amounts.js +85 -0
- package/dist/mollie/amounts.js.map +1 -0
- package/dist/mollie/client.d.ts +26 -0
- package/dist/mollie/client.js +136 -0
- package/dist/mollie/client.js.map +1 -0
- package/dist/mollie/errors.d.ts +16 -0
- package/dist/mollie/errors.js +35 -0
- package/dist/mollie/errors.js.map +1 -0
- package/dist/mollie/fields.d.ts +6 -0
- package/dist/mollie/fields.js +25 -0
- package/dist/mollie/fields.js.map +1 -0
- package/dist/mollie/guards.d.ts +16 -0
- package/dist/mollie/guards.js +63 -0
- package/dist/mollie/guards.js.map +1 -0
- package/dist/mollie/ids.d.ts +20 -0
- package/dist/mollie/ids.js +51 -0
- package/dist/mollie/ids.js.map +1 -0
- package/dist/mollie/json.d.ts +3 -0
- package/dist/mollie/json.js +31 -0
- package/dist/mollie/json.js.map +1 -0
- package/dist/mollie/metadata.d.ts +21 -0
- package/dist/mollie/metadata.js +121 -0
- package/dist/mollie/metadata.js.map +1 -0
- package/dist/mollie/resources.d.ts +13 -0
- package/dist/mollie/resources.js +132 -0
- package/dist/mollie/resources.js.map +1 -0
- package/dist/mollie/types.d.ts +119 -0
- package/dist/mollie/types.js +3 -0
- package/dist/mollie/types.js.map +1 -0
- package/docs/1.introduction.md +52 -0
- package/docs/2.payments.md +160 -0
- package/docs/3.webhooks.md +55 -0
- package/docs/4.subscriptions.md +109 -0
- package/docs/5.testing.md +67 -0
- package/package.json +86 -4
- package/skills/mollie/SKILL.md +55 -0
- package/skills/mollie/cases.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright (c) 2025-present - AntelopeJS Team
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@antelopejs/mollie`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@antelopejs/mollie"><img data-illustration alt="NPM version" src="https://img.shields.io/npm/v/@antelopejs/mollie.svg?style=for-the-badge&labelColor=000000"></a>
|
|
5
|
+
<a href="./LICENSE"><img data-illustration alt="License" src="https://img.shields.io/npm/l/@antelopejs/mollie.svg?style=for-the-badge&labelColor=000000"></a>
|
|
6
|
+
<a href="https://discord.gg/sjK28QHrA7"><img data-illustration src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
A Mollie payment module for AntelopeJS. It implements the payment interface, and it implements the subscriptions interface on Mollie's own subscriptions.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
ajs project modules add @antelopejs/mollie
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Interfaces
|
|
18
|
+
|
|
19
|
+
This module implements two interfaces. You import each one separately, so a module that takes payments does not depend on subscriptions.
|
|
20
|
+
|
|
21
|
+
| Name | Install command | |
|
|
22
|
+
| ------------- | -------------------------------------- | ---------------------------------------------------------------------- |
|
|
23
|
+
| Payment | `ajs module imports add payment` | [Documentation](https://github.com/AntelopeJS/interface-payment) |
|
|
24
|
+
| Subscriptions | `ajs module imports add subscriptions` | [Documentation](https://github.com/AntelopeJS/interface-subscriptions) |
|
|
25
|
+
|
|
26
|
+
It needs no other module. It uses no Redis, no database and no API module.
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"apiKey": "test_…",
|
|
33
|
+
"webhookUrl": "https://shop.example.org/payments/mollie"
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- `apiKey` (required) is a Mollie API key. A `test_…` key works against Mollie's test mode.
|
|
38
|
+
- `webhookUrl` is the public URL of your route that passes Mollie's deliveries to `VerifyWebhook`. The module sends it with every payment and subscription it creates. Without it, Mollie calls nothing, so the module raises no payment event and reports no subscription renewal. Mollie refuses a `localhost` URL.
|
|
39
|
+
- `accounts` holds further Mollie accounts, each with its own `apiKey` and `webhookUrl`. The key of each entry is the name that callers pass as the trailing `provider` argument of an interface function. The top-level account is the default.
|
|
40
|
+
- `apiUrl` is the base URL of the Mollie API. It defaults to `https://api.mollie.com`. The test suite points it at a local stand-in.
|
|
41
|
+
- `settleTimeoutMs` is how long `CapturePayment` waits for Mollie to apply a capture, in every account. It defaults to 10 seconds. `0` returns as soon as Mollie accepts the capture. Any value but a finite number, 0 or more, makes the module refuse to start.
|
|
42
|
+
|
|
43
|
+
The module uses API keys only. It does not support Mollie Connect or OAuth.
|
|
44
|
+
|
|
45
|
+
## Webhooks
|
|
46
|
+
|
|
47
|
+
For payments, Mollie recommends its classic webhooks. A classic delivery posts `id=tr_…` and nothing else, and Mollie does not sign it. `VerifyWebhook` reads that payment back from Mollie, and every field of the event comes from that read. A delivery that names no payment, or names a payment that Mollie does not have on the account, rejects with `WebhookVerificationError`. When Mollie cannot be reached, `VerifyWebhook` rejects with a plain `PaymentError`, so your route answers with an error and Mollie delivers again.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { createServer } from "node:http";
|
|
51
|
+
import { buffer } from "node:stream/consumers";
|
|
52
|
+
import {
|
|
53
|
+
type PaymentEvent,
|
|
54
|
+
VerifyWebhook,
|
|
55
|
+
WebhookVerificationError,
|
|
56
|
+
} from "@antelopejs/interface-payment";
|
|
57
|
+
|
|
58
|
+
async function handle(event: PaymentEvent): Promise<void> {
|
|
59
|
+
console.log(`${event.type} ${event.id}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Serve this at `webhookUrl`.
|
|
63
|
+
createServer(async (request, response) => {
|
|
64
|
+
try {
|
|
65
|
+
const event = await VerifyWebhook({
|
|
66
|
+
body: await buffer(request),
|
|
67
|
+
headers: request.headers,
|
|
68
|
+
});
|
|
69
|
+
if (event) await handle(event); // undefined: a genuine delivery with nothing to report
|
|
70
|
+
response.writeHead(200).end();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
response
|
|
73
|
+
.writeHead(error instanceof WebhookVerificationError ? 403 : 500)
|
|
74
|
+
.end();
|
|
75
|
+
}
|
|
76
|
+
}).listen(8080);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`VerifyWebhook` takes the unparsed body, so the route reads it raw. The route answers 403 only for a delivery that `VerifyWebhook` could not establish as genuine. Any other failure answers 500, and Mollie delivers again.
|
|
80
|
+
|
|
81
|
+
The module raises only `payment.*` events. A classic delivery names a payment, never the refund or chargeback that caused it, so **the module never raises `refund.succeeded`, `refund.failed` or `dispute.opened`**. Read a refund back with `GetRefund`, and a payment's refunded total with `GetPayment`. [Webhooks](./docs/3.webhooks.md) explains why.
|
|
82
|
+
|
|
83
|
+
## What differs from other providers
|
|
84
|
+
|
|
85
|
+
- **Every payer-present payment is a redirect.** `CreatePayment` and `CreateCheckoutSession` return `requires_action` with Mollie's checkout URL. A checkout session and its payment share one identifier.
|
|
86
|
+
- **Saved methods are Mollie mandates.** A payment with `savePaymentMethod` creates one, as Mollie's `first` payment. A saved card is listed once its payment reads `succeeded`: the module waits up to 5 seconds for Mollie to turn the mandate valid. A saved method belongs to one customer. Detaching it revokes the mandate, and Mollie then cancels every subscription that charges it.
|
|
87
|
+
- **Off-session charges settle later.** A charge against a saved method comes back `pending`. Mollie reports `succeeded`, `authorized` or `failed` afterwards, through the webhook. A decline is then a `failed` payment, not the result of the creating call.
|
|
88
|
+
- **Holding funds works only for some methods.** `authorizeOnly` needs a method that Mollie can capture by hand: cards, Klarna, Billie, Riverty, Vipps, MobilePay, PayPal and Billink. The module refuses any other method instead of letting Mollie capture at once, and a hosted page offers only those methods.
|
|
89
|
+
- **Captures settle after the call.** Mollie accepts a capture as `pending` and applies it about a second later. `CapturePayment` waits for that up to `settleTimeoutMs`. If Mollie has not applied the capture by then, `CapturePayment` returns the payment `pending`, with `amountCaptured` set to the amount being captured. A failed read while it waits returns `pending` the same way. A capture Mollie fails rejects with a `PaymentError` whose `providerCode` is `capture_failed`. A second capture of the same payment, or a cancellation, while the first capture is in flight or applied rejects with `InvalidPaymentStateError` before it reaches Mollie.
|
|
90
|
+
- **Idempotency keys last one hour at Mollie.** `RefundPayment`, `CapturePayment` and `CreateSubscription` find their earlier result by key at any time. For other calls, a replay within the hour returns the original result. After the hour, Mollie treats the same key as a new request.
|
|
91
|
+
- **No `refund.*` or `dispute.opened` events.** See [Webhooks](#webhooks).
|
|
92
|
+
|
|
93
|
+
## Subscriptions
|
|
94
|
+
|
|
95
|
+
Subscriptions are Mollie's own. Mollie holds the schedule and creates every renewal payment. [Subscriptions](./docs/4.subscriptions.md) has the full mapping. In short:
|
|
96
|
+
|
|
97
|
+
- **`CreateSubscription` charges the first period.** It charges a payment whose metadata names the subscription under `antelope.subscription`, and Mollie's own schedule starts one period later. Mollie reports a declined charge after the call returns, so the subscription is created `active` and goes `past_due` if that charge fails. Nothing retries that first charge.
|
|
98
|
+
- **Mollie schedules by calendar date.** The module rounds a trial end or a billing anchor up to the start of the next day in Europe/Amsterdam, and reports that time. A period runs from one such midnight to the next.
|
|
99
|
+
- **Mollie owns the retries.** Mollie retries a failed renewal up to five times, then cancels the subscription. The module reports it `canceled` with `endReason: "payment_failed"`.
|
|
100
|
+
- **Cancelling at period end stops Mollie at once.** The module reports the subscription as running until the end of the period it paid for. Mollie raises nothing when that period ends, so neither does this module.
|
|
101
|
+
- **Events.** The call that causes `subscription.created` or `subscription.canceled` raises it. A handler that throws makes that call reject, and replaying the call's idempotency key raises the event again. The payment webhook raises `subscription.payment_succeeded` and `subscription.payment_failed`.
|
|
102
|
+
- **About 600 bytes of subscription metadata.** Mollie keeps 1,024 bytes of metadata per subscription, and the module keeps room in them to record the first charge and a cancellation. `CreateSubscription` rejects metadata that would leave no such room with `InvalidSubscriptionRequestError`. With a reference and an idempotency key of up to 64 bytes each as JSON text, where a character JSON escapes, such as `"` or `\`, counts as its escape, 600 bytes of metadata as JSON always fit.
|
|
103
|
+
- **Only this module's subscriptions.** The module does not list, read, change or raise events for subscriptions made in the dashboard or by other code on the account, and it does not mark their charges.
|
|
104
|
+
- **Replay a failed creation with its idempotency key.** The subscription may already exist at Mollie, and Mollie will charge it from the next period. Replay once the call has failed, not while it runs: a replay that overlaps it can cancel the subscription it returns if the first charge fails in between.
|
|
105
|
+
|
|
106
|
+
## Prefer the generic fallback?
|
|
107
|
+
|
|
108
|
+
Wire `@antelopejs/payment-subscriptions`, and add `disabledExports: ["@antelopejs/interface-subscriptions"]` to this module's entry.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
|
|
113
|
+
|
|
114
|
+
## Compatibility
|
|
115
|
+
|
|
116
|
+
<!-- antelopejs-docs-compat:start -->
|
|
117
|
+
|
|
118
|
+
| Package | Supported | Tested with |
|
|
119
|
+
| ------------------------------------- | ---------------- | ----------- |
|
|
120
|
+
| `@antelopejs/interface-core` | `>=0.0.5 <1.0.0` | `0.4.0` |
|
|
121
|
+
| `@antelopejs/interface-payment` | `>=0.2.0 <0.3.0` | `0.2.0` |
|
|
122
|
+
| `@antelopejs/interface-subscriptions` | `>=0.1.0 <0.2.0` | `0.1.0` |
|
|
123
|
+
|
|
124
|
+
<!-- antelopejs-docs-compat:end -->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MollieClient } from "./mollie/client";
|
|
2
|
+
export interface AccountConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
webhookUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Account {
|
|
7
|
+
client: MollieClient;
|
|
8
|
+
webhookUrl?: string;
|
|
9
|
+
settleTimeoutMs: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SharedSettings {
|
|
12
|
+
apiUrl?: string;
|
|
13
|
+
settleTimeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function RegisterAccount(name: string | undefined, config: AccountConfig, shared: SharedSettings): void;
|
|
16
|
+
export declare function ClearAccounts(): void;
|
|
17
|
+
export declare function GetAccount(provider?: string): Account;
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegisterAccount = RegisterAccount;
|
|
4
|
+
exports.ClearAccounts = ClearAccounts;
|
|
5
|
+
exports.GetAccount = GetAccount;
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
7
|
+
const interface_payment_1 = require("@antelopejs/interface-payment");
|
|
8
|
+
const client_1 = require("./mollie/client");
|
|
9
|
+
const fields_1 = require("./mollie/fields");
|
|
10
|
+
const accounts = new Map();
|
|
11
|
+
const DEFAULT_ACCOUNT = "";
|
|
12
|
+
const DEFAULT_SETTLE_TIMEOUT_MS = 10_000;
|
|
13
|
+
const LONGEST_TIMER_MS = 2_147_483_647;
|
|
14
|
+
function settleTimeoutMs(value) {
|
|
15
|
+
if (value === undefined)
|
|
16
|
+
return DEFAULT_SETTLE_TIMEOUT_MS;
|
|
17
|
+
if (!Number.isInteger(value) || value < 0 || value > LONGEST_TIMER_MS) {
|
|
18
|
+
throw new RangeError(`settleTimeoutMs must be a whole number of milliseconds from 0 to ${LONGEST_TIMER_MS}, not ${(0, node_util_1.inspect)(value)}`);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function RegisterAccount(name, config, shared) {
|
|
23
|
+
accounts.set(name ?? DEFAULT_ACCOUNT, {
|
|
24
|
+
client: new client_1.MollieClient({ apiKey: config.apiKey, apiUrl: shared.apiUrl }),
|
|
25
|
+
settleTimeoutMs: settleTimeoutMs(shared.settleTimeoutMs),
|
|
26
|
+
...(0, fields_1.DefinedFields)({ webhookUrl: config.webhookUrl || undefined }),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function ClearAccounts() {
|
|
30
|
+
accounts.clear();
|
|
31
|
+
}
|
|
32
|
+
function GetAccount(provider) {
|
|
33
|
+
const account = accounts.get(provider ?? DEFAULT_ACCOUNT);
|
|
34
|
+
if (!account) {
|
|
35
|
+
throw new interface_payment_1.PaymentError(provider
|
|
36
|
+
? `No Mollie account configured under "${provider}"`
|
|
37
|
+
: "The Mollie module has no default account configured");
|
|
38
|
+
}
|
|
39
|
+
return account;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":";;AAmDA,0CAUC;AAED,sCAEC;AAED,gCAUC;AA7ED,yCAAoC;AACpC,qEAA6D;AAE7D,4CAA+C;AAC/C,4CAAgD;AA0Bh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CAAC,CAAC,qDAAqD,CAC1D,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type CheckoutSession, type CheckoutSessionRequest } from "@antelopejs/interface-payment";
|
|
2
|
+
export declare function CreateCheckoutSession(request: CheckoutSessionRequest, idempotencyKey: string, provider?: string): Promise<CheckoutSession>;
|
|
3
|
+
export declare function GetCheckoutSession(id: string, provider?: string): Promise<CheckoutSession>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateCheckoutSession = CreateCheckoutSession;
|
|
4
|
+
exports.GetCheckoutSession = GetCheckoutSession;
|
|
5
|
+
const resources_1 = require("../../mollie/resources");
|
|
6
|
+
const interface_payment_1 = require("@antelopejs/interface-payment");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const payments_1 = require("./payments");
|
|
9
|
+
const accounts_1 = require("../../accounts");
|
|
10
|
+
const fields_1 = require("../../mollie/fields");
|
|
11
|
+
const amounts_1 = require("../../mollie/amounts");
|
|
12
|
+
const metadata_1 = require("../../mollie/metadata");
|
|
13
|
+
const instruments_1 = require("./instruments");
|
|
14
|
+
const mapping_1 = require("./mapping");
|
|
15
|
+
const SESSION_ENTITY = "checkout session";
|
|
16
|
+
const MOLLIE_LOCALES = new Set([
|
|
17
|
+
"ca_ES",
|
|
18
|
+
"cs_CZ",
|
|
19
|
+
"da_DK",
|
|
20
|
+
"de_AT",
|
|
21
|
+
"de_CH",
|
|
22
|
+
"de_DE",
|
|
23
|
+
"de_LU",
|
|
24
|
+
"el_GR",
|
|
25
|
+
"en_BE",
|
|
26
|
+
"en_GB",
|
|
27
|
+
"en_NL",
|
|
28
|
+
"en_US",
|
|
29
|
+
"es_ES",
|
|
30
|
+
"fi_FI",
|
|
31
|
+
"fr_BE",
|
|
32
|
+
"fr_FR",
|
|
33
|
+
"fr_LU",
|
|
34
|
+
"hu_HU",
|
|
35
|
+
"is_IS",
|
|
36
|
+
"it_IT",
|
|
37
|
+
"lt_LT",
|
|
38
|
+
"lv_LV",
|
|
39
|
+
"nb_NO",
|
|
40
|
+
"nl_BE",
|
|
41
|
+
"nl_NL",
|
|
42
|
+
"pl_PL",
|
|
43
|
+
"pt_PT",
|
|
44
|
+
"sk_SK",
|
|
45
|
+
"sl_SI",
|
|
46
|
+
"sv_SE",
|
|
47
|
+
"tr_TR",
|
|
48
|
+
]);
|
|
49
|
+
const MOLLIE_LOCALE_BY_LANGUAGE = {
|
|
50
|
+
cs: "cs_CZ",
|
|
51
|
+
da: "da_DK",
|
|
52
|
+
de: "de_DE",
|
|
53
|
+
el: "el_GR",
|
|
54
|
+
en: "en_US",
|
|
55
|
+
es: "es_ES",
|
|
56
|
+
fi: "fi_FI",
|
|
57
|
+
fr: "fr_FR",
|
|
58
|
+
hu: "hu_HU",
|
|
59
|
+
it: "it_IT",
|
|
60
|
+
lt: "lt_LT",
|
|
61
|
+
lv: "lv_LV",
|
|
62
|
+
nb: "nb_NO",
|
|
63
|
+
nl: "nl_NL",
|
|
64
|
+
pl: "pl_PL",
|
|
65
|
+
pt: "pt_PT",
|
|
66
|
+
sk: "sk_SK",
|
|
67
|
+
sl: "sl_SI",
|
|
68
|
+
sv: "sv_SE",
|
|
69
|
+
tr: "tr_TR",
|
|
70
|
+
};
|
|
71
|
+
function toMollieLocale(locale) {
|
|
72
|
+
if (!locale)
|
|
73
|
+
return undefined;
|
|
74
|
+
const candidate = locale.replace("-", "_");
|
|
75
|
+
if (MOLLIE_LOCALES.has(candidate))
|
|
76
|
+
return candidate;
|
|
77
|
+
return (0, fields_1.Lookup)(MOLLIE_LOCALE_BY_LANGUAGE, locale.split("-")[0]);
|
|
78
|
+
}
|
|
79
|
+
function toSession(payment) {
|
|
80
|
+
const redirectUrl = (0, mapping_1.CheckoutUrl)(payment);
|
|
81
|
+
return {
|
|
82
|
+
id: payment.id,
|
|
83
|
+
redirectUrl: redirectUrl ?? "",
|
|
84
|
+
status: (0, mapping_1.ToPaymentStatus)(payment),
|
|
85
|
+
payment: payment.id,
|
|
86
|
+
...(0, fields_1.DefinedFields)({
|
|
87
|
+
expiresAt: payment.expiresAt
|
|
88
|
+
? (0, mapping_1.ToEpochMillis)(payment.expiresAt)
|
|
89
|
+
: undefined,
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function sessionBody(request) {
|
|
94
|
+
const locale = toMollieLocale(request.locale);
|
|
95
|
+
return {
|
|
96
|
+
amount: (0, amounts_1.ToMollieAmount)(request.amount),
|
|
97
|
+
description: request.description ?? request.reference,
|
|
98
|
+
redirectUrl: request.successUrl,
|
|
99
|
+
cancelUrl: request.cancelUrl,
|
|
100
|
+
sequenceType: request.savePaymentMethod ? "first" : "oneoff",
|
|
101
|
+
metadata: (0, metadata_1.WriteMetadata)({ reference: request.reference }, request.metadata),
|
|
102
|
+
...(0, fields_1.DefinedFields)({
|
|
103
|
+
customerId: request.customer,
|
|
104
|
+
captureMode: request.authorizeOnly ? "manual" : undefined,
|
|
105
|
+
method: request.authorizeOnly ? instruments_1.MANUAL_CAPTURE_METHODS : undefined,
|
|
106
|
+
locale,
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function CreateCheckoutSession(request, idempotencyKey, provider) {
|
|
111
|
+
if (request.savePaymentMethod && !request.customer) {
|
|
112
|
+
throw new interface_payment_1.PaymentError("savePaymentMethod requires a customer");
|
|
113
|
+
}
|
|
114
|
+
const account = (0, accounts_1.GetAccount)(provider);
|
|
115
|
+
const body = sessionBody(request);
|
|
116
|
+
return (0, errors_1.TranslatingNamed)({ customer: request.customer }, async () => toSession(await account.client.request({
|
|
117
|
+
method: "POST",
|
|
118
|
+
path: "/payments",
|
|
119
|
+
body: {
|
|
120
|
+
...body,
|
|
121
|
+
...(0, fields_1.DefinedFields)({ webhookUrl: account.webhookUrl }),
|
|
122
|
+
},
|
|
123
|
+
idempotencyKey,
|
|
124
|
+
}, resources_1.IsMolliePayment)));
|
|
125
|
+
}
|
|
126
|
+
async function GetCheckoutSession(id, provider) {
|
|
127
|
+
return toSession(await (0, payments_1.ReadPayment)((0, accounts_1.GetAccount)(provider), id, SESSION_ENTITY));
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../../src/implementations/payment/checkout.ts"],"names":[],"mappings":";;AAsHA,sDA0BC;AAED,gDAKC;AAvJD,sDAAyD;AACzD,qEAKuC;AAEvC,qCAA4C;AAC5C,yCAAyC;AACzC,6CAA4C;AAC5C,gDAA4D;AAC5D,kDAAsD;AACtD,oDAAsD;AACtD,+CAAuD;AAEvD,uCAAwE;AAExE,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAE1C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;CACR,CAAC,CAAC;AAGH,MAAM,yBAAyB,GAAG;IAChC,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;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,UAAU,EAAE,CAAC;SACrD;QACD,cAAc;KACf,EACD,2BAAe,CAChB,CACF,CACF,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,EAAU,EACV,QAAiB;IAEjB,OAAO,SAAS,CAAC,MAAM,IAAA,sBAAW,EAAC,IAAA,qBAAU,EAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Customer, CustomerRequest, PaymentMethod } from "@antelopejs/interface-payment";
|
|
2
|
+
export declare function CreateCustomer(request: CustomerRequest, idempotencyKey: string, provider?: string): Promise<Customer>;
|
|
3
|
+
export declare function GetCustomer(id: string, provider?: string): Promise<Customer>;
|
|
4
|
+
export declare function DeleteCustomer(id: string, _idempotencyKey: string, provider?: string): Promise<void>;
|
|
5
|
+
export declare function ListPaymentMethods(customer: string, provider?: string): Promise<PaymentMethod[]>;
|
|
6
|
+
export declare function DetachPaymentMethod(id: string, _idempotencyKey: string, provider?: string): Promise<void>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateCustomer = CreateCustomer;
|
|
4
|
+
exports.GetCustomer = GetCustomer;
|
|
5
|
+
exports.DeleteCustomer = DeleteCustomer;
|
|
6
|
+
exports.ListPaymentMethods = ListPaymentMethods;
|
|
7
|
+
exports.DetachPaymentMethod = DetachPaymentMethod;
|
|
8
|
+
const resources_1 = require("../../mollie/resources");
|
|
9
|
+
const accounts_1 = require("../../accounts");
|
|
10
|
+
const errors_1 = require("./errors");
|
|
11
|
+
const fields_1 = require("../../mollie/fields");
|
|
12
|
+
const ids_1 = require("../../mollie/ids");
|
|
13
|
+
const mapping_1 = require("./mapping");
|
|
14
|
+
const metadata_1 = require("../../mollie/metadata");
|
|
15
|
+
const CUSTOMER_ENTITY = "customer";
|
|
16
|
+
const METHOD_ENTITY = "payment method";
|
|
17
|
+
const MANDATE_PAGE = "/mandates?limit=250";
|
|
18
|
+
function toCustomer(customer) {
|
|
19
|
+
const metadata = (0, metadata_1.ReadCallerMetadata)(customer.metadata);
|
|
20
|
+
return {
|
|
21
|
+
id: customer.id,
|
|
22
|
+
...(0, fields_1.DefinedFields)({
|
|
23
|
+
email: customer.email ?? undefined,
|
|
24
|
+
name: customer.name ?? undefined,
|
|
25
|
+
metadata: (0, fields_1.NonEmpty)(metadata),
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function assertCustomerId(id) {
|
|
30
|
+
if (!(0, ids_1.IsMollieId)("customer", id))
|
|
31
|
+
throw (0, errors_1.NotFound)(id, CUSTOMER_ENTITY);
|
|
32
|
+
}
|
|
33
|
+
async function CreateCustomer(request, idempotencyKey, provider) {
|
|
34
|
+
const account = (0, accounts_1.GetAccount)(provider);
|
|
35
|
+
return (0, errors_1.Translating)("", CUSTOMER_ENTITY, async () => toCustomer(await account.client.request({
|
|
36
|
+
method: "POST",
|
|
37
|
+
path: "/customers",
|
|
38
|
+
body: {
|
|
39
|
+
...(0, fields_1.DefinedFields)({ email: request.email, name: request.name }),
|
|
40
|
+
metadata: (0, metadata_1.WriteMetadata)({}, request.metadata),
|
|
41
|
+
},
|
|
42
|
+
idempotencyKey,
|
|
43
|
+
}, resources_1.IsMollieCustomer)));
|
|
44
|
+
}
|
|
45
|
+
async function GetCustomer(id, provider) {
|
|
46
|
+
assertCustomerId(id);
|
|
47
|
+
const account = (0, accounts_1.GetAccount)(provider);
|
|
48
|
+
return (0, errors_1.Translating)(id, CUSTOMER_ENTITY, async () => toCustomer(await account.client.request({
|
|
49
|
+
method: "GET",
|
|
50
|
+
path: `/customers/${id}`,
|
|
51
|
+
}, resources_1.IsMollieCustomer)));
|
|
52
|
+
}
|
|
53
|
+
async function DeleteCustomer(id, _idempotencyKey, provider) {
|
|
54
|
+
assertCustomerId(id);
|
|
55
|
+
const account = (0, accounts_1.GetAccount)(provider);
|
|
56
|
+
await (0, errors_1.Translating)(id, CUSTOMER_ENTITY, () => account.client.execute({ method: "DELETE", path: `/customers/${id}` }));
|
|
57
|
+
}
|
|
58
|
+
async function ListPaymentMethods(customer, provider) {
|
|
59
|
+
assertCustomerId(customer);
|
|
60
|
+
const account = (0, accounts_1.GetAccount)(provider);
|
|
61
|
+
return (0, errors_1.Translating)(customer, CUSTOMER_ENTITY, async () => {
|
|
62
|
+
const mandates = await account.client.list(`/customers/${customer}${MANDATE_PAGE}`, "mandates", resources_1.IsMollieMandate);
|
|
63
|
+
return mandates
|
|
64
|
+
.filter(mapping_1.IsChargeableOffSession)
|
|
65
|
+
.map((mandate) => (0, mapping_1.ToPaymentMethod)(mandate, customer))
|
|
66
|
+
.sort((first, second) => second.createdAt - first.createdAt);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function DetachPaymentMethod(id, _idempotencyKey, provider) {
|
|
70
|
+
const parsed = (0, ids_1.ParsePaymentMethodId)(id);
|
|
71
|
+
if (!parsed)
|
|
72
|
+
throw (0, errors_1.NotFound)(id, METHOD_ENTITY);
|
|
73
|
+
const account = (0, accounts_1.GetAccount)(provider);
|
|
74
|
+
await (0, errors_1.Translating)(id, METHOD_ENTITY, () => account.client.execute({
|
|
75
|
+
method: "DELETE",
|
|
76
|
+
path: `/customers/${parsed.parent}/mandates/${parsed.child}`,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.js","sourceRoot":"","sources":["../../../src/implementations/payment/customers.ts"],"names":[],"mappings":";;AAmCA,wCAsBC;AAED,kCAiBC;AAED,wCAUC;AAED,gDAiBC;AAED,kDAcC;AA3HD,sDAA2E;AAO3E,6CAA4C;AAC5C,qCAAiD;AACjD,gDAA8D;AAC9D,0CAAoE;AACpE,uCAAoE;AAEpE,oDAA0E;AAE1E,MAA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AAC,IAAA,yBAAe,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;aACpD,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,mBAAmB,CACvC,EAAU,EACV,eAAuB,EACvB,QAAiB;IAEjB,MAAM,MAAM,GAAG,IAAA,0BAAoB,EAAC,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAA,iBAAQ,EAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAA,qBAAU,EAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,IAAA,oBAAW,EAAC,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,CACxC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,cAAc,MAAM,CAAC,MAAM,aAAa,MAAM,CAAC,KAAK,EAAE;KAC7D,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CustomerEntity, type PaymentEntity } from "@antelopejs/interface-payment";
|
|
2
|
+
export type Entity = CustomerEntity | PaymentEntity;
|
|
3
|
+
export declare function NotFound(id: string, entity: Entity, code?: string): Error;
|
|
4
|
+
export declare function Translating<T>(id: string, entity: Entity, call: () => Promise<T>): Promise<T>;
|
|
5
|
+
export interface Named {
|
|
6
|
+
customer?: string;
|
|
7
|
+
paymentMethod?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function TranslatingNamed<T>(named: Named, call: () => Promise<T>): Promise<T>;
|
|
10
|
+
export declare function InTurnOrder<First, Second>(first: Promise<First>, second: Promise<Second>): Promise<[First, Second]>;
|