@easypayment/medusa-paypal 0.5.0 → 0.5.2
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/src/admin/index.js +10 -10
- package/.medusa/server/src/admin/index.mjs +10 -10
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js +14 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +5 -1
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +20 -2
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/README.md +163 -63
- package/package.json +1 -1
- package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +11 -0
- package/src/modules/paypal/models/paypal_connection.ts +22 -21
- package/src/modules/paypal/service.ts +1271 -1247
package/README.md
CHANGED
|
@@ -1,39 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# EasyPayment PayPal for Medusa
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PayPal Wallet and Advanced Card Payments integration for Medusa v2.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- PayPal Wallet (Smart Buttons)
|
|
10
|
+
- PayPal Advanced Card Payments
|
|
11
|
+
- Admin configuration UI for PayPal settings
|
|
12
|
+
- Store API support for storefront integrations
|
|
13
|
+
- Configurable checkout behavior
|
|
9
14
|
|
|
10
15
|
---
|
|
11
16
|
|
|
12
17
|
## Compatibility
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
| Component | Version |
|
|
20
|
+
|-----------|---------|
|
|
21
|
+
| Medusa | `^2.12.0` |
|
|
22
|
+
| Node.js | `>=20` |
|
|
16
23
|
|
|
17
24
|
---
|
|
18
25
|
|
|
19
|
-
##
|
|
26
|
+
## Installation
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
Install the package in your Medusa backend:
|
|
22
29
|
|
|
23
30
|
```bash
|
|
24
31
|
npm install @easypayment/medusa-paypal
|
|
25
|
-
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or with pnpm:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
26
37
|
pnpm add @easypayment/medusa-paypal
|
|
27
|
-
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or with yarn:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
28
43
|
yarn add @easypayment/medusa-paypal
|
|
29
44
|
```
|
|
30
45
|
|
|
31
|
-
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Medusa Configuration
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
Register the plugin and both payment providers in `medusa-config.ts`:
|
|
34
51
|
|
|
35
52
|
```ts
|
|
36
|
-
|
|
53
|
+
import { loadEnv, defineConfig } from "@medusajs/framework/utils"
|
|
54
|
+
|
|
55
|
+
loadEnv(process.env.NODE_ENV || "development", process.cwd())
|
|
56
|
+
|
|
57
|
+
export default defineConfig({
|
|
58
|
+
projectConfig: {
|
|
59
|
+
databaseUrl: process.env.DATABASE_URL,
|
|
60
|
+
http: {
|
|
61
|
+
storeCors: process.env.STORE_CORS!,
|
|
62
|
+
adminCors: process.env.ADMIN_CORS!,
|
|
63
|
+
authCors: process.env.AUTH_CORS!,
|
|
64
|
+
jwtSecret: process.env.JWT_SECRET || "supersecret",
|
|
65
|
+
cookieSecret: process.env.COOKIE_SECRET || "supersecret",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
|
|
37
69
|
plugins: [
|
|
38
70
|
{
|
|
39
71
|
resolve: "@easypayment/medusa-paypal",
|
|
@@ -49,10 +81,12 @@ module.exports = defineConfig({
|
|
|
49
81
|
{
|
|
50
82
|
resolve: "@easypayment/medusa-paypal/providers/paypal",
|
|
51
83
|
id: "paypal",
|
|
84
|
+
dependencies: ["paypal_onboarding"],
|
|
52
85
|
},
|
|
53
86
|
{
|
|
54
87
|
resolve: "@easypayment/medusa-paypal/providers/paypal_card",
|
|
55
88
|
id: "paypal_card",
|
|
89
|
+
dependencies: ["paypal_onboarding"],
|
|
56
90
|
},
|
|
57
91
|
],
|
|
58
92
|
},
|
|
@@ -61,80 +95,146 @@ module.exports = defineConfig({
|
|
|
61
95
|
})
|
|
62
96
|
```
|
|
63
97
|
|
|
64
|
-
|
|
98
|
+
---
|
|
65
99
|
|
|
66
|
-
|
|
100
|
+
## Environment Variables
|
|
101
|
+
|
|
102
|
+
Add the required variables to your backend `.env` file:
|
|
103
|
+
|
|
104
|
+
```env
|
|
105
|
+
STORE_CORS=http://localhost:8000,https://docs.medusajs.com
|
|
106
|
+
ADMIN_CORS=http://localhost:5173,http://localhost:9000,https://docs.medusajs.com
|
|
107
|
+
AUTH_CORS=http://localhost:5173,http://localhost:9000,http://localhost:8000,https://docs.medusajs.com
|
|
108
|
+
|
|
109
|
+
REDIS_URL=redis://localhost:6379
|
|
110
|
+
JWT_SECRET=supersecret
|
|
111
|
+
COOKIE_SECRET=supersecret
|
|
112
|
+
DATABASE_URL=postgres://postgres:root@localhost/medusa-medusa-backend
|
|
113
|
+
|
|
114
|
+
MEDUSA_ADMIN_ONBOARDING_TYPE=nextjs
|
|
115
|
+
MEDUSA_ADMIN_ONBOARDING_NEXTJS_DIRECTORY=medusa-backend-storefront
|
|
67
116
|
|
|
68
|
-
```bash
|
|
69
|
-
# required for API + onboarding defaults
|
|
70
|
-
PAYPAL_ENV=sandbox
|
|
71
117
|
PAYPAL_CURRENCY=EUR
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Start the Backend
|
|
123
|
+
|
|
124
|
+
Run your Medusa backend:
|
|
72
125
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
PAYPAL_CREDENTIALS_ENCRYPTION_KEY=your-32-byte-or-strong-secret
|
|
126
|
+
```bash
|
|
127
|
+
npm run dev
|
|
76
128
|
```
|
|
77
129
|
|
|
78
|
-
|
|
130
|
+
Then open Medusa Admin.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Admin Setup
|
|
79
135
|
|
|
80
|
-
|
|
136
|
+
After installation, configure PayPal from the Medusa Admin PayPal settings pages.
|
|
81
137
|
|
|
82
|
-
|
|
83
|
-
- Open Medusa Admin.
|
|
84
|
-
- Go to the PayPal settings pages.
|
|
138
|
+
### PayPal Wallet
|
|
85
139
|
|
|
86
|
-
|
|
140
|
+
Available settings include:
|
|
87
141
|
|
|
88
|
-
|
|
142
|
+
- `enabled`
|
|
143
|
+
- `title`
|
|
144
|
+
- `disableButtons`
|
|
145
|
+
- `buttonColor`
|
|
146
|
+
- `buttonShape`
|
|
147
|
+
- `buttonWidth`
|
|
148
|
+
- `buttonHeight`
|
|
149
|
+
- `buttonLabel`
|
|
89
150
|
|
|
90
|
-
|
|
151
|
+
### Advanced Card Payments
|
|
91
152
|
|
|
92
|
-
|
|
93
|
-
- `enabled`
|
|
94
|
-
- `title`
|
|
95
|
-
- `disableButtons`
|
|
96
|
-
- `buttonColor`, `buttonShape`, `buttonWidth`, `buttonHeight`, `buttonLabel`
|
|
97
|
-
- **Advanced Card Payments**
|
|
98
|
-
- `enabled`
|
|
99
|
-
- `title`
|
|
100
|
-
- `threeDS`
|
|
101
|
-
- **Additional Settings**
|
|
102
|
-
- `paymentAction` (`capture` or `authorize`)
|
|
103
|
-
- `brandName`
|
|
104
|
-
- `landingPage`
|
|
105
|
-
- `requireInstantPayment`
|
|
106
|
-
- `sendItemDetails`
|
|
107
|
-
- `invoicePrefix`
|
|
108
|
-
- `creditCardStatementName`
|
|
153
|
+
Available settings include:
|
|
109
154
|
|
|
110
|
-
|
|
155
|
+
- `enabled`
|
|
156
|
+
- `title`
|
|
157
|
+
- `threeDS`
|
|
111
158
|
|
|
112
|
-
|
|
159
|
+
### Additional Checkout Settings
|
|
113
160
|
|
|
114
|
-
|
|
115
|
-
- `pp_paypal_card_paypal_card`
|
|
161
|
+
Available settings include:
|
|
116
162
|
|
|
117
|
-
|
|
163
|
+
- `paymentAction` (`capture` or `authorize`)
|
|
164
|
+
- `brandName`
|
|
165
|
+
- `landingPage`
|
|
166
|
+
- `requireInstantPayment`
|
|
167
|
+
- `sendItemDetails`
|
|
168
|
+
- `invoicePrefix`
|
|
169
|
+
- `creditCardStatementName`
|
|
118
170
|
|
|
119
171
|
---
|
|
120
172
|
|
|
121
|
-
##
|
|
173
|
+
## Provider IDs
|
|
174
|
+
|
|
175
|
+
With the default configuration shown above, the generated Medusa provider IDs are:
|
|
176
|
+
|
|
177
|
+
```txt
|
|
178
|
+
pp_paypal_paypal
|
|
179
|
+
pp_paypal_card_paypal_card
|
|
180
|
+
```
|
|
122
181
|
|
|
123
|
-
|
|
124
|
-
- [ ] `medusa-config.ts` updated (plugin + both providers)
|
|
125
|
-
- [ ] Required env vars set
|
|
126
|
-
- [ ] PayPal credentials configured in Admin
|
|
127
|
-
- [ ] Storefront uses correct provider IDs
|
|
182
|
+
Use these exact provider IDs in your storefront unless you change the provider `id` values in `medusa-config.ts`.
|
|
128
183
|
|
|
129
184
|
---
|
|
130
185
|
|
|
131
|
-
##
|
|
186
|
+
## Storefront Usage
|
|
132
187
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
188
|
+
When creating a payment session, use one of the generated provider IDs.
|
|
189
|
+
|
|
190
|
+
Example for PayPal Wallet:
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
{
|
|
194
|
+
"provider_id": "pp_paypal_paypal"
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Example for PayPal Card:
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"provider_id": "pp_paypal_card_paypal_card"
|
|
203
|
+
}
|
|
136
204
|
```
|
|
137
205
|
|
|
206
|
+
Typical flow:
|
|
207
|
+
|
|
208
|
+
1. Create cart
|
|
209
|
+
2. Create payment collection
|
|
210
|
+
3. Create payment session with the selected provider ID
|
|
211
|
+
|
|
212
|
+
Example endpoint:
|
|
213
|
+
|
|
214
|
+
```http
|
|
215
|
+
POST /store/payment-collections/{id}/payment-sessions
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Example body:
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"provider_id": "pp_paypal_paypal"
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Quick Setup Checklist
|
|
229
|
+
|
|
230
|
+
- Install `@easypayment/medusa-paypal`
|
|
231
|
+
- Register the plugin in `medusa-config.ts`
|
|
232
|
+
- Register both payment providers
|
|
233
|
+
- Add required environment variables
|
|
234
|
+
- Start the Medusa backend
|
|
235
|
+
- Configure PayPal in Admin
|
|
236
|
+
- Use the correct provider IDs in the storefront
|
|
237
|
+
|
|
138
238
|
---
|
|
139
239
|
|
|
140
240
|
## License
|
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Migration } from "@mikro-orm/migrations"
|
|
2
|
+
|
|
3
|
+
export class Migration20270102090000 extends Migration {
|
|
4
|
+
override async up(): Promise<void> {
|
|
5
|
+
this.addSql(`alter table if exists "paypal_connection" add column if not exists "seller_email" text null;`)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
override async down(): Promise<void> {
|
|
9
|
+
this.addSql(`alter table if exists "paypal_connection" drop column if exists "seller_email";`)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { model } from "@medusajs/framework/utils"
|
|
2
|
-
|
|
3
|
-
const PayPalConnection = model.define("paypal_connection", {
|
|
4
|
-
id: model.id().primaryKey(),
|
|
5
|
-
|
|
6
|
-
environment: model.text(), // sandbox|live
|
|
7
|
-
status: model.text(), // disconnected|pending|pending_credentials|connected|revoked
|
|
8
|
-
|
|
9
|
-
shared_id: model.text().nullable(),
|
|
10
|
-
auth_code: model.text().nullable(),
|
|
11
|
-
|
|
12
|
-
seller_client_id: model.text().nullable(),
|
|
13
|
-
seller_client_secret: model.text().nullable(),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { model } from "@medusajs/framework/utils"
|
|
2
|
+
|
|
3
|
+
const PayPalConnection = model.define("paypal_connection", {
|
|
4
|
+
id: model.id().primaryKey(),
|
|
5
|
+
|
|
6
|
+
environment: model.text(), // sandbox|live
|
|
7
|
+
status: model.text(), // disconnected|pending|pending_credentials|connected|revoked
|
|
8
|
+
|
|
9
|
+
shared_id: model.text().nullable(),
|
|
10
|
+
auth_code: model.text().nullable(),
|
|
11
|
+
|
|
12
|
+
seller_client_id: model.text().nullable(),
|
|
13
|
+
seller_client_secret: model.text().nullable(),
|
|
14
|
+
seller_email: model.text().nullable(),
|
|
15
|
+
|
|
16
|
+
app_access_token: model.text().nullable(),
|
|
17
|
+
app_access_token_expires_at: model.dateTime().nullable(),
|
|
18
|
+
|
|
19
|
+
metadata: model.json().nullable(),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export default PayPalConnection
|