@easypayment/medusa-paypal-ui 1.0.41 → 1.0.43

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/dist/index.cjs CHANGED
@@ -184,6 +184,21 @@ var BUTTON_WIDTH_MAP = {
184
184
  large: "500px",
185
185
  responsive: "100%"
186
186
  };
187
+ async function markPaymentComplete(baseUrl, cartId, publishableApiKey) {
188
+ try {
189
+ await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
190
+ method: "POST",
191
+ headers: {
192
+ "Content-Type": "application/json",
193
+ ...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
194
+ },
195
+ body: JSON.stringify({ cart_id: cartId }),
196
+ credentials: "include"
197
+ });
198
+ } catch (e) {
199
+ console.warn("[PayPal] paypal-complete call failed:", e);
200
+ }
201
+ }
187
202
  function PayPalSmartButtons(props) {
188
203
  const { baseUrl, publishableApiKey, cartId, config, onPaid, onError } = props;
189
204
  const api = react.useMemo(
@@ -194,149 +209,147 @@ function PayPalSmartButtons(props) {
194
209
  const [processing, setProcessing] = react.useState(false);
195
210
  if (!config.currency_supported) return null;
196
211
  const containerWidth = BUTTON_WIDTH_MAP[config.button_width ?? "responsive"] ?? "100%";
197
- return (
198
- // ── CHANGED: added position: relative so the overlay can sit on top ──────
199
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { width: containerWidth, position: "relative" }, children: [
200
- /* @__PURE__ */ jsxRuntime.jsx("style", { children: SPIN_STYLE }),
201
- processing && /* @__PURE__ */ jsxRuntime.jsxs(
202
- "div",
203
- {
204
- style: {
205
- position: "absolute",
206
- inset: 0,
207
- zIndex: 10,
208
- background: "rgba(255,255,255,0.90)",
209
- borderRadius: 8,
210
- display: "flex",
211
- flexDirection: "column",
212
- alignItems: "center",
213
- justifyContent: "center",
214
- gap: 10,
215
- minHeight: 60
216
- },
217
- children: [
218
- /* @__PURE__ */ jsxRuntime.jsx(
219
- "div",
220
- {
221
- style: {
222
- width: 28,
223
- height: 28,
224
- borderRadius: "50%",
225
- border: "2.5px solid #e5e7eb",
226
- borderTopColor: "#0070ba",
227
- animation: "_pp_spin .7s linear infinite"
228
- }
229
- }
230
- ),
231
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center" }, children: [
232
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, color: "#374151", fontWeight: 500 }, children: "Processing your payment\u2026" }),
233
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
234
- ] })
235
- ]
236
- }
237
- ),
238
- config.environment === "sandbox" && /* @__PURE__ */ jsxRuntime.jsxs(
239
- "div",
240
- {
241
- style: {
242
- display: "flex",
243
- alignItems: "flex-start",
244
- gap: 8,
245
- padding: "10px 14px",
246
- background: "#eff6ff",
247
- border: "1px solid #bfdbfe",
248
- borderRadius: 8,
249
- fontSize: 13,
250
- color: "#1e40af",
251
- lineHeight: 1.5,
252
- marginBottom: 10
253
- },
254
- children: [
255
- /* @__PURE__ */ jsxRuntime.jsxs(
256
- "svg",
257
- {
258
- width: "16",
259
- height: "16",
260
- viewBox: "0 0 24 24",
261
- fill: "none",
262
- stroke: "#1e40af",
263
- strokeWidth: "2",
264
- strokeLinecap: "round",
265
- style: { flexShrink: 0, marginTop: 1 },
266
- children: [
267
- /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
268
- /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 8v4M12 16h.01" })
269
- ]
212
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { width: containerWidth, position: "relative" }, children: [
213
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: SPIN_STYLE }),
214
+ processing && /* @__PURE__ */ jsxRuntime.jsxs(
215
+ "div",
216
+ {
217
+ style: {
218
+ position: "absolute",
219
+ inset: 0,
220
+ zIndex: 10,
221
+ background: "rgba(255,255,255,0.90)",
222
+ borderRadius: 8,
223
+ display: "flex",
224
+ flexDirection: "column",
225
+ alignItems: "center",
226
+ justifyContent: "center",
227
+ gap: 10,
228
+ minHeight: 60
229
+ },
230
+ children: [
231
+ /* @__PURE__ */ jsxRuntime.jsx(
232
+ "div",
233
+ {
234
+ style: {
235
+ width: 28,
236
+ height: 28,
237
+ borderRadius: "50%",
238
+ border: "2.5px solid #e5e7eb",
239
+ borderTopColor: "#0070ba",
240
+ animation: "_pp_spin .7s linear infinite"
270
241
  }
271
- ),
272
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Sandbox mode \u2014 you will not be charged. Use your PayPal sandbox account to complete the payment." })
273
- ]
274
- }
275
- ),
276
- /* @__PURE__ */ jsxRuntime.jsx(
277
- reactPaypalJs.PayPalButtons,
278
- {
279
- style: {
280
- layout: "vertical",
281
- color: config.button_color,
282
- shape: config.button_shape,
283
- label: config.button_label,
284
- height: config.button_height
285
- },
286
- createOrder: async () => {
287
- setError(null);
288
- const r = await api.createOrder(cartId);
289
- return r.id;
290
- },
291
- onApprove: async (data) => {
292
- try {
293
- setProcessing(true);
294
- setError(null);
295
- const orderId = String(data?.orderID || "");
296
- const result = await api.captureOrder(cartId, orderId);
297
- onPaid?.(result);
298
- } catch (e) {
299
- const msg = e instanceof Error ? e.message : "Payment capture failed";
300
- setError(msg);
301
- onError?.(msg);
302
- setProcessing(false);
303
242
  }
304
- },
305
- onCancel: () => {
306
- setProcessing(false);
307
- },
308
- onError: (err) => {
309
- setProcessing(false);
310
- const msg = err instanceof Error ? err.message : err?.message || "PayPal error";
243
+ ),
244
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center" }, children: [
245
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, color: "#374151", fontWeight: 500 }, children: "Processing your payment\u2026" }),
246
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
247
+ ] })
248
+ ]
249
+ }
250
+ ),
251
+ config.environment === "sandbox" && /* @__PURE__ */ jsxRuntime.jsxs(
252
+ "div",
253
+ {
254
+ style: {
255
+ display: "flex",
256
+ alignItems: "flex-start",
257
+ gap: 8,
258
+ padding: "10px 14px",
259
+ background: "#eff6ff",
260
+ border: "1px solid #bfdbfe",
261
+ borderRadius: 8,
262
+ fontSize: 13,
263
+ color: "#1e40af",
264
+ lineHeight: 1.5,
265
+ marginBottom: 10
266
+ },
267
+ children: [
268
+ /* @__PURE__ */ jsxRuntime.jsxs(
269
+ "svg",
270
+ {
271
+ width: "16",
272
+ height: "16",
273
+ viewBox: "0 0 24 24",
274
+ fill: "none",
275
+ stroke: "#1e40af",
276
+ strokeWidth: "2",
277
+ strokeLinecap: "round",
278
+ style: { flexShrink: 0, marginTop: 1 },
279
+ children: [
280
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
281
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 8v4M12 16h.01" })
282
+ ]
283
+ }
284
+ ),
285
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Sandbox mode \u2014 you will not be charged. Use your PayPal sandbox account to complete the payment." })
286
+ ]
287
+ }
288
+ ),
289
+ /* @__PURE__ */ jsxRuntime.jsx(
290
+ reactPaypalJs.PayPalButtons,
291
+ {
292
+ style: {
293
+ layout: "vertical",
294
+ color: config.button_color,
295
+ shape: config.button_shape,
296
+ label: config.button_label,
297
+ height: config.button_height
298
+ },
299
+ createOrder: async () => {
300
+ setError(null);
301
+ const r = await api.createOrder(cartId);
302
+ return r.id;
303
+ },
304
+ onApprove: async (data) => {
305
+ try {
306
+ setProcessing(true);
307
+ setError(null);
308
+ const orderId = String(data?.orderID || "");
309
+ const result = await api.captureOrder(cartId, orderId);
310
+ await markPaymentComplete(baseUrl, cartId, publishableApiKey);
311
+ onPaid?.(result);
312
+ } catch (e) {
313
+ const msg = e instanceof Error ? e.message : "Payment capture failed";
311
314
  setError(msg);
312
315
  onError?.(msg);
316
+ setProcessing(false);
313
317
  }
318
+ },
319
+ onCancel: () => {
320
+ setProcessing(false);
321
+ },
322
+ onError: (err) => {
323
+ setProcessing(false);
324
+ const msg = err instanceof Error ? err.message : err?.message || "PayPal error";
325
+ setError(msg);
326
+ onError?.(msg);
314
327
  }
315
- ),
316
- error ? /* @__PURE__ */ jsxRuntime.jsxs(
317
- "div",
318
- {
319
- style: {
320
- marginTop: 10,
321
- display: "flex",
322
- alignItems: "flex-start",
323
- gap: 8,
324
- padding: "10px 14px",
325
- background: "#fef2f2",
326
- border: "1px solid #fecaca",
327
- borderRadius: 8,
328
- fontSize: 13,
329
- color: "#b91c1c",
330
- lineHeight: 1.5
331
- },
332
- children: [
333
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { flexShrink: 0, fontSize: 15 }, children: "\u26A0\uFE0F" }),
334
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: error })
335
- ]
336
- }
337
- ) : null
338
- ] })
339
- );
328
+ }
329
+ ),
330
+ error ? /* @__PURE__ */ jsxRuntime.jsxs(
331
+ "div",
332
+ {
333
+ style: {
334
+ marginTop: 10,
335
+ display: "flex",
336
+ alignItems: "flex-start",
337
+ gap: 8,
338
+ padding: "10px 14px",
339
+ background: "#fef2f2",
340
+ border: "1px solid #fecaca",
341
+ borderRadius: 8,
342
+ fontSize: 13,
343
+ color: "#b91c1c",
344
+ lineHeight: 1.5
345
+ },
346
+ children: [
347
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { flexShrink: 0, fontSize: 15 }, children: "\u26A0\uFE0F" }),
348
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: error })
349
+ ]
350
+ }
351
+ ) : null
352
+ ] });
340
353
  }
341
354
  var SPIN_STYLE2 = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
342
355
  var cardStyle = {
@@ -381,6 +394,21 @@ var labelStyle = {
381
394
  marginBottom: 6,
382
395
  letterSpacing: "0.01em"
383
396
  };
397
+ async function markPaymentComplete2(baseUrl, cartId, publishableApiKey) {
398
+ try {
399
+ await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
400
+ method: "POST",
401
+ headers: {
402
+ "Content-Type": "application/json",
403
+ ...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
404
+ },
405
+ body: JSON.stringify({ cart_id: cartId }),
406
+ credentials: "include"
407
+ });
408
+ } catch (e) {
409
+ console.warn("[PayPal Card] paypal-complete call failed:", e);
410
+ }
411
+ }
384
412
  function SubmitButton({
385
413
  disabled,
386
414
  label,
@@ -508,6 +536,7 @@ function PayPalAdvancedCard(props) {
508
536
  setError(null);
509
537
  const orderId = String(data?.orderID || "");
510
538
  const result = await api.captureOrder(cartId, orderId);
539
+ await markPaymentComplete2(baseUrl, cartId, publishableApiKey);
511
540
  onPaid?.(result);
512
541
  } catch (e) {
513
542
  const msg = e instanceof Error ? e.message : "Card payment failed";