@abdssamie/adyen-payments 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 +201 -0
- package/README.md +258 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/index.d.ts +206 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +566 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +36 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +215 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/private.d.ts +71 -0
- package/dist/component/private.d.ts.map +1 -0
- package/dist/component/private.js +250 -0
- package/dist/component/private.js.map +1 -0
- package/dist/component/public.d.ts +170 -0
- package/dist/component/public.d.ts.map +1 -0
- package/dist/component/public.js +210 -0
- package/dist/component/public.js.map +1 -0
- package/dist/component/schema.d.ts +101 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +63 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/react/hooks.d.ts +182 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +215 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +104 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.test.ts +196 -0
- package/src/client/index.ts +823 -0
- package/src/client/setup.test.ts +26 -0
- package/src/client/webhooks.test.ts +182 -0
- package/src/component/_generated/api.ts +52 -0
- package/src/component/_generated/component.ts +293 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/private.ts +277 -0
- package/src/component/public.test.ts +92 -0
- package/src/component/public.ts +229 -0
- package/src/component/schema.ts +67 -0
- package/src/component/setup.test.ts +11 -0
- package/src/react/hooks.ts +488 -0
- package/src/react/index.ts +18 -0
- package/src/test.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Convex Adyen Payments
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/@abdssamie%2Fadyen-payments)
|
|
4
|
+
|
|
5
|
+
A Convex component that integrates your application with **Adyen Payments**. It enables checkout sessions (supporting the Adyen Drop-in & Web Components SDK), secure payment tokenization for recurring billing, and automatic database updates via HMAC-validated webhooks.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 Installation
|
|
10
|
+
|
|
11
|
+
Install the package in your project:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @abdssamie/adyen-payments
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @abdssamie/adyen-payments
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Create or update your `convex/convex.config.ts` file to import and use the component:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// convex/convex.config.ts
|
|
23
|
+
import { defineApp } from "convex/server";
|
|
24
|
+
import adyenPayments from "@abdssamie/adyen-payments/convex.config.js";
|
|
25
|
+
|
|
26
|
+
const app = defineApp();
|
|
27
|
+
app.use(adyenPayments);
|
|
28
|
+
|
|
29
|
+
export default app;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🔑 Environment Variables & Dashboard Configuration
|
|
35
|
+
|
|
36
|
+
The component requires the following environment variables. Set them in your Convex dashboard under **Settings** > **Environment Variables** or locally in `.env.local`:
|
|
37
|
+
|
|
38
|
+
| Environment Variable | Description |
|
|
39
|
+
| :--- | :--- |
|
|
40
|
+
| `ADYEN_API_KEY` | Server-side API key for executing requests (e.g. `AQEy...`). |
|
|
41
|
+
| `ADYEN_MERCHANT_ACCOUNT` | The merchant account code (e.g. `CompanyAccountECOM`). |
|
|
42
|
+
| `ADYEN_ENVIRONMENT` | Set to `TEST` for sandbox testing, or `LIVE` for production. |
|
|
43
|
+
| `ADYEN_HMAC_KEY` | HMAC signature key for validating incoming webhook authenticity. |
|
|
44
|
+
| `APP_URL` | Base URL of your app (e.g. `https://myapp.com` or `http://localhost:3000`). |
|
|
45
|
+
|
|
46
|
+
### How to Get Your Credentials from the Adyen Customer Area
|
|
47
|
+
|
|
48
|
+
#### 1. Retrieve the Merchant Account Name
|
|
49
|
+
1. Log in to the [Adyen Customer Area](https://ca-live.adyen.com/ca/ca/login.shtml) (use sandbox for testing, live for production).
|
|
50
|
+
2. Click the account switcher in the top-left corner.
|
|
51
|
+
3. Toggle to your specific **Merchant Account** (which handles payments) rather than the **Company Account** (used for administration).
|
|
52
|
+
4. Copy the unique account name/code. This is your `ADYEN_MERCHANT_ACCOUNT`.
|
|
53
|
+
|
|
54
|
+
#### 2. Generate an API Key
|
|
55
|
+
1. In the account switcher, select your **Company Account** level.
|
|
56
|
+
2. In the sidebar, navigate to **Developers** > **API credentials**.
|
|
57
|
+
3. Select your integration's web service user (typically starting with `ws@Company.[YourCompanyAccount]`).
|
|
58
|
+
4. Under **Server settings** > **Authentication**, click the **API key** tab.
|
|
59
|
+
5. Click **Generate API key**.
|
|
60
|
+
6. **Important**: Copy this key immediately and store it securely. You cannot view it again once you navigate away. Click **Save changes** at the bottom of the page.
|
|
61
|
+
|
|
62
|
+
#### 3. Set Up Webhooks & Generate an HMAC Key
|
|
63
|
+
1. Select your specific **Merchant Account** in the switcher.
|
|
64
|
+
2. Go to **Developers** > **Webhooks** in the sidebar.
|
|
65
|
+
3. Click **+ Webhook** on the top-right.
|
|
66
|
+
4. Select **Standard Webhook** and click **Add**.
|
|
67
|
+
5. Set the **Server URL** to your Convex deployment site endpoint (e.g., `https://<your-deployment>.convex.site/adyen/webhooks`).
|
|
68
|
+
6. Scroll down to the **Security** tab and click **Generate** under the HMAC Key section.
|
|
69
|
+
7. Copy the generated HMAC key. This is your `ADYEN_HMAC_KEY`.
|
|
70
|
+
8. Ensure the webhook state is toggled to **Active** and click **Save configuration**.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 💻 Usage
|
|
75
|
+
|
|
76
|
+
To use the client, import `AdyenPayments` and initialize it with your registered component:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { AdyenPayments } from "@abdssamie/adyen-payments";
|
|
80
|
+
import { components } from "./_generated/api";
|
|
81
|
+
|
|
82
|
+
const adyenClient = new AdyenPayments(components.adyenPayments, {
|
|
83
|
+
autoCapture: true, // If true (default), capture immediately. Set false for manual capture.
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 1. Initializing Checkout
|
|
88
|
+
Create an action in your app's `convex/` folder to initialize a payment checkout session. This provides the `sessionId` and configuration payload required by Adyen's frontend Drop-in/Components SDK.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { action } from "./_generated/server";
|
|
92
|
+
import { v } from "convex/values";
|
|
93
|
+
|
|
94
|
+
export const startCheckout = action({
|
|
95
|
+
args: {
|
|
96
|
+
amount: v.number(), // Value in minor units (e.g., 1000 for $10.00)
|
|
97
|
+
currency: v.string(), // e.g. "USD", "EUR"
|
|
98
|
+
shopperReference: v.string(), // Unique shopper identifier
|
|
99
|
+
},
|
|
100
|
+
handler: async (ctx, args) => {
|
|
101
|
+
const session = await adyenClient.createCheckoutSession(ctx, {
|
|
102
|
+
amount: args.amount,
|
|
103
|
+
currency: args.currency,
|
|
104
|
+
successUrl: `https://myapp.com/checkout/success`,
|
|
105
|
+
cancelUrl: `https://myapp.com/checkout/cancel`,
|
|
106
|
+
shopperReference: args.shopperReference,
|
|
107
|
+
});
|
|
108
|
+
return session; // Returns { sessionId, sessionData, url? }
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> **Note:** This component supports the Adyen Drop-in and Web Components SDK only. It does not support hosted checkout pages (HPP) or Pay By Link — the `url` field in the session response is optional and `null` for most merchant configurations.
|
|
114
|
+
|
|
115
|
+
### 2. Charging a Stored Card (Recurring / MIT)
|
|
116
|
+
When a shopper pays during checkout and consents to saving their payment details, Adyen stores a token. You can trigger recurring charges from a backend action:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
export const chargeRecurring = action({
|
|
120
|
+
args: {
|
|
121
|
+
shopperReference: v.string(),
|
|
122
|
+
recurringDetailReference: v.string(), // The stored card token
|
|
123
|
+
amount: v.number(),
|
|
124
|
+
currency: v.string(),
|
|
125
|
+
},
|
|
126
|
+
handler: async (ctx, args) => {
|
|
127
|
+
return await adyenClient.chargeStoredCard(ctx, {
|
|
128
|
+
shopperReference: args.shopperReference,
|
|
129
|
+
recurringDetailReference: args.recurringDetailReference,
|
|
130
|
+
amount: args.amount,
|
|
131
|
+
currency: args.currency,
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 3. Payment Modifications (Manual Capture, Refund, Cancel)
|
|
138
|
+
If you configure `autoCapture: false` (manual capture), you must manually capture authorizations:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
export const capture = action({
|
|
142
|
+
args: { pspReference: v.string(), amount: v.number(), currency: v.string() },
|
|
143
|
+
handler: async (ctx, args) => {
|
|
144
|
+
return await adyenClient.capturePayment(ctx, args);
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
export const refund = action({
|
|
149
|
+
args: { pspReference: v.string(), amount: v.number(), currency: v.string() },
|
|
150
|
+
handler: async (ctx, args) => {
|
|
151
|
+
return await adyenClient.refundPayment(ctx, args);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export const cancel = action({
|
|
156
|
+
args: { pspReference: v.string() },
|
|
157
|
+
handler: async (ctx, args) => {
|
|
158
|
+
return await adyenClient.cancelPayment(ctx, args);
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 🔔 Webhook Integration
|
|
166
|
+
|
|
167
|
+
Adyen webhooks require a Node.js context because signature verification depends on Node-native packages. Define the handler inside a `"use node"` file, and map it inside your `http.ts` router.
|
|
168
|
+
|
|
169
|
+
### 1. Webhook Handler (`convex/adyenWebhooks.ts`)
|
|
170
|
+
```ts
|
|
171
|
+
"use node";
|
|
172
|
+
|
|
173
|
+
import { internalAction } from "./_generated/server";
|
|
174
|
+
import { components } from "./_generated/api";
|
|
175
|
+
import { createWebhookHandler } from "@abdssamie/adyen-payments";
|
|
176
|
+
import { v } from "convex/values";
|
|
177
|
+
|
|
178
|
+
// Create raw handler with custom hooks if needed
|
|
179
|
+
const rawHandler = createWebhookHandler(components.adyenPayments, {
|
|
180
|
+
events: {
|
|
181
|
+
AUTHORISATION: async (ctx, notification) => {
|
|
182
|
+
console.log(`Payment authorized for order: ${notification.merchantReference}`);
|
|
183
|
+
},
|
|
184
|
+
CAPTURE: async (ctx, notification) => {
|
|
185
|
+
console.log(`Payment captured: ${notification.pspReference}`);
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export const handleWebhook = internalAction({
|
|
191
|
+
args: { bodyText: v.string(), url: v.string() },
|
|
192
|
+
handler: async (ctx, args) => {
|
|
193
|
+
const request = new Request(args.url, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
body: args.bodyText,
|
|
196
|
+
headers: { "Content-Type": "application/json" },
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const response = await rawHandler(ctx, request);
|
|
200
|
+
if (!response.ok) {
|
|
201
|
+
throw new Error(`Webhook error: ${response.status}`);
|
|
202
|
+
}
|
|
203
|
+
return await response.text();
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 2. HTTP Routing (`convex/http.ts`)
|
|
209
|
+
```ts
|
|
210
|
+
import { httpRouter } from "convex/server";
|
|
211
|
+
import { httpAction } from "./_generated/server";
|
|
212
|
+
import { internal } from "./_generated/api";
|
|
213
|
+
|
|
214
|
+
const http = httpRouter();
|
|
215
|
+
|
|
216
|
+
http.route({
|
|
217
|
+
path: "/adyen/webhooks",
|
|
218
|
+
method: "POST",
|
|
219
|
+
handler: httpAction(async (ctx, request) => {
|
|
220
|
+
const bodyText = await request.text();
|
|
221
|
+
try {
|
|
222
|
+
const responseText = await ctx.runAction(
|
|
223
|
+
internal.adyenWebhooks.handleWebhook,
|
|
224
|
+
{ bodyText, url: request.url }
|
|
225
|
+
);
|
|
226
|
+
return new Response(responseText, {
|
|
227
|
+
status: 200,
|
|
228
|
+
headers: { "Content-Type": "text/plain" },
|
|
229
|
+
});
|
|
230
|
+
} catch (err) {
|
|
231
|
+
console.error("Webhook processing error:", err);
|
|
232
|
+
return new Response("Webhook Error", { status: 400 });
|
|
233
|
+
}
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export default http;
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## 🛠️ Developing the Component
|
|
243
|
+
|
|
244
|
+
To contribute or make changes to the component repository itself, follow these steps to test and compile local changes:
|
|
245
|
+
|
|
246
|
+
```sh
|
|
247
|
+
# Install dependencies
|
|
248
|
+
pnpm install
|
|
249
|
+
|
|
250
|
+
# Run the dev watcher (recompiles the component and runs example backend)
|
|
251
|
+
pnpm dev
|
|
252
|
+
|
|
253
|
+
# Run unit tests
|
|
254
|
+
pnpm test
|
|
255
|
+
|
|
256
|
+
# Lint files
|
|
257
|
+
pnpm lint
|
|
258
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=_ignore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ignore.js","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":";AAAA,kEAAkE"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { Types } from "@adyen/api-library";
|
|
2
|
+
import type { GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDataModel, HttpRouter } from "convex/server";
|
|
3
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
4
|
+
import { NotificationRequestItem } from "@adyen/api-library/lib/src/typings/notification/models.js";
|
|
5
|
+
export type QueryCtx = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
|
|
6
|
+
export type MutationCtx = Pick<GenericMutationCtx<GenericDataModel>, "runQuery" | "runMutation">;
|
|
7
|
+
export type ActionCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation" | "runAction">;
|
|
8
|
+
export type AdyenComponent = ComponentApi;
|
|
9
|
+
export declare const EventCodeEnum: typeof NotificationRequestItem.EventCodeEnum;
|
|
10
|
+
export interface AdyenPaymentsOptions {
|
|
11
|
+
ADYEN_API_KEY?: string;
|
|
12
|
+
ADYEN_MERCHANT_ACCOUNT?: string;
|
|
13
|
+
ADYEN_ENVIRONMENT?: "TEST" | "LIVE";
|
|
14
|
+
/**
|
|
15
|
+
* Default delay in hours before capturing the payment.
|
|
16
|
+
* - `0` (default): Capture immediately (Auto-capture).
|
|
17
|
+
* - `-1`: Manual capture (must be captured via API later).
|
|
18
|
+
* - `N` (greater than 0): Capture automatically after N hours.
|
|
19
|
+
*/
|
|
20
|
+
captureDelayHours?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to capture the payment automatically.
|
|
23
|
+
* If true (default), capture immediately.
|
|
24
|
+
* If false, perform manual capture (must be captured via API later).
|
|
25
|
+
*/
|
|
26
|
+
autoCapture?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adyen Payments Client
|
|
30
|
+
*
|
|
31
|
+
* Provides methods for managing shoppers, stored card payment methods,
|
|
32
|
+
* and performing checkout sessions or payments via the Adyen API.
|
|
33
|
+
*/
|
|
34
|
+
export declare class AdyenPayments {
|
|
35
|
+
component: AdyenComponent;
|
|
36
|
+
private _apiKey;
|
|
37
|
+
private _merchantAccount;
|
|
38
|
+
private _environment;
|
|
39
|
+
captureDelayHours: number;
|
|
40
|
+
constructor(component: AdyenComponent, options?: AdyenPaymentsOptions);
|
|
41
|
+
get apiKey(): string;
|
|
42
|
+
get merchantAccount(): string;
|
|
43
|
+
get environment(): "TEST" | "LIVE";
|
|
44
|
+
/**
|
|
45
|
+
* Helper to initialize the official Adyen SDK Client
|
|
46
|
+
*/
|
|
47
|
+
private getAdyenClient;
|
|
48
|
+
/**
|
|
49
|
+
* Manually create or update a shopper mapping in the database.
|
|
50
|
+
*/
|
|
51
|
+
createShopper(ctx: ActionCtx, args: {
|
|
52
|
+
shopperReference: string;
|
|
53
|
+
email?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
userId?: string;
|
|
56
|
+
metadata?: Record<string, unknown>;
|
|
57
|
+
}): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Get or create a shopper for a user ID.
|
|
60
|
+
* Checks database indexes first to avoid creating duplicates.
|
|
61
|
+
*/
|
|
62
|
+
getOrCreateShopper(ctx: ActionCtx, args: {
|
|
63
|
+
userId: string;
|
|
64
|
+
email?: string;
|
|
65
|
+
name?: string;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
shopperReference: string;
|
|
68
|
+
isNew: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Create an Adyen Checkout Session to initialize Drop-in/Components SDK.
|
|
72
|
+
*/
|
|
73
|
+
createCheckoutSession(ctx: ActionCtx, args: {
|
|
74
|
+
amount: number;
|
|
75
|
+
currency: string;
|
|
76
|
+
successUrl: string;
|
|
77
|
+
cancelUrl: string;
|
|
78
|
+
shopperReference?: string;
|
|
79
|
+
captureDelayHours?: number;
|
|
80
|
+
autoCapture?: boolean;
|
|
81
|
+
metadata?: Record<string, string>;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
sessionId: string;
|
|
84
|
+
sessionData: string;
|
|
85
|
+
url: string | null;
|
|
86
|
+
merchantReference: string;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Retrieve and sync tokenized payment methods stored for a shopper.
|
|
90
|
+
*/
|
|
91
|
+
listStoredPaymentMethods(ctx: ActionCtx, args: {
|
|
92
|
+
shopperReference: string;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
recurringDetailReference: string;
|
|
95
|
+
variant: string;
|
|
96
|
+
cardLast4: string | undefined;
|
|
97
|
+
cardExpiryMonth: string | undefined;
|
|
98
|
+
cardExpiryYear: string | undefined;
|
|
99
|
+
}[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Disable/delete a stored payment method token in Adyen and local database.
|
|
102
|
+
*/
|
|
103
|
+
deleteStoredPaymentMethod(ctx: ActionCtx, args: {
|
|
104
|
+
shopperReference: string;
|
|
105
|
+
recurringDetailReference: string;
|
|
106
|
+
}): Promise<null>;
|
|
107
|
+
/**
|
|
108
|
+
* Charge a stored payment method token (Merchant Initiated Transaction / Subscription).
|
|
109
|
+
*/
|
|
110
|
+
chargeStoredCard(ctx: ActionCtx, args: {
|
|
111
|
+
shopperReference: string;
|
|
112
|
+
recurringDetailReference: string;
|
|
113
|
+
amount: number;
|
|
114
|
+
currency: string;
|
|
115
|
+
reference?: string;
|
|
116
|
+
returnUrl?: string;
|
|
117
|
+
captureDelayHours?: number;
|
|
118
|
+
autoCapture?: boolean;
|
|
119
|
+
metadata?: Record<string, unknown>;
|
|
120
|
+
}): Promise<{
|
|
121
|
+
pspReference: string | null;
|
|
122
|
+
status: string;
|
|
123
|
+
resultCode: string;
|
|
124
|
+
merchantReference: string;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Capture an authorised payment.
|
|
128
|
+
*/
|
|
129
|
+
capturePayment(ctx: ActionCtx, args: {
|
|
130
|
+
pspReference: string;
|
|
131
|
+
amount: number;
|
|
132
|
+
currency: string;
|
|
133
|
+
}): Promise<{
|
|
134
|
+
pspReference: string;
|
|
135
|
+
status: Types.checkout.PaymentCaptureResponse.StatusEnum;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Refund a captured payment.
|
|
139
|
+
*/
|
|
140
|
+
refundPayment(ctx: ActionCtx, args: {
|
|
141
|
+
pspReference: string;
|
|
142
|
+
amount: number;
|
|
143
|
+
currency: string;
|
|
144
|
+
}): Promise<{
|
|
145
|
+
pspReference: string;
|
|
146
|
+
status: Types.checkout.PaymentRefundResponse.StatusEnum;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Cancel an uncaptured authorized payment.
|
|
150
|
+
*/
|
|
151
|
+
cancelPayment(ctx: ActionCtx, args: {
|
|
152
|
+
pspReference: string;
|
|
153
|
+
}): Promise<{
|
|
154
|
+
pspReference: string;
|
|
155
|
+
status: Types.checkout.PaymentCancelResponse.StatusEnum;
|
|
156
|
+
}>;
|
|
157
|
+
}
|
|
158
|
+
export type AdyenNotificationItem = Types.notification.NotificationRequestItem & {
|
|
159
|
+
shopperReference?: string;
|
|
160
|
+
};
|
|
161
|
+
export interface AdyenEventHandlers {
|
|
162
|
+
[eventCode: string]: (ctx: ActionCtx, notification: AdyenNotificationItem) => Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
export interface RegisterRoutesConfig {
|
|
165
|
+
webhookPath?: string;
|
|
166
|
+
ADYEN_HMAC_KEY?: string;
|
|
167
|
+
events?: AdyenEventHandlers;
|
|
168
|
+
onNotification?: (ctx: ActionCtx, notification: AdyenNotificationItem) => Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Creates a raw webhook handler function for use with `httpAction` in a
|
|
172
|
+
* `"use node"` file.
|
|
173
|
+
*
|
|
174
|
+
* Because `http.ts` cannot have the `"use node"` directive, the recommended
|
|
175
|
+
* pattern is:
|
|
176
|
+
*
|
|
177
|
+
* ```ts
|
|
178
|
+
* // adyenWebhooks.ts — "use node"
|
|
179
|
+
* import { httpAction } from "./_generated/server";
|
|
180
|
+
* import { components } from "./_generated/api";
|
|
181
|
+
* import { createWebhookHandler } from "@abdssamie/adyen-payments";
|
|
182
|
+
*
|
|
183
|
+
* export const webhookHandler = httpAction(
|
|
184
|
+
* createWebhookHandler(components.adyenPayments, { ... })
|
|
185
|
+
* );
|
|
186
|
+
*
|
|
187
|
+
* // http.ts — no directive
|
|
188
|
+
* import { httpRouter } from "convex/server";
|
|
189
|
+
* import { webhookHandler } from "./adyenWebhooks";
|
|
190
|
+
*
|
|
191
|
+
* const http = httpRouter();
|
|
192
|
+
* http.route({ path: "/adyen/webhooks", method: "POST", handler: webhookHandler });
|
|
193
|
+
* export default http;
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export declare function createWebhookHandler(component: AdyenComponent, config?: Omit<RegisterRoutesConfig, "webhookPath">): (ctx: GenericActionCtx<GenericDataModel>, req: Request) => Promise<Response>;
|
|
197
|
+
/**
|
|
198
|
+
* Convenience helper that registers the Adyen webhook route directly on an
|
|
199
|
+
* `HttpRouter`.
|
|
200
|
+
*
|
|
201
|
+
* @deprecated Prefer `createWebhookHandler` + `httpAction` in a `"use node"`
|
|
202
|
+
* file — see the `createWebhookHandler` JSDoc for the recommended pattern.
|
|
203
|
+
* This function must be called from a `"use node"` file when used.
|
|
204
|
+
*/
|
|
205
|
+
export declare function registerRoutes(http: HttpRouter, component: AdyenComponent, config?: RegisterRoutesConfig): void;
|
|
206
|
+
//# sourceMappingURL=index.d.ts.map
|