@webbers/pay-payments-medusa 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/.medusa/server/package.json +90 -0
- package/.medusa/server/src/admin/index.js +229 -0
- package/.medusa/server/src/admin/index.mjs +228 -0
- package/.medusa/server/src/api/admin/pay/clear-cache/route.js +23 -0
- package/.medusa/server/src/api/admin/pay/payment-methods/route.js +36 -0
- package/.medusa/server/src/api/store/pay/payment-methods/route.js +36 -0
- package/.medusa/server/src/providers/pay/core/constants.js +52 -0
- package/.medusa/server/src/providers/pay/core/http-client.js +107 -0
- package/.medusa/server/src/providers/pay/core/pay-base.js +561 -0
- package/.medusa/server/src/providers/pay/core/pay-client.js +118 -0
- package/.medusa/server/src/providers/pay/index.js +22 -0
- package/.medusa/server/src/providers/pay/services/index.js +17 -0
- package/.medusa/server/src/providers/pay/services/pay-bancontact.js +21 -0
- package/.medusa/server/src/providers/pay/services/pay-creditcard.js +21 -0
- package/.medusa/server/src/providers/pay/services/pay-ideal.js +21 -0
- package/.medusa/server/src/providers/pay/services/pay-provider.js +23 -0
- package/.medusa/server/src/providers/pay/services/pay-softpos.js +20 -0
- package/.medusa/server/src/providers/pay/types/common.js +3 -0
- package/.medusa/server/src/providers/pay/types/index.js +28 -0
- package/.medusa/server/src/providers/pay/types/order.js +3 -0
- package/.medusa/server/src/providers/pay/types/transaction.js +3 -0
- package/.medusa/server/src/providers/pay/utils/getExpirationForPaymentMethod.js +16 -0
- package/.medusa/server/src/providers/pay/utils/getSortedPaymentMethods.js +20 -0
- package/.medusa/server/src/providers/pay/utils/paymentMethodMap.js +133 -0
- package/.medusa/server/src/workflows/hooks/order-created.js +96 -0
- package/README.md +221 -0
- package/package.json +90 -0
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
5
|
+
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<h1 align="center">
|
|
10
|
+
Pay. payments for Medusa V2
|
|
11
|
+
</h1>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
Get access to 50+ payment options for online and in-store payments.
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="#">
|
|
19
|
+
<img src="https://img.shields.io/badge/license-TBD-blue.svg" />
|
|
20
|
+
</a>
|
|
21
|
+
<a href="#">
|
|
22
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
|
|
23
|
+
</a>
|
|
24
|
+
<br />
|
|
25
|
+
<a href="https://www.pay.nl/en/">
|
|
26
|
+
<img src="https://img.shields.io/badge/www-pay.nl-blue.svg?style=flat" alt="Website" />
|
|
27
|
+
</a>
|
|
28
|
+
<a href="https://webbers.com">
|
|
29
|
+
<img src="https://img.shields.io/badge/www-webbers.com-blue.svg?style=flat" alt="Website" />
|
|
30
|
+
</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
TBD from here
|
|
35
|
+
|
|
36
|
+
## Getting Started
|
|
37
|
+
|
|
38
|
+
## Table of Contents
|
|
39
|
+
|
|
40
|
+
- [Features](#features)
|
|
41
|
+
- [Prerequisites](#prerequisites)
|
|
42
|
+
- [Installation](#installation)
|
|
43
|
+
- [Configuration](#configuration)
|
|
44
|
+
- [Configuration Options](#configuration-options)
|
|
45
|
+
- [Environment Variables](#environment-variables)
|
|
46
|
+
- [Usage](#usage)
|
|
47
|
+
- [Client-Side Integration](#client-side-integration)
|
|
48
|
+
- [Supported Payment Methods](#supported-payment-methods)
|
|
49
|
+
- [Extending the Plugin](#extending-the-plugin)
|
|
50
|
+
- [Local Development and Customization](#local-development-and-customization)
|
|
51
|
+
- [License](#license)
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- **Multiple Payment Methods**: Supports a wide range of Pay payment methods including:
|
|
56
|
+
|
|
57
|
+
- iDEAL
|
|
58
|
+
- Bancontact
|
|
59
|
+
- Credit Card
|
|
60
|
+
- PayPal
|
|
61
|
+
- Apple Pay
|
|
62
|
+
- Gift Card
|
|
63
|
+
|
|
64
|
+
- **Easily Extendable**: The modular architecture makes it easy to add support for additional Pay payment methods.
|
|
65
|
+
|
|
66
|
+
- **Webhook Support**: Full support for Pay webhooks for real-time payment status updates.
|
|
67
|
+
|
|
68
|
+
- **Automatic Capture**: Configurable automatic capture of payments.
|
|
69
|
+
|
|
70
|
+
## Prerequisites
|
|
71
|
+
|
|
72
|
+
- Medusa server v2.3.0 or later
|
|
73
|
+
- Node.js v20 or later
|
|
74
|
+
- A [Pay](https://www.pay.nl/en/) account and token & secret with payment methods enabled.
|
|
75
|
+
|
|
76
|
+
> [!NOTE]
|
|
77
|
+
> _You can get the API token & secret from your Pay dashboard: click Settings > Click sales channel > Copy api tokens_
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
yarn add @webbers/pay-payments-medusa
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Configuration
|
|
86
|
+
|
|
87
|
+
Add the provider to the `@medusajs/payment` module in your `medusa-config.ts` file & add it as plugin:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
plugins: [
|
|
91
|
+
// ... other plugins
|
|
92
|
+
'@webbers/pay-payments-medusa'
|
|
93
|
+
],
|
|
94
|
+
modules
|
|
95
|
+
:
|
|
96
|
+
[
|
|
97
|
+
// ... other modules
|
|
98
|
+
{
|
|
99
|
+
resolve: "@medusajs/payment",
|
|
100
|
+
options: {
|
|
101
|
+
providers: [
|
|
102
|
+
{
|
|
103
|
+
resolve: "@webbers/pay-payments-medusa/providers/pay",
|
|
104
|
+
id: "pay",
|
|
105
|
+
options: {
|
|
106
|
+
paymentDescription: "Your description", // optional
|
|
107
|
+
atCode: process.env.PAY_AT_CODE,
|
|
108
|
+
apiToken: process.env.PAY_API_TOKEN,
|
|
109
|
+
slCode: process.env.PAY_SL_CODE,
|
|
110
|
+
slSecret: process.env.PAY_SL_SECRET,
|
|
111
|
+
returnUrl: process.env.PAY_RETURN_URL,
|
|
112
|
+
testMode: process.env.PAY_TEST_MODE === 'true',
|
|
113
|
+
tguApiUrl: process.env.PAY_TGU_API_URL, // defaults to https://connect.pay.nl/v1
|
|
114
|
+
otherSlCodes: process.env.PAY_OTHER_SL_CODE ? JSON.parse(process.env.PAY_OTHER_SL_CODE) : undefined,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Configuration Options
|
|
124
|
+
|
|
125
|
+
| Option | Description | Default |
|
|
126
|
+
|----------------------|-----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
127
|
+
| `atCode` | Your Pay AT code | Required |
|
|
128
|
+
| `apiToken` | Your Pay API token | Required |
|
|
129
|
+
| `slCode` | Your Pay sales channel code | Required |
|
|
130
|
+
| `slSecret` | Your Pay sales channel secret | Required |
|
|
131
|
+
| `returnUrl` | The URL to return to after payment | Required |
|
|
132
|
+
| `medusaUrl` | The URL of your Medusa server | Required |
|
|
133
|
+
| `testMode` | Whether to enable test payments | Optional |
|
|
134
|
+
| `tguApiUrl` | Pay TGU API Url | Optional, use if you want to use a specific or private TGU, see [here](https://developer.pay.nl/docs/transaction-gateway-unit#multi-cores-more-tgus). |
|
|
135
|
+
| `otherSlCodes` | Your other Pay sales channel code and secrets | Optional, used for webhook signature validation when using multiple Pay. sales channels. Format `'{"SL-CODE-X":"secretX","SL-CODE-Y":"secretY"}'` |
|
|
136
|
+
|
|
137
|
+
## Environment Variables
|
|
138
|
+
|
|
139
|
+
Create or update your `.env` file with the following variables:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
PAY_AT_CODE="<your-pay-at-code>"
|
|
143
|
+
PAY_API_TOKEN="<your-pay-api-token>"
|
|
144
|
+
PAY_SL_CODE="<your-pay-sl-code>"
|
|
145
|
+
PAY_SL_SECRET="<your-pay-sl-secret>"
|
|
146
|
+
#PAY_TEST_MODE="true"
|
|
147
|
+
PAY_EXCHANGE_URL="https://your-store.com/checkout/payment"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Usage
|
|
151
|
+
|
|
152
|
+
Once installed and configured, the Pay payment methods will be available in your Medusa admin. To enable them, log in to
|
|
153
|
+
you Medusa Admin, browse to Settings > Regions, add or edit a region and select the desired Pay providers from the
|
|
154
|
+
dropdown.
|
|
155
|
+
|
|
156
|
+

|
|
157
|
+
|
|
158
|
+
Make sure that the selected payment methods are enabled in your Pay origanization settings as well.
|
|
159
|
+
|
|
160
|
+
### Client-Side Integration
|
|
161
|
+
|
|
162
|
+
To integrate with your storefront, you'll need to implement the payment flow according to Pay's and Medusa's
|
|
163
|
+
documentation. Here's a basic example:
|
|
164
|
+
|
|
165
|
+
1. Create a payment session in your checkout flow
|
|
166
|
+
2. Redirect the customer to the Pay payment page
|
|
167
|
+
3. Handle the webhook notifications to update the payment status
|
|
168
|
+
|
|
169
|
+
_Example integration using the [Medusa Next.js Starter](https://github.com/medusajs/nextjs-starter-medusa):_
|
|
170
|
+
|
|
171
|
+
https://github.com/user-attachments/assets/742ee261-5e41-4e33-9a72-faf1a424fc52
|
|
172
|
+
|
|
173
|
+
### Supported Payment Methods
|
|
174
|
+
|
|
175
|
+
The plugin currently supports the following Pay payment methods:
|
|
176
|
+
|
|
177
|
+
| Payment Method | Provider ID |
|
|
178
|
+
|----------------|-------------------------|
|
|
179
|
+
| iDEAL | `pp_pay-ideal_pay` |
|
|
180
|
+
| Credit Card | `pp_pay-card_pay` |
|
|
181
|
+
| Bancontact | `pp_pay-bancontact_pay` |
|
|
182
|
+
| Gift Card | `pp_pay-giftcard_pay` |
|
|
183
|
+
| PayPal | `pp_pay-paypal_pay` |
|
|
184
|
+
| Apple Pay | `pp_pay-apple-pay_pay` |
|
|
185
|
+
|
|
186
|
+
## Extending the Plugin
|
|
187
|
+
|
|
188
|
+
To add support for additional Pay payment methods, create a new service in `src/providers/Pay/services` that extends the
|
|
189
|
+
`PayBase` class:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import {PaymentMethod} from "@Pay/api-client";
|
|
193
|
+
import PayBase from "../core/Pay-base";
|
|
194
|
+
import {PaymentOptions, PaymentProviderKeys} from "../types";
|
|
195
|
+
|
|
196
|
+
class PayNewMethodService extends PayBase {
|
|
197
|
+
static identifier = "Pay-new-method";
|
|
198
|
+
|
|
199
|
+
get paymentCreateOptions(): PaymentOptions {
|
|
200
|
+
return {
|
|
201
|
+
method: PaymentMethod.newMethod,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default PayNewMethodService;
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Make sure to replace `new method` with the actual Pay payment method ID.
|
|
210
|
+
|
|
211
|
+
Export your new service from `src/providers/Pay/services/index.ts`. Then add your new service to the list of services in
|
|
212
|
+
`src/providers/Pay/index.ts`.
|
|
213
|
+
|
|
214
|
+
## Local development and customization
|
|
215
|
+
|
|
216
|
+
In case you want to customize and test the plugin locally, refer to
|
|
217
|
+
the [Medusa Plugin docs](https://docs.medusajs.com/learn/fundamentals/plugins/create#3-publish-plugin-locally-for-development-and-testing).
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
TBD
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webbers/pay-payments-medusa",
|
|
3
|
+
"displayName": "Medusa v2 Pay. Plugin",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "The Pay.nl payment provider plugin for Medusa v2",
|
|
6
|
+
"author": "Webbers B.V. <development@webbers.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
".medusa/server"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
"./workflows": "./.medusa/server/src/workflows/index.js",
|
|
14
|
+
"./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
|
|
15
|
+
"./modules/*": "./.medusa/server/src/modules/*/index.js",
|
|
16
|
+
"./providers/*": "./.medusa/server/src/providers/*/index.js",
|
|
17
|
+
"./admin": {
|
|
18
|
+
"import": "./.medusa/server/src/admin/index.mjs",
|
|
19
|
+
"require": "./.medusa/server/src/admin/index.js",
|
|
20
|
+
"default": "./.medusa/server/src/admin/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./*": "./.medusa/server/src/*.js"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"medusa",
|
|
26
|
+
"plugin",
|
|
27
|
+
"medusa-plugin-other",
|
|
28
|
+
"medusa-plugin",
|
|
29
|
+
"medusa-v2"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "medusa plugin:build",
|
|
33
|
+
"dev": "medusa plugin:develop",
|
|
34
|
+
"prepublishOnly": "medusa plugin:build"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@medusajs/admin-sdk": "^2.7.1",
|
|
38
|
+
"@medusajs/cli": "^2.7.1",
|
|
39
|
+
"@medusajs/framework": "^2.7.1",
|
|
40
|
+
"@medusajs/icons": "^2.7.1",
|
|
41
|
+
"@medusajs/medusa": "^2.7.1",
|
|
42
|
+
"@medusajs/test-utils": "^2.7.1",
|
|
43
|
+
"@medusajs/types": "^2.7.1",
|
|
44
|
+
"@medusajs/ui": "^4.0.9",
|
|
45
|
+
"@mikro-orm/cli": "6.4.3",
|
|
46
|
+
"@mikro-orm/core": "6.4.3",
|
|
47
|
+
"@mikro-orm/knex": "6.4.3",
|
|
48
|
+
"@mikro-orm/migrations": "6.4.3",
|
|
49
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
50
|
+
"@swc/core": "1.5.7",
|
|
51
|
+
"@types/node": "^20.17.45",
|
|
52
|
+
"@types/react": "^18.3.21",
|
|
53
|
+
"@types/react-dom": "^18.3.7",
|
|
54
|
+
"awilix": "^8.0.1",
|
|
55
|
+
"pg": "^8.15.6",
|
|
56
|
+
"prettier": "^3.5.3",
|
|
57
|
+
"prop-types": "^15.8.1",
|
|
58
|
+
"react": "^18.2.0",
|
|
59
|
+
"react-dom": "^18.2.0",
|
|
60
|
+
"ts-node": "^10.9.2",
|
|
61
|
+
"typescript": "^5.6.2",
|
|
62
|
+
"vite": "^5.4.19",
|
|
63
|
+
"yalc": "^1.0.0-pre.53"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@medusajs/admin-sdk": "^2.7.1",
|
|
67
|
+
"@medusajs/cli": "^2.7.1",
|
|
68
|
+
"@medusajs/framework": "^2.7.1",
|
|
69
|
+
"@medusajs/icons": "^2.7.1",
|
|
70
|
+
"@medusajs/medusa": "^2.7.1",
|
|
71
|
+
"@medusajs/test-utils": "^2.7.1",
|
|
72
|
+
"@medusajs/ui": "4.0.3",
|
|
73
|
+
"@mikro-orm/cli": "6.4.3",
|
|
74
|
+
"@mikro-orm/core": "6.4.3",
|
|
75
|
+
"@mikro-orm/knex": "6.4.3",
|
|
76
|
+
"@mikro-orm/migrations": "6.4.3",
|
|
77
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
78
|
+
"awilix": "^8.0.1",
|
|
79
|
+
"pg": "^8.13.0"
|
|
80
|
+
},
|
|
81
|
+
"engines": {
|
|
82
|
+
"node": ">=20"
|
|
83
|
+
},
|
|
84
|
+
"packageManager": "pnpm@10.9.0",
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@medusajs/core-flows": "^2.7.1",
|
|
87
|
+
"@medusajs/js-sdk": "^2.7.1",
|
|
88
|
+
"@tanstack/react-query": "^5.75.7"
|
|
89
|
+
}
|
|
90
|
+
}
|