@easypayment/medusa-paypal 0.7.1 → 0.7.3
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 +6 -7
- package/.medusa/server/src/admin/index.mjs +6 -7
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +0 -4
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +0 -10
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +0 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +0 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +2 -4
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.js +1 -4
- package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.js +2 -13
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.js +0 -10
- package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js +2 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js +2 -2
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +0 -3
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +8 -4
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +0 -4
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.js +0 -4
- package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +11 -24
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +20 -5
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +2 -2
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts +0 -4
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +2 -4
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.js +0 -11
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
- package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal/index.js +0 -1
- package/.medusa/server/src/providers/paypal/index.js.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.js +0 -1
- package/.medusa/server/src/providers/paypal_card/index.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js +0 -16
- package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -1
- package/README.md +9 -22
- package/package.json +7 -4
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +0 -1
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +0 -1
- package/src/admin/routes/settings/paypal/connection/page.tsx +1 -49
- package/src/admin/routes/settings/paypal/page.tsx +13 -17
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +0 -2
- package/src/api/admin/paypal/onboard-complete/route.ts +34 -44
- package/src/api/admin/paypal/onboarding-status/route.ts +17 -18
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +0 -1
- package/src/api/store/paypal/capture-order/route.ts +3 -4
- package/src/api/store/paypal/config/route.ts +99 -102
- package/src/api/store/paypal/create-order/route.ts +3 -13
- package/src/api/store/paypal-complete/route.ts +0 -10
- package/src/modules/paypal/clients/paypal-seller.client.ts +62 -59
- package/src/modules/paypal/models/paypal_connection.ts +2 -2
- package/src/modules/paypal/payment-provider/card-service.ts +9 -4
- package/src/modules/paypal/payment-provider/index.ts +15 -19
- package/src/modules/paypal/payment-provider/service.ts +12 -24
- package/src/modules/paypal/service.ts +21 -5
- package/src/modules/paypal/types/config.ts +2 -2
- package/src/modules/paypal/utils/paypal-auth.ts +31 -32
- package/src/modules/paypal/webhook-processor.ts +0 -14
- package/src/providers/paypal/index.ts +8 -10
- package/src/providers/paypal_card/index.ts +8 -10
- package/src/subscribers/paypal-order-invoice.ts +0 -16
|
@@ -4,8 +4,6 @@ exports.config = void 0;
|
|
|
4
4
|
exports.default = paypalOrderInvoiceHandler;
|
|
5
5
|
const paypal_auth_1 = require("../modules/paypal/utils/paypal-auth");
|
|
6
6
|
const provider_ids_1 = require("../modules/paypal/utils/provider-ids");
|
|
7
|
-
// PayPal orders can only be PATCHed in CREATED or APPROVED status.
|
|
8
|
-
// Once COMPLETED (post-capture) the order is immutable.
|
|
9
7
|
const PATCHABLE_STATUSES = new Set(["CREATED", "APPROVED", "SAVED"]);
|
|
10
8
|
async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
11
9
|
const orderId = event?.data?.id;
|
|
@@ -14,7 +12,6 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
14
12
|
try {
|
|
15
13
|
const query = container.resolve("query");
|
|
16
14
|
const paypal = container.resolve("paypal_onboarding");
|
|
17
|
-
// Fetch the Medusa order with payment session data
|
|
18
15
|
const { data: orders } = await query.graph({
|
|
19
16
|
entity: "order",
|
|
20
17
|
fields: [
|
|
@@ -31,7 +28,6 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
31
28
|
const order = orders?.[0];
|
|
32
29
|
if (!order)
|
|
33
30
|
return;
|
|
34
|
-
// Find the PayPal payment session
|
|
35
31
|
const sessions = (order.payment_collections || []).flatMap((pc) => pc.payment_sessions || []);
|
|
36
32
|
const paypalSession = sessions
|
|
37
33
|
.filter((s) => (0, provider_ids_1.isPayPalProviderId)(s.provider_id))
|
|
@@ -47,7 +43,6 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
47
43
|
console.info("[PayPal] invoice subscriber: no order_id in session for order", orderId);
|
|
48
44
|
return;
|
|
49
45
|
}
|
|
50
|
-
// Build the target invoice_id using display_id (ideal format)
|
|
51
46
|
const settings = await paypal.getSettings().catch(() => ({}));
|
|
52
47
|
const settingsData = settings && typeof settings === "object" && "data" in settings
|
|
53
48
|
? (settings.data ?? {})
|
|
@@ -60,13 +55,8 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
60
55
|
const invoiceId = `${invoicePrefix}${displayId}`.trim();
|
|
61
56
|
if (!invoiceId)
|
|
62
57
|
return;
|
|
63
|
-
// Get PayPal access token
|
|
64
58
|
const creds = await paypal.getActiveCredentials();
|
|
65
59
|
const { accessToken, base } = await (0, paypal_auth_1.getPayPalAccessToken)(creds);
|
|
66
|
-
// Check PayPal order status before attempting PATCH.
|
|
67
|
-
// PayPal only allows PATCH on CREATED or APPROVED orders.
|
|
68
|
-
// COMPLETED orders (post-capture) are immutable, so skip PATCH and
|
|
69
|
-
// log the reconciliation mapping instead.
|
|
70
60
|
let paypalOrderStatus = "";
|
|
71
61
|
let currentInvoiceId = "";
|
|
72
62
|
try {
|
|
@@ -80,7 +70,6 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
80
70
|
catch (e) {
|
|
81
71
|
console.warn("[PayPal] invoice subscriber: order status fetch failed:", e?.message);
|
|
82
72
|
}
|
|
83
|
-
// Always log the display_id -> paypalOrderId mapping for reconciliation
|
|
84
73
|
console.info("[PayPal] invoice reconciliation mapping:", {
|
|
85
74
|
medusaOrderId: orderId,
|
|
86
75
|
displayId,
|
|
@@ -89,18 +78,14 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
89
78
|
paypalOrderStatus,
|
|
90
79
|
currentInvoiceId,
|
|
91
80
|
});
|
|
92
|
-
// If order is COMPLETED, invoice_id is immutable — skip PATCH
|
|
93
81
|
if (paypalOrderStatus && !PATCHABLE_STATUSES.has(paypalOrderStatus)) {
|
|
94
82
|
console.info(`[PayPal] invoice_id PATCH skipped — order status is ${paypalOrderStatus} (immutable).`, `Reconcile via: PayPal order ${paypalOrderId} = Medusa order #${displayId}`);
|
|
95
83
|
return;
|
|
96
84
|
}
|
|
97
|
-
// If invoice_id already matches target, skip PATCH
|
|
98
85
|
if (currentInvoiceId === invoiceId) {
|
|
99
86
|
console.info(`[PayPal] invoice_id already "${invoiceId}" — skipping PATCH`);
|
|
100
87
|
return;
|
|
101
88
|
}
|
|
102
|
-
// Attempt PATCH only for CREATED/APPROVED orders.
|
|
103
|
-
// This handles the authorize-only flow where capture hasn't happened yet.
|
|
104
89
|
const patchResp = await fetch(`${base}/v2/checkout/orders/${paypalOrderId}`, {
|
|
105
90
|
method: "PATCH",
|
|
106
91
|
headers: {
|
|
@@ -130,7 +115,6 @@ async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
|
130
115
|
}
|
|
131
116
|
}
|
|
132
117
|
catch (e) {
|
|
133
|
-
// Non-fatal — never block order placement
|
|
134
118
|
console.warn("[PayPal] paypalOrderInvoiceHandler error:", e?.message || e);
|
|
135
119
|
}
|
|
136
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-order-invoice.js","sourceRoot":"","sources":["../../../../src/subscribers/paypal-order-invoice.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"paypal-order-invoice.js","sourceRoot":"","sources":["../../../../src/subscribers/paypal-order-invoice.ts"],"names":[],"mappings":";;;AAOA,4CA+JC;AApKD,qEAA0E;AAC1E,uEAAyE;AAEzE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AAErD,KAAK,UAAU,yBAAyB,CAAC,EACtD,KAAK,EACL,SAAS,GACsB;IAC/B,MAAM,OAAO,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAA;IAC/B,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAQ,CAAA;QAC/C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;QAE1E,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;YACzC,MAAM,EAAE,OAA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QAED,IAAI,SAAS,CAAC,EAAE,IAAI,SAAS,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC7C,OAAO,CAAC,IAAI,CACV,mCAAmC,SAAS,GAAG,EAC/C,iBAAiB,aAAa,cAAc,SAAS,GAAG,CACzD,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;YACtD,OAAO,CAAC,IAAI,CAAC,kCAAkC,EAAE;gBAC/C,MAAM,EAAE,SAAS,CAAC,MAAM;gBACxB,aAAa;gBACb,SAAS;gBACT,iBAAiB;gBACjB,OAAO;aACR,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,2CAA2C,EAAE,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC;AAEY,QAAA,MAAM,GAAqB;IACtC,KAAK,EAAE,cAAc;CACtB,CAAA"}
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<h1
|
|
3
|
+
<h1>PayPal for Medusa</h1>
|
|
4
4
|
|
|
5
|
-
<p><strong>PayPal payment plugin for Medusa
|
|
5
|
+
<p><strong>PayPal payment plugin for Medusa</strong></p>
|
|
6
6
|
|
|
7
7
|
<p>
|
|
8
8
|
<a href="https://www.npmjs.com/package/@easypayment/medusa-paypal"><img src="https://img.shields.io/npm/v/@easypayment/medusa-paypal?color=blue&label=npm" alt="npm version" /></a>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<a href="https://developer.paypal.com"><img src="https://img.shields.io/badge/PayPal-PPCP-003087" alt="PayPal PPCP" /></a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
<p>
|
|
14
|
+
<p>PayPal, Credit/Debit Cards, Venmo, SEPA, iDEAL, Mercado Pago, Bancontact & more - by an official PayPal Partner</p>
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
@@ -89,20 +89,7 @@ export default defineConfig({
|
|
|
89
89
|
|
|
90
90
|
---
|
|
91
91
|
|
|
92
|
-
## Step 3 —
|
|
93
|
-
|
|
94
|
-
Add these to your Medusa server `.env`:
|
|
95
|
-
|
|
96
|
-
```env
|
|
97
|
-
# Required
|
|
98
|
-
MEDUSA_BACKEND_URL=https://your-medusa-server.com
|
|
99
|
-
STOREFRONT_URL=https://your-storefront.com
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Step 4 — Run database migrations
|
|
92
|
+
## Step 3 — Run database migrations
|
|
106
93
|
|
|
107
94
|
```bash
|
|
108
95
|
npx medusa db:migrate
|
|
@@ -110,7 +97,7 @@ npx medusa db:migrate
|
|
|
110
97
|
|
|
111
98
|
---
|
|
112
99
|
|
|
113
|
-
## Step
|
|
100
|
+
## Step 4 — Connect your PayPal account
|
|
114
101
|
|
|
115
102
|
1. Start your Medusa server
|
|
116
103
|
2. Open Medusa Admin → **Settings → PayPal → PayPal Connection**
|
|
@@ -121,7 +108,7 @@ Credentials are saved automatically. To connect manually instead, click **Insert
|
|
|
121
108
|
|
|
122
109
|
---
|
|
123
110
|
|
|
124
|
-
## Step
|
|
111
|
+
## Step 5 — Enable providers in your region
|
|
125
112
|
|
|
126
113
|
1. Medusa Admin → **Settings → Regions → [your region]**
|
|
127
114
|
2. Under **Payment Providers**, enable:
|
|
@@ -130,7 +117,7 @@ Credentials are saved automatically. To connect manually instead, click **Insert
|
|
|
130
117
|
|
|
131
118
|
---
|
|
132
119
|
|
|
133
|
-
## Step
|
|
120
|
+
## Step 6 — Configure settings (optional)
|
|
134
121
|
|
|
135
122
|
All settings are in Medusa Admin → **Settings → PayPal** and take effect immediately with no server restart.
|
|
136
123
|
|
|
@@ -142,7 +129,7 @@ All settings are in Medusa Admin → **Settings → PayPal** and take effect imm
|
|
|
142
129
|
|
|
143
130
|
---
|
|
144
131
|
|
|
145
|
-
## Step
|
|
132
|
+
## Step 7 — Connect the frontend package
|
|
146
133
|
|
|
147
134
|
Install the storefront UI package to render PayPal at checkout:
|
|
148
135
|
|
|
@@ -150,6 +137,6 @@ Install the storefront UI package to render PayPal at checkout:
|
|
|
150
137
|
npm install @easypayment/medusa-paypal-ui
|
|
151
138
|
```
|
|
152
139
|
|
|
153
|
-
See the [medusa-paypal-frontend README](
|
|
140
|
+
See the [medusa-paypal-frontend README](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui) for integration steps.
|
|
154
141
|
|
|
155
142
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easypayment/medusa-paypal",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Industry-standard PayPal integration for Medusa v2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./.medusa/server/src/index.js",
|
|
@@ -66,11 +66,14 @@
|
|
|
66
66
|
"url": "https://github.com/easypayment/medusa-paypal.git"
|
|
67
67
|
},
|
|
68
68
|
"keywords": [
|
|
69
|
-
"medusa
|
|
69
|
+
"medusa",
|
|
70
70
|
"medusa-v2",
|
|
71
|
+
"medusa-plugin",
|
|
71
72
|
"medusa-plugin-integration",
|
|
72
73
|
"medusa-plugin-payment",
|
|
73
|
-
"paypal",
|
|
74
|
-
"
|
|
74
|
+
"medusa-paypal-payment",
|
|
75
|
+
"medusa-paypal-plugin",
|
|
76
|
+
"medusa-paypal-integration",
|
|
77
|
+
"medusa-paypal"
|
|
75
78
|
]
|
|
76
79
|
}
|
|
@@ -105,7 +105,6 @@ export default function AdvancedCardPaymentsTab() {
|
|
|
105
105
|
const saved = payload?.advanced_card_payments
|
|
106
106
|
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved))
|
|
107
107
|
} catch {
|
|
108
|
-
// use defaults
|
|
109
108
|
} finally {
|
|
110
109
|
setLoading(false)
|
|
111
110
|
}
|
|
@@ -14,11 +14,7 @@ export const config = defineRouteConfig({
|
|
|
14
14
|
hide: true,
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
/* ------------------------------------------------------------------ */
|
|
18
|
-
/* HIGH PRIORITY EXECUTION - RUNS BEFORE COMPONENT MOUNTS */
|
|
19
|
-
/* ------------------------------------------------------------------ */
|
|
20
17
|
|
|
21
|
-
// 1. Inject Preload Link IMMEDIATELY
|
|
22
18
|
if (typeof window !== "undefined") {
|
|
23
19
|
const preloadHref =
|
|
24
20
|
"https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js"
|
|
@@ -34,7 +30,6 @@ if (typeof window !== "undefined") {
|
|
|
34
30
|
document.head.appendChild(preloadLink)
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
// 2. Inject PayPal Script IMMEDIATELY (before React renders)
|
|
38
33
|
const existingScript = document.getElementById(
|
|
39
34
|
"paypal-partner-js"
|
|
40
35
|
) as HTMLScriptElement | null
|
|
@@ -53,7 +48,6 @@ declare global {
|
|
|
53
48
|
apps?: {
|
|
54
49
|
Signup?: {
|
|
55
50
|
miniBrowser?: { init: () => void }
|
|
56
|
-
// some partner.js builds expose MiniBrowser (capital M)
|
|
57
51
|
MiniBrowser?: { closeFlow?: () => void }
|
|
58
52
|
}
|
|
59
53
|
}
|
|
@@ -62,20 +56,17 @@ declare global {
|
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
// Partner.js is now loaded lazily only when needed (removed global injection)
|
|
66
59
|
|
|
67
60
|
const SERVICE_URL = "/admin/paypal/onboarding-link"
|
|
68
61
|
const CACHE_KEY = "pp_onboard_cache"
|
|
69
62
|
const RELOAD_KEY = "pp_onboard_reloaded_once"
|
|
70
|
-
const CACHE_EXPIRY = 10 * 60 * 1000
|
|
63
|
+
const CACHE_EXPIRY = 10 * 60 * 1000
|
|
71
64
|
|
|
72
|
-
// ✅ backend endpoint to exchange authCode/sharedId (medusa)
|
|
73
65
|
const ONBOARDING_COMPLETE_ENDPOINT = "/admin/paypal/onboard-complete"
|
|
74
66
|
const STATUS_ENDPOINT = "/admin/paypal/status"
|
|
75
67
|
const SAVE_CREDENTIALS_ENDPOINT = "/admin/paypal/save-credentials"
|
|
76
68
|
const DISCONNECT_ENDPOINT = "/admin/paypal/disconnect"
|
|
77
69
|
|
|
78
|
-
// 3. Immediate Cache Check (runs before React component)
|
|
79
70
|
let cachedUrl: string | null = null
|
|
80
71
|
if (typeof window !== "undefined") {
|
|
81
72
|
try {
|
|
@@ -91,14 +82,10 @@ if (typeof window !== "undefined") {
|
|
|
91
82
|
}
|
|
92
83
|
}
|
|
93
84
|
|
|
94
|
-
/* ------------------------------------------------------------------ */
|
|
95
|
-
/* REACT COMPONENT */
|
|
96
|
-
/* ------------------------------------------------------------------ */
|
|
97
85
|
|
|
98
86
|
export default function PayPalConnectionPage() {
|
|
99
87
|
const [env, setEnv] = useState<"sandbox" | "live">("live")
|
|
100
88
|
|
|
101
|
-
// Sync initial environment from backend
|
|
102
89
|
useEffect(() => {
|
|
103
90
|
fetch("/admin/paypal/environment", { method: "GET" })
|
|
104
91
|
.then((r) => r.json())
|
|
@@ -122,7 +109,6 @@ export default function PayPalConnectionPage() {
|
|
|
122
109
|
seller_email?: string | null
|
|
123
110
|
} | null>(null)
|
|
124
111
|
|
|
125
|
-
// ✅ onboarding in progress (for disabling UI)
|
|
126
112
|
const [onboardingInProgress, setOnboardingInProgress] = useState(false)
|
|
127
113
|
|
|
128
114
|
const initLoaderRef = useRef<HTMLDivElement>(null)
|
|
@@ -131,7 +117,6 @@ export default function PayPalConnectionPage() {
|
|
|
131
117
|
const runIdRef = useRef(0)
|
|
132
118
|
const currentRunId = useRef(0)
|
|
133
119
|
|
|
134
|
-
// Measure PayPal button width for OR centering (Woo-style)
|
|
135
120
|
const ppBtnMeasureRef = useRef<HTMLAnchorElement | null>(null)
|
|
136
121
|
const [ppBtnWidth, setPpBtnWidth] = useState<number | null>(null)
|
|
137
122
|
|
|
@@ -139,7 +124,6 @@ export default function PayPalConnectionPage() {
|
|
|
139
124
|
return clientId.trim().length > 0 && secret.trim().length > 0
|
|
140
125
|
}, [clientId, secret])
|
|
141
126
|
|
|
142
|
-
// Exact copy of fetchFreshLink from original JS (+ reload-once logic ONLY)
|
|
143
127
|
const fetchFreshLink = useCallback(
|
|
144
128
|
(runId: number) => {
|
|
145
129
|
if (initLoaderRef.current) {
|
|
@@ -192,7 +176,6 @@ export default function PayPalConnectionPage() {
|
|
|
192
176
|
[env]
|
|
193
177
|
)
|
|
194
178
|
|
|
195
|
-
// Exact copy of showUI from original JS (safe: only init when button exists)
|
|
196
179
|
const showUI = useCallback(() => {
|
|
197
180
|
const btn = document.querySelector('[data-paypal-button="true"]')
|
|
198
181
|
if (btn && window.PAYPAL?.apps?.Signup?.miniBrowser?.init) {
|
|
@@ -201,13 +184,11 @@ export default function PayPalConnectionPage() {
|
|
|
201
184
|
setConnState("ready")
|
|
202
185
|
}, [])
|
|
203
186
|
|
|
204
|
-
// Exact copy of showError from original JS
|
|
205
187
|
const showError = useCallback((msg: string) => {
|
|
206
188
|
setConnState("error")
|
|
207
189
|
setError(msg)
|
|
208
190
|
}, [])
|
|
209
191
|
|
|
210
|
-
// activatePayPal (keeps PayPal partner.js global injection; waits for PAYPAL then inits)
|
|
211
192
|
const activatePayPal = useCallback(
|
|
212
193
|
(url: string, runId: number) => {
|
|
213
194
|
if (paypalButtonRef.current) {
|
|
@@ -221,7 +202,6 @@ export default function PayPalConnectionPage() {
|
|
|
221
202
|
showUI()
|
|
222
203
|
return
|
|
223
204
|
}
|
|
224
|
-
// wait briefly for partner.js to finish loading
|
|
225
205
|
setTimeout(tryInit, 50)
|
|
226
206
|
}
|
|
227
207
|
|
|
@@ -230,7 +210,6 @@ export default function PayPalConnectionPage() {
|
|
|
230
210
|
[showUI]
|
|
231
211
|
)
|
|
232
212
|
|
|
233
|
-
// Initialize - runs on mount and env change
|
|
234
213
|
useEffect(() => {
|
|
235
214
|
currentRunId.current = ++runIdRef.current
|
|
236
215
|
const runId = currentRunId.current
|
|
@@ -242,7 +221,6 @@ export default function PayPalConnectionPage() {
|
|
|
242
221
|
setError(null)
|
|
243
222
|
setFinalUrl("")
|
|
244
223
|
|
|
245
|
-
// 1) If already connected in DB, don't ask to onboard again
|
|
246
224
|
try {
|
|
247
225
|
const r = await fetch(`${STATUS_ENDPOINT}?environment=${env}`, {
|
|
248
226
|
method: "GET",
|
|
@@ -262,13 +240,10 @@ export default function PayPalConnectionPage() {
|
|
|
262
240
|
return
|
|
263
241
|
}
|
|
264
242
|
} catch (e) {
|
|
265
|
-
// ignore status errors; proceed with onboarding
|
|
266
243
|
console.error(e)
|
|
267
244
|
}
|
|
268
245
|
|
|
269
|
-
// 2) Not connected -> continue onboarding flow
|
|
270
246
|
if (cachedUrl) {
|
|
271
|
-
console.log("Using prioritized cache...")
|
|
272
247
|
activatePayPal(cachedUrl, runId)
|
|
273
248
|
} else {
|
|
274
249
|
fetchFreshLink(runId)
|
|
@@ -283,20 +258,16 @@ export default function PayPalConnectionPage() {
|
|
|
283
258
|
}
|
|
284
259
|
}, [env, fetchFreshLink, activatePayPal])
|
|
285
260
|
|
|
286
|
-
// ✅ setupOnboarding() behavior (Woo-style) inside callback
|
|
287
261
|
useLayoutEffect(() => {
|
|
288
262
|
window.onboardingCallback = async function (authCode: string, sharedId: string) {
|
|
289
|
-
// Woo sets this; keep safe
|
|
290
263
|
try {
|
|
291
264
|
;(window as any).onbeforeunload = ""
|
|
292
265
|
} catch {}
|
|
293
266
|
|
|
294
|
-
// show blocking state (no new UI components, just disable + loader text)
|
|
295
267
|
setOnboardingInProgress(true)
|
|
296
268
|
setConnState("loading")
|
|
297
269
|
setError(null)
|
|
298
270
|
|
|
299
|
-
// post to backend (authCode/sharedId/env)
|
|
300
271
|
const payload = {
|
|
301
272
|
authCode,
|
|
302
273
|
sharedId,
|
|
@@ -315,7 +286,6 @@ export default function PayPalConnectionPage() {
|
|
|
315
286
|
throw new Error(txt || `Onboarding exchange failed (${res.status})`)
|
|
316
287
|
}
|
|
317
288
|
|
|
318
|
-
// ✅ ONLY NOW close the mini-browser flow
|
|
319
289
|
try {
|
|
320
290
|
const close1 = window.PAYPAL?.apps?.Signup?.MiniBrowser?.closeFlow
|
|
321
291
|
if (typeof close1 === "function") close1()
|
|
@@ -327,13 +297,11 @@ export default function PayPalConnectionPage() {
|
|
|
327
297
|
if (typeof close2 === "function") close2()
|
|
328
298
|
} catch {}
|
|
329
299
|
|
|
330
|
-
// clear cache so next run fetches new url
|
|
331
300
|
try {
|
|
332
301
|
localStorage.removeItem(CACHE_KEY)
|
|
333
302
|
localStorage.removeItem(RELOAD_KEY)
|
|
334
303
|
} catch {}
|
|
335
304
|
|
|
336
|
-
// Woo does: window.location.href = window.location.href;
|
|
337
305
|
window.location.href = window.location.href
|
|
338
306
|
} catch (e: any) {
|
|
339
307
|
console.error(e)
|
|
@@ -348,7 +316,6 @@ export default function PayPalConnectionPage() {
|
|
|
348
316
|
}
|
|
349
317
|
}, [env])
|
|
350
318
|
|
|
351
|
-
// Measure PayPal button width (for OR centering under button)
|
|
352
319
|
useLayoutEffect(() => {
|
|
353
320
|
const el = ppBtnMeasureRef.current
|
|
354
321
|
if (!el) return
|
|
@@ -451,7 +418,6 @@ export default function PayPalConnectionPage() {
|
|
|
451
418
|
localStorage.removeItem(RELOAD_KEY)
|
|
452
419
|
} catch {}
|
|
453
420
|
|
|
454
|
-
// Restart onboarding link generation for current env
|
|
455
421
|
currentRunId.current = ++runIdRef.current
|
|
456
422
|
const runId = currentRunId.current
|
|
457
423
|
fetchFreshLink(runId)
|
|
@@ -488,13 +454,10 @@ export default function PayPalConnectionPage() {
|
|
|
488
454
|
<div className="flex flex-col gap-6">
|
|
489
455
|
<h1 className="text-xl font-semibold">PayPal Gateway By Easy Payment</h1>
|
|
490
456
|
|
|
491
|
-
{/* Tabs header */}
|
|
492
457
|
<PayPalTabs />
|
|
493
458
|
|
|
494
|
-
{/* Main container */}
|
|
495
459
|
<div className="rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm">
|
|
496
460
|
<div className="grid grid-cols-1 gap-y-6 p-4 md:grid-cols-[260px_1fr] md:items-start">
|
|
497
|
-
{/* Environment */}
|
|
498
461
|
<div className="text-sm font-medium pt-2">Environment</div>
|
|
499
462
|
<div className="max-w-xl">
|
|
500
463
|
<select
|
|
@@ -508,7 +471,6 @@ export default function PayPalConnectionPage() {
|
|
|
508
471
|
</select>
|
|
509
472
|
</div>
|
|
510
473
|
|
|
511
|
-
{/* Connect */}
|
|
512
474
|
<div className="text-sm font-medium pt-2">
|
|
513
475
|
{env === "sandbox" ? "Connect to PayPal (Sandbox)" : "Connect to PayPal"}
|
|
514
476
|
</div>
|
|
@@ -518,7 +480,6 @@ export default function PayPalConnectionPage() {
|
|
|
518
480
|
<div>
|
|
519
481
|
<div className="text-sm text-green-600 bg-green-50 p-3 rounded border border-green-200">
|
|
520
482
|
✅ Successfully connected to PayPal!
|
|
521
|
-
{/* Hidden PayPal button anchor to satisfy partner.js DOM expectations */}
|
|
522
483
|
<a
|
|
523
484
|
data-paypal-button="true"
|
|
524
485
|
data-paypal-onboard-complete="onboardingCallback"
|
|
@@ -552,7 +513,6 @@ export default function PayPalConnectionPage() {
|
|
|
552
513
|
</div>
|
|
553
514
|
) : (
|
|
554
515
|
<>
|
|
555
|
-
{/* Status Loader */}
|
|
556
516
|
<div
|
|
557
517
|
ref={initLoaderRef}
|
|
558
518
|
id="init-loader"
|
|
@@ -568,9 +528,7 @@ export default function PayPalConnectionPage() {
|
|
|
568
528
|
</span>
|
|
569
529
|
</div>
|
|
570
530
|
|
|
571
|
-
{/* PayPal Button */}
|
|
572
531
|
<div className={`${connState === "ready" ? "block" : "hidden"}`}>
|
|
573
|
-
{/* Row 1: button (left aligned) */}
|
|
574
532
|
<a
|
|
575
533
|
ref={(node) => {
|
|
576
534
|
paypalButtonRef.current = node
|
|
@@ -591,7 +549,6 @@ export default function PayPalConnectionPage() {
|
|
|
591
549
|
Connect to PayPal
|
|
592
550
|
</a>
|
|
593
551
|
|
|
594
|
-
{/* Row 2: OR centered under button width */}
|
|
595
552
|
<div
|
|
596
553
|
className="mt-2"
|
|
597
554
|
style={{
|
|
@@ -607,7 +564,6 @@ export default function PayPalConnectionPage() {
|
|
|
607
564
|
</div>
|
|
608
565
|
</div>
|
|
609
566
|
|
|
610
|
-
{/* Row 3: manual link aligned to button LEFT */}
|
|
611
567
|
<div className="mt-1">
|
|
612
568
|
<button
|
|
613
569
|
type="button"
|
|
@@ -620,7 +576,6 @@ export default function PayPalConnectionPage() {
|
|
|
620
576
|
</div>
|
|
621
577
|
</div>
|
|
622
578
|
|
|
623
|
-
{/* If not ready yet, show manual link still */}
|
|
624
579
|
<div className={`${connState === "ready" ? "hidden" : "block"} mt-3`}>
|
|
625
580
|
<button
|
|
626
581
|
type="button"
|
|
@@ -632,7 +587,6 @@ export default function PayPalConnectionPage() {
|
|
|
632
587
|
</button>
|
|
633
588
|
</div>
|
|
634
589
|
|
|
635
|
-
{/* Error Log */}
|
|
636
590
|
<div
|
|
637
591
|
ref={errorLogRef}
|
|
638
592
|
id="error-log"
|
|
@@ -646,7 +600,6 @@ export default function PayPalConnectionPage() {
|
|
|
646
600
|
)}
|
|
647
601
|
</div>
|
|
648
602
|
|
|
649
|
-
{/* Manual credentials section */}
|
|
650
603
|
{showManual && (
|
|
651
604
|
<div className="md:col-span-2">
|
|
652
605
|
<div className="ml-[260px] max-w-xl mt-4 grid grid-cols-1 gap-3 md:grid-cols-2">
|
|
@@ -724,7 +677,6 @@ export default function PayPalConnectionPage() {
|
|
|
724
677
|
</div>
|
|
725
678
|
</div>
|
|
726
679
|
|
|
727
|
-
{/* Loader styles */}
|
|
728
680
|
<style>{`
|
|
729
681
|
.loader {
|
|
730
682
|
border: 3px solid #f3f3f3;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import { defineRouteConfig } from "@medusajs/admin-sdk"
|
|
3
|
-
import { Navigate } from "react-router-dom"
|
|
4
|
-
|
|
5
|
-
export const config = defineRouteConfig({
|
|
6
|
-
label: "PayPal",
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return <Navigate to="connection" replace />
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default PayPalSettingsIndexRoute
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { defineRouteConfig } from "@medusajs/admin-sdk"
|
|
3
|
+
import { Navigate } from "react-router-dom"
|
|
4
|
+
|
|
5
|
+
export const config = defineRouteConfig({
|
|
6
|
+
label: "PayPal",
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
const PayPalSettingsIndexRoute = () => {
|
|
10
|
+
return <Navigate to="connection" replace />
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default PayPalSettingsIndexRoute
|
|
@@ -159,7 +159,6 @@ export default function PayPalSettingsTab() {
|
|
|
159
159
|
}))
|
|
160
160
|
}
|
|
161
161
|
} catch {
|
|
162
|
-
// Silently ignore load errors — the form will use defaults
|
|
163
162
|
} finally {
|
|
164
163
|
setLoading(false)
|
|
165
164
|
}
|
|
@@ -268,7 +267,6 @@ export default function PayPalSettingsTab() {
|
|
|
268
267
|
</div>
|
|
269
268
|
</SectionCard>
|
|
270
269
|
|
|
271
|
-
{/* Button Appearance */}
|
|
272
270
|
<SectionCard
|
|
273
271
|
title="Button Appearance"
|
|
274
272
|
description="Control PayPal Smart Button styling (color/shape/size/label)."
|
|
@@ -1,44 +1,34 @@
|
|
|
1
|
-
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
-
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return res.json({ ok: true })
|
|
38
|
-
} catch (e: any) {
|
|
39
|
-
console.error("[PayPal] onboard-complete failed", e)
|
|
40
|
-
return res.status(500).json({
|
|
41
|
-
message: e?.message || "Failed to exchange and save PayPal credentials",
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
+
|
|
4
|
+
export async function GET(_req: MedusaRequest, res: MedusaResponse) {
|
|
5
|
+
return res.status(405).json({
|
|
6
|
+
message:
|
|
7
|
+
"Method Not Allowed. Use POST with JSON: { authCode, sharedId, env }. This endpoint is called by the PayPal onboarding callback.",
|
|
8
|
+
})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
12
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
13
|
+
const body = req.body as { authCode?: string; sharedId?: string; env?: "sandbox" | "live" }
|
|
14
|
+
|
|
15
|
+
if (!body?.authCode || !body?.sharedId) {
|
|
16
|
+
return res.status(400).json({ message: "Missing authCode/sharedId" })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
|
|
21
|
+
await paypal.exchangeAndSaveSellerCredentials({
|
|
22
|
+
authCode: body.authCode,
|
|
23
|
+
sharedId: body.sharedId,
|
|
24
|
+
env: body.env,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return res.json({ ok: true })
|
|
28
|
+
} catch (e: any) {
|
|
29
|
+
console.error("[PayPal] onboard-complete failed", e)
|
|
30
|
+
return res.status(500).json({
|
|
31
|
+
message: e?.message || "Failed to exchange and save PayPal credentials",
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|