strapi-plugin-payone-provider 1.5.6 → 1.5.8-beta.1

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.
@@ -42,7 +42,7 @@ const ApplePayButton = ({
42
42
  const checkApplePayAvailability = async () => {
43
43
  try {
44
44
  console.log("[Apple Pay] Checking availability...");
45
-
45
+
46
46
  // Check secure context using browser's native property
47
47
  // This is the most reliable way to check if we're in a secure context
48
48
  const isSecureContext = typeof window !== 'undefined' && window.isSecureContext;
@@ -57,7 +57,7 @@ const ApplePayButton = ({
57
57
  // - 127.0.0.1 (even on HTTP)
58
58
  // - file:// URLs
59
59
  const isSecure = isSecureContext || isLocalhost;
60
-
60
+
61
61
  console.log("[Apple Pay] Secure context check:", {
62
62
  isSecureContext: isSecureContext,
63
63
  protocol: protocol,
@@ -78,12 +78,12 @@ const ApplePayButton = ({
78
78
  reason: !isSecureContext ? "window.isSecureContext is false" : "Unknown"
79
79
  });
80
80
  }
81
-
81
+
82
82
  // First, check if Payment Request API is available
83
83
  // Payment Request API works on HTTP too, but Apple Pay JS API requires HTTPS
84
84
  if (typeof window === 'undefined' || !window.PaymentRequest) {
85
85
  console.log("[Apple Pay] Payment Request API not available");
86
-
86
+
87
87
  // Fallback: Check Apple Pay JS API (for Safari, requires HTTPS)
88
88
  if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
89
89
  try {
@@ -95,11 +95,11 @@ const ApplePayButton = ({
95
95
  return { available: false, method: null, error: 'insecure_context' };
96
96
  }
97
97
  }
98
-
98
+
99
99
  if (!isSecure && typeof window !== 'undefined' && window.ApplePaySession) {
100
100
  console.warn("[Apple Pay] Apple Pay JS API requires HTTPS. Using Payment Request API fallback.");
101
101
  }
102
-
102
+
103
103
  console.log("[Apple Pay] No Apple Pay support found");
104
104
  return { available: false, method: null };
105
105
  }
@@ -152,11 +152,11 @@ const ApplePayButton = ({
152
152
  try {
153
153
  const canPay = await testRequest.canMakePayment();
154
154
  console.log("[Apple Pay] canMakePayment result:", canPay);
155
-
155
+
156
156
  if (canPay) {
157
157
  return { available: true, method: 'paymentRequest' };
158
158
  }
159
-
159
+
160
160
  // If PaymentRequest says no, try Apple Pay JS API as fallback (only on HTTPS)
161
161
  if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
162
162
  try {
@@ -172,17 +172,17 @@ const ApplePayButton = ({
172
172
  }
173
173
  }
174
174
  }
175
-
175
+
176
176
  return { available: false, method: null };
177
177
  } catch (e) {
178
178
  console.error("[Apple Pay] Error checking canMakePayment:", e);
179
-
179
+
180
180
  // If it's insecure context error, we can't use Apple Pay JS API
181
181
  if (e.message && e.message.includes('insecure')) {
182
182
  console.warn("[Apple Pay] Insecure context detected. Apple Pay requires HTTPS.");
183
183
  return { available: false, method: null, error: 'insecure_context' };
184
184
  }
185
-
185
+
186
186
  // For other errors, try Apple Pay JS API as fallback (only on HTTPS)
187
187
  if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
188
188
  try {
@@ -193,7 +193,7 @@ const ApplePayButton = ({
193
193
  return { available: false, method: null };
194
194
  }
195
195
  }
196
-
196
+
197
197
  return { available: false, method: null };
198
198
  }
199
199
  }
@@ -204,7 +204,7 @@ const ApplePayButton = ({
204
204
  const hostnameFinal = typeof window !== 'undefined' ? window.location.hostname : '';
205
205
  const isLocalhostFinal = hostnameFinal === 'localhost' || hostnameFinal === '127.0.0.1';
206
206
  const isSecureFinal = isSecureContextFinal || isLocalhostFinal;
207
-
207
+
208
208
  if (isSecureFinal) {
209
209
  console.log("[Apple Pay] canMakePayment not available, assuming support (secure context)");
210
210
  return { available: true, method: 'paymentRequest' };
@@ -219,20 +219,20 @@ const ApplePayButton = ({
219
219
  }
220
220
  } catch (error) {
221
221
  console.error("[Apple Pay] Error checking availability:", error);
222
-
222
+
223
223
  // Check if it's insecure context error
224
224
  if (error.message && error.message.includes('insecure')) {
225
225
  console.warn("[Apple Pay] Insecure context - Apple Pay requires HTTPS");
226
226
  return { available: false, method: null, error: 'insecure_context' };
227
227
  }
228
-
228
+
229
229
  // Fallback: Try Apple Pay JS API (only on HTTPS)
230
230
  // Re-check secure context
231
231
  const isSecureContextFallback = typeof window !== 'undefined' && window.isSecureContext;
232
232
  const hostnameFallback = typeof window !== 'undefined' ? window.location.hostname : '';
233
233
  const isLocalhostFallback = hostnameFallback === 'localhost' || hostnameFallback === '127.0.0.1';
234
234
  const isSecureFallback = isSecureContextFallback || isLocalhostFallback;
235
-
235
+
236
236
  if (typeof window !== 'undefined' && window.ApplePaySession && isSecureFallback) {
237
237
  try {
238
238
  const canMakePayments = ApplePaySession.canMakePayments();
@@ -244,16 +244,16 @@ const ApplePayButton = ({
244
244
  }
245
245
  }
246
246
  }
247
-
247
+
248
248
  return { available: false, method: null };
249
249
  }
250
250
  };
251
251
 
252
252
  useEffect(() => {
253
253
  const scriptUrl = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
254
-
254
+
255
255
  console.log("[Apple Pay] Loading Apple Pay SDK script...");
256
-
256
+
257
257
  if (document.querySelector(`script[src="${scriptUrl}"]`)) {
258
258
  console.log("[Apple Pay] Script already loaded");
259
259
  // Script already loaded, check if it's ready
@@ -270,20 +270,20 @@ const ApplePayButton = ({
270
270
  script.src = scriptUrl;
271
271
  script.crossOrigin = "anonymous";
272
272
  script.async = true;
273
-
273
+
274
274
  script.onload = () => {
275
275
  console.log("[Apple Pay] SDK script loaded successfully");
276
276
  setTimeout(() => {
277
277
  initializeButton();
278
278
  }, 500);
279
279
  };
280
-
280
+
281
281
  script.onerror = (error) => {
282
282
  console.error("[Apple Pay] Failed to load SDK script:", error);
283
283
  setIsLoading(false);
284
284
  setIsAvailable(false);
285
285
  setErrorMessage("Failed to load Apple Pay SDK. Please check Content Security Policy settings.");
286
-
286
+
287
287
  // Even if script fails, try to use Payment Request API
288
288
  console.log("[Apple Pay] Trying Payment Request API as fallback...");
289
289
  setTimeout(() => {
@@ -306,22 +306,22 @@ const ApplePayButton = ({
306
306
  const initializeButton = async () => {
307
307
  try {
308
308
  console.log("[Apple Pay] Initializing button...");
309
-
310
- const isSecure = typeof window !== 'undefined' &&
311
- (window.location.protocol === 'https:' ||
312
- window.location.hostname === 'localhost' ||
313
- window.location.hostname === '127.0.0.1');
314
-
309
+
310
+ const isSecure = typeof window !== 'undefined' &&
311
+ (window.location.protocol === 'https:' ||
312
+ window.location.hostname === 'localhost' ||
313
+ window.location.hostname === '127.0.0.1');
314
+
315
315
  console.log("[Apple Pay] Secure context check:", {
316
316
  protocol: window.location?.protocol,
317
317
  hostname: window.location?.hostname,
318
318
  isSecure: isSecure
319
319
  });
320
-
321
- const isLocalhost = typeof window !== 'undefined' &&
322
- (window.location.hostname === 'localhost' ||
323
- window.location.hostname === '127.0.0.1');
324
-
320
+
321
+ const isLocalhost = typeof window !== 'undefined' &&
322
+ (window.location.hostname === 'localhost' ||
323
+ window.location.hostname === '127.0.0.1');
324
+
325
325
  if (!isSecure && !isLocalhost && window.location?.protocol === 'http:') {
326
326
  const errorMsg = "Apple Pay requires HTTPS. Please access this page via HTTPS (https://yourdomain.com) instead of HTTP. Localhost (http://localhost) is allowed for development.";
327
327
  setErrorMessage(errorMsg);
@@ -331,7 +331,7 @@ const ApplePayButton = ({
331
331
  console.warn("[Apple Pay] Current URL:", window.location.href);
332
332
  return;
333
333
  }
334
-
334
+
335
335
  // Log context information
336
336
  console.log("[Apple Pay] Context info:", {
337
337
  protocol: window.location?.protocol,
@@ -340,16 +340,16 @@ const ApplePayButton = ({
340
340
  isLocalhost: isLocalhost,
341
341
  fullUrl: window.location?.href
342
342
  });
343
-
343
+
344
344
  // Check availability
345
345
  const availability = await checkApplePayAvailability();
346
346
  console.log("[Apple Pay] Availability check result:", availability);
347
-
347
+
348
348
  setIsAvailable(availability.available);
349
-
349
+
350
350
  if (!availability.available) {
351
351
  let errorMsg = "Apple Pay is not available on this device or browser.";
352
-
352
+
353
353
  if (isLocalhost) {
354
354
  errorMsg = "Apple Pay is not available on localhost. Apple Pay requires a registered domain with HTTPS. " +
355
355
  "For testing, please use a production domain with HTTPS or test on a device with Safari (iOS/macOS). " +
@@ -366,7 +366,7 @@ const ApplePayButton = ({
366
366
  } else {
367
367
  errorMsg += " Please use Safari on iOS, macOS, or iPadOS, or a browser that supports Payment Request API (Chrome, Edge, Safari).";
368
368
  }
369
-
369
+
370
370
  setErrorMessage(errorMsg);
371
371
  setIsLoading(false);
372
372
  console.warn("[Apple Pay] Not available:", errorMsg);
@@ -380,14 +380,14 @@ const ApplePayButton = ({
380
380
  console.error("[Apple Pay] Initialization error:", error);
381
381
  setIsLoading(false);
382
382
  setIsAvailable(false);
383
-
383
+
384
384
  // Check for insecure context error
385
385
  if (error.message && error.message.includes('insecure')) {
386
386
  setErrorMessage("Apple Pay requires HTTPS. Please access this page via HTTPS (https://yourdomain.com) instead of HTTP. Localhost is allowed for development.");
387
387
  } else {
388
388
  setErrorMessage(error.message || "Failed to initialize Apple Pay");
389
389
  }
390
-
390
+
391
391
  if (onError) {
392
392
  onError(error);
393
393
  }
@@ -406,11 +406,11 @@ const ApplePayButton = ({
406
406
  });
407
407
 
408
408
  // Check HTTPS requirement
409
- const isSecure = typeof window !== 'undefined' &&
410
- (window.location.protocol === 'https:' ||
411
- window.location.hostname === 'localhost' ||
412
- window.location.hostname === '127.0.0.1');
413
-
409
+ const isSecure = typeof window !== 'undefined' &&
410
+ (window.location.protocol === 'https:' ||
411
+ window.location.hostname === 'localhost' ||
412
+ window.location.hostname === '127.0.0.1');
413
+
414
414
  if (!isSecure && window.location?.protocol === 'http:') {
415
415
  const errorMsg = "Apple Pay requires HTTPS. Please access this page via HTTPS.";
416
416
  console.error("[Apple Pay]", errorMsg);
@@ -496,16 +496,35 @@ const ApplePayButton = ({
496
496
  });
497
497
 
498
498
  merchantSessionPromise.then(session => {
499
- console.log("[Apple Pay] Merchant session received:", {
500
- hasMerchantIdentifier: !!session.merchantIdentifier,
501
- merchantIdentifier: session.merchantIdentifier,
502
- domainName: session.domainName,
503
- displayName: session.displayName,
504
- epochTimestamp: session.epochTimestamp,
505
- expiresAt: session.expiresAt,
506
- fullSession: session
507
- });
508
-
499
+ console.log("[Apple Pay] ========== MERCHANT SESSION RECEIVED ==========");
500
+ console.log("[Apple Pay] Full Merchant Session (JSON):", JSON.stringify(session, null, 2));
501
+ console.log("[Apple Pay] Session Type:", typeof session);
502
+ console.log("[Apple Pay] Is Object:", session instanceof Object);
503
+ console.log("[Apple Pay] Session Keys:", Object.keys(session || {}));
504
+ console.log("[Apple Pay] Session Keys Count:", Object.keys(session || {}).length);
505
+ console.log("[Apple Pay] Has Merchant Identifier:", !!session?.merchantIdentifier);
506
+ console.log("[Apple Pay] Merchant Identifier:", session?.merchantIdentifier);
507
+ console.log("[Apple Pay] Has Merchant Session Identifier:", !!session?.merchantSessionIdentifier);
508
+ console.log("[Apple Pay] Merchant Session Identifier:", session?.merchantSessionIdentifier);
509
+ console.log("[Apple Pay] Domain Name:", session?.domainName);
510
+ console.log("[Apple Pay] Display Name:", session?.displayName);
511
+ console.log("[Apple Pay] Epoch Timestamp:", session?.epochTimestamp);
512
+ console.log("[Apple Pay] Expires At:", session?.expiresAt);
513
+ console.log("[Apple Pay] Nonce:", session?.nonce);
514
+
515
+ // Log all properties
516
+ console.log("[Apple Pay] All Session Properties:");
517
+ if (session && typeof session === 'object') {
518
+ for (const [key, value] of Object.entries(session)) {
519
+ if (typeof value === 'string' && value.length > 200) {
520
+ console.log(`[Apple Pay] ${key}:`, value.substring(0, 200) + "... (truncated, length: " + value.length + ")");
521
+ } else {
522
+ console.log(`[Apple Pay] ${key}:`, value);
523
+ }
524
+ }
525
+ }
526
+ console.log("[Apple Pay] ==========================================");
527
+
509
528
  // Validate merchant session
510
529
  if (!session || (!session.merchantIdentifier && !session.merchantSessionIdentifier)) {
511
530
  console.error("[Apple Pay] Invalid merchant session - missing merchantIdentifier");
@@ -528,12 +547,12 @@ const ApplePayButton = ({
528
547
  stack: error.stack,
529
548
  response: error.response
530
549
  });
531
-
550
+
532
551
  // Call onError to notify the user
533
552
  if (typeof onError === 'function') {
534
553
  onError(new Error(`Apple Pay merchant validation failed: ${error.message}. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay).`));
535
554
  }
536
-
555
+
537
556
  // Complete with a rejected promise
538
557
  // This will cause Apple Pay to close the dialog, which is expected behavior
539
558
  // We cannot proceed without a valid merchant session from Payone
@@ -576,20 +595,20 @@ const ApplePayButton = ({
576
595
  message: error.message,
577
596
  stack: error.stack
578
597
  });
579
-
598
+
580
599
  // Check if error is due to cancellation (user cancelled)
581
600
  // Payment Request API throws "AbortError" when user cancels
582
- if (error.name === 'AbortError' ||
583
- (error.message && (
584
- error.message.includes('Cancelled') ||
585
- error.message.includes('cancel') ||
586
- error.message.includes('abort')
587
- ))) {
601
+ if (error.name === 'AbortError' ||
602
+ (error.message && (
603
+ error.message.includes('Cancelled') ||
604
+ error.message.includes('cancel') ||
605
+ error.message.includes('abort')
606
+ ))) {
588
607
  console.log("[Apple Pay] User cancelled the payment");
589
608
  // Don't call onError for user cancellation
590
609
  return;
591
610
  }
592
-
611
+
593
612
  // If it's a merchant validation error, log it specifically
594
613
  if (error.message && (
595
614
  error.message.includes('merchant') ||
@@ -617,11 +636,11 @@ const ApplePayButton = ({
617
636
 
618
637
  // Extract payment token
619
638
  const paymentToken = response.details?.paymentToken || response.details?.token;
620
-
639
+
621
640
  if (!paymentToken) {
622
641
  console.error("[Apple Pay] Payment token is missing from response");
623
642
  try {
624
- await response.complete("fail");
643
+ await response.complete("fail");
625
644
  } catch (completeError) {
626
645
  console.error("[Apple Pay] Error completing payment with fail:", completeError);
627
646
  }
@@ -663,11 +682,11 @@ const ApplePayButton = ({
663
682
  // The callback should set the token in state and return success immediately
664
683
  // It should NOT process the payment yet - that will happen when user clicks the button
665
684
  const callbackResult = onTokenReceived(tokenString, {
666
- paymentToken: paymentToken,
667
- billingContact: response.payerName || response.details?.billingContact,
668
- shippingContact: response.shippingAddress || response.details?.shippingAddress,
669
- shippingOption: response.shippingOption || response.details?.shippingOption
670
- });
685
+ paymentToken: paymentToken,
686
+ billingContact: response.payerName || response.details?.billingContact,
687
+ shippingContact: response.shippingAddress || response.details?.shippingAddress,
688
+ shippingOption: response.shippingOption || response.details?.shippingOption
689
+ });
671
690
 
672
691
  // If callback returns a promise, wait for it to resolve or reject
673
692
  if (callbackResult && typeof callbackResult.then === 'function') {
@@ -779,12 +798,56 @@ const ApplePayButton = ({
779
798
  }
780
799
  });
781
800
 
782
- console.log("[Apple Pay] Merchant session received from backend:", {
783
- hasData: !!merchantSession.data,
784
- merchantIdentifier: merchantSession.data?.merchantIdentifier
785
- });
801
+ console.log("[Apple Pay] ========== BACKEND RESPONSE START ==========");
802
+ console.log("[Apple Pay] Full Backend Response:", JSON.stringify(merchantSession, null, 2));
803
+ console.log("[Apple Pay] Response Type:", typeof merchantSession);
804
+ console.log("[Apple Pay] Has Data:", !!merchantSession.data);
805
+ console.log("[Apple Pay] Has Error:", !!merchantSession.error);
806
+
807
+ if (merchantSession.data) {
808
+ console.log("[Apple Pay] Data Object:", merchantSession.data);
809
+ console.log("[Apple Pay] Data Type:", typeof merchantSession.data);
810
+ console.log("[Apple Pay] Data Keys:", Object.keys(merchantSession.data));
811
+ console.log("[Apple Pay] Data Keys Count:", Object.keys(merchantSession.data).length);
812
+ console.log("[Apple Pay] Merchant Identifier:", merchantSession.data.merchantIdentifier);
813
+ console.log("[Apple Pay] Domain Name:", merchantSession.data.domainName);
814
+ console.log("[Apple Pay] Display Name:", merchantSession.data.displayName);
815
+ console.log("[Apple Pay] Epoch Timestamp:", merchantSession.data.epochTimestamp);
816
+ console.log("[Apple Pay] Expires At:", merchantSession.data.expiresAt);
817
+ }
818
+
819
+ if (merchantSession.error) {
820
+ console.log("[Apple Pay] Error Object:", merchantSession.error);
821
+ console.log("[Apple Pay] Error Message:", merchantSession.error.message);
822
+ console.log("[Apple Pay] Error Details:", merchantSession.error.details);
823
+ }
824
+
825
+ console.log("[Apple Pay] ========== BACKEND RESPONSE END ==========");
826
+
827
+ // Check if there's an error in the response
828
+ if (merchantSession.error) {
829
+ console.error("[Apple Pay] Backend returned error:", merchantSession.error);
830
+ throw new Error(merchantSession.error.message || "Apple Pay merchant validation failed");
831
+ }
832
+
833
+ // Validate merchant session
834
+ const session = merchantSession.data || merchantSession;
835
+
836
+ // Check if session is empty object
837
+ if (!session || Object.keys(session).length === 0) {
838
+ console.error("[Apple Pay] Empty merchant session received from backend");
839
+ console.error("[Apple Pay] Full response:", JSON.stringify(merchantSession, null, 2));
840
+ throw new Error("Empty merchant session received. This usually means Payone did not return a valid merchant session. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay).");
841
+ }
842
+
843
+ if (!session.merchantIdentifier && !session.merchantSessionIdentifier) {
844
+ console.error("[Apple Pay] Invalid merchant session - missing merchantIdentifier");
845
+ console.error("[Apple Pay] Session object:", JSON.stringify(session, null, 2));
846
+ console.error("[Apple Pay] Full response:", JSON.stringify(merchantSession, null, 2));
847
+ throw new Error("Invalid merchant session: missing merchantIdentifier. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay). The merchant session must come from Payone after successful Apple Pay onboarding.");
848
+ }
786
849
 
787
- return merchantSession.data || merchantSession;
850
+ return session;
788
851
  } catch (error) {
789
852
  console.error("[Apple Pay] Merchant validation error:", {
790
853
  message: error.message,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-payone-provider",
3
- "version": "1.5.6",
3
+ "version": "1.5.8-beta.1",
4
4
  "description": "Strapi plugin for Payone payment gateway integration",
5
5
  "license": "MIT",
6
6
  "maintainers": [
@@ -189,20 +189,70 @@ module.exports = ({ strapi }) => ({
189
189
  } : "No user");
190
190
 
191
191
  const params = ctx.request.body;
192
- const result = await getPayoneService(strapi).validateApplePayMerchant(params);
192
+ let result;
193
+ try {
194
+ result = await getPayoneService(strapi).validateApplePayMerchant(params);
195
+ } catch (serviceError) {
196
+ // Service threw an error - re-throw it so it's caught by the outer catch block
197
+ strapi.log.error("[Apple Pay] Service threw error:", {
198
+ message: serviceError.message,
199
+ stack: serviceError.stack
200
+ });
201
+ throw serviceError;
202
+ }
193
203
 
194
204
  strapi.log.info("[Apple Pay] Merchant validation result:", {
195
205
  hasResult: !!result,
196
- hasMerchantIdentifier: !!result.merchantIdentifier
206
+ resultType: typeof result,
207
+ resultIsObject: result instanceof Object,
208
+ resultKeys: result ? Object.keys(result) : [],
209
+ resultKeysLength: result ? Object.keys(result).length : 0,
210
+ hasMerchantIdentifier: !!result?.merchantIdentifier,
211
+ hasMerchantSessionIdentifier: !!result?.merchantSessionIdentifier,
212
+ merchantIdentifier: result?.merchantIdentifier,
213
+ domainName: result?.domainName,
214
+ displayName: result?.displayName,
215
+ epochTimestamp: result?.epochTimestamp,
216
+ expiresAt: result?.expiresAt,
217
+ fullResult: JSON.stringify(result)
197
218
  });
198
219
 
220
+ // Validate result before sending
221
+ // Check if result is null, undefined, empty object, or missing merchantIdentifier
222
+ if (!result ||
223
+ (typeof result === 'object' && Object.keys(result).length === 0) ||
224
+ (!result.merchantIdentifier && !result.merchantSessionIdentifier)) {
225
+ strapi.log.error("[Apple Pay] CRITICAL: Invalid or empty merchant session returned!");
226
+ strapi.log.error("[Apple Pay] Result details:", {
227
+ hasResult: !!result,
228
+ resultType: typeof result,
229
+ resultIsObject: result instanceof Object,
230
+ resultKeys: result ? Object.keys(result) : [],
231
+ resultKeysLength: result ? Object.keys(result).length : 0,
232
+ hasMerchantIdentifier: !!result?.merchantIdentifier,
233
+ hasMerchantSessionIdentifier: !!result?.merchantSessionIdentifier,
234
+ resultStringified: JSON.stringify(result)
235
+ });
236
+ ctx.throw(500, "Apple Pay merchant validation failed: Invalid or empty merchant session received from Payone. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay). The merchant session must come from Payone after successful Apple Pay onboarding. Check server logs for Payone response details.");
237
+ }
238
+
199
239
  ctx.body = { data: result };
200
240
  } catch (error) {
201
241
  strapi.log.error("[Apple Pay] Controller error:", {
202
242
  message: error.message,
203
- stack: error.stack
243
+ stack: error.stack,
244
+ name: error.name
204
245
  });
205
- handleError(ctx, error);
246
+
247
+ // Return error response instead of empty object
248
+ // This will help frontend understand what went wrong
249
+ ctx.status = error.status || 500;
250
+ ctx.body = {
251
+ error: {
252
+ message: error.message || "Apple Pay merchant validation failed",
253
+ details: "Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay)"
254
+ }
255
+ };
206
256
  }
207
257
  }
208
258
  });
@@ -115,17 +115,71 @@ const initializeApplePaySession = async (strapi, params) => {
115
115
  throw axiosError;
116
116
  }
117
117
 
118
- strapi.log.info("[Apple Pay] Payone response received:", {
119
- status: response.status,
120
- statusText: response.statusText,
121
- headers: response.headers
122
- });
118
+ strapi.log.info("[Apple Pay] ========== PAYONE RESPONSE START ==========");
119
+ strapi.log.info("[Apple Pay] HTTP Status:", response.status);
120
+ strapi.log.info("[Apple Pay] HTTP Status Text:", response.statusText);
121
+ strapi.log.info("[Apple Pay] Response Headers:", JSON.stringify(response.headers, null, 2));
122
+ strapi.log.info("[Apple Pay] Raw Response Data Type:", typeof response.data);
123
+ strapi.log.info("[Apple Pay] Raw Response Data:", response.data);
123
124
 
124
125
  // Parse response
125
126
  const responseData = parseResponse(response.data, strapi.log);
126
127
 
127
- strapi.log.info("[Apple Pay] Session initialization response:", JSON.stringify(responseData, null, 2));
128
- strapi.log.info("[Apple Pay] Response status:", responseData.status || responseData.Status);
128
+ strapi.log.info("[Apple Pay] ========== PARSED RESPONSE ==========");
129
+ strapi.log.info("[Apple Pay] Full Parsed Response (JSON):", JSON.stringify(responseData, null, 2));
130
+ strapi.log.info("[Apple Pay] Response Type:", typeof responseData);
131
+ strapi.log.info("[Apple Pay] Is Object:", responseData instanceof Object);
132
+ strapi.log.info("[Apple Pay] All Response Keys:", Object.keys(responseData));
133
+ strapi.log.info("[Apple Pay] Response Keys Count:", Object.keys(responseData).length);
134
+
135
+ // Log each key-value pair
136
+ strapi.log.info("[Apple Pay] ========== RESPONSE KEY-VALUE PAIRS ==========");
137
+ for (const [key, value] of Object.entries(responseData)) {
138
+ if (typeof value === 'string' && value.length > 200) {
139
+ strapi.log.info(`[Apple Pay] ${key}:`, value.substring(0, 200) + "... (truncated, length: " + value.length + ")");
140
+ } else {
141
+ strapi.log.info(`[Apple Pay] ${key}:`, value);
142
+ }
143
+ }
144
+
145
+ strapi.log.info("[Apple Pay] ========== IMPORTANT FIELDS ==========");
146
+ strapi.log.info("[Apple Pay] status:", responseData.status || responseData.Status || "NOT_SET");
147
+ strapi.log.info("[Apple Pay] Status (lowercase):", responseData.status || "NOT_SET");
148
+ strapi.log.info("[Apple Pay] Status (uppercase):", responseData.Status || "NOT_SET");
149
+ strapi.log.info("[Apple Pay] errorcode:", responseData.errorcode || responseData.ErrorCode || responseData.error_code || "none");
150
+ strapi.log.info("[Apple Pay] errormessage:", responseData.errormessage || responseData.ErrorMessage || responseData.errortxt || responseData.ErrorTxt || responseData.error_message || "none");
151
+ strapi.log.info("[Apple Pay] workorderid:", responseData.workorderid || responseData.workorderId || responseData.WorkorderId || "none");
152
+ strapi.log.info("[Apple Pay] txid:", responseData.txid || responseData.TxId || responseData.tx_id || "none");
153
+
154
+ // Check for Apple Pay session in various formats
155
+ strapi.log.info("[Apple Pay] ========== APPLE PAY SESSION CHECK ==========");
156
+ const applePaySessionKeys = [
157
+ "add_paydata[applepay_payment_session]",
158
+ "add_paydata_applepay_payment_session",
159
+ "addPaydata[applepay_payment_session]",
160
+ "addPaydata_applepay_payment_session",
161
+ "applepay_payment_session",
162
+ "applePayPaymentSession",
163
+ "payment_session",
164
+ "paymentSession"
165
+ ];
166
+
167
+ for (const key of applePaySessionKeys) {
168
+ if (responseData[key]) {
169
+ strapi.log.info(`[Apple Pay] Found Apple Pay session in key: ${key}`);
170
+ strapi.log.info(`[Apple Pay] Session value length: ${responseData[key].length}`);
171
+ strapi.log.info(`[Apple Pay] Session value preview: ${responseData[key].substring(0, 100)}...`);
172
+ }
173
+ }
174
+
175
+ // Check add_paydata object if it exists
176
+ if (responseData.add_paydata) {
177
+ strapi.log.info("[Apple Pay] add_paydata object exists:", typeof responseData.add_paydata);
178
+ strapi.log.info("[Apple Pay] add_paydata keys:", Object.keys(responseData.add_paydata));
179
+ strapi.log.info("[Apple Pay] add_paydata content:", JSON.stringify(responseData.add_paydata, null, 2));
180
+ }
181
+
182
+ strapi.log.info("[Apple Pay] ========== PAYONE RESPONSE END ==========");
129
183
 
130
184
  if (responseData.errorcode || responseData.ErrorCode) {
131
185
  strapi.log.warn("[Apple Pay] Response contains error:", {
@@ -167,6 +221,18 @@ const validateApplePayMerchant = async (strapi, params) => {
167
221
  throw new Error("Payone settings not configured");
168
222
  }
169
223
 
224
+ // Log all settings to verify MerchantId is being read correctly
225
+ strapi.log.info("[Apple Pay] ========== SETTINGS FROM CONFIG ==========");
226
+ strapi.log.info("[Apple Pay] Full Settings Object:", JSON.stringify(settings, null, 2));
227
+ strapi.log.info("[Apple Pay] Settings Keys:", Object.keys(settings || {}));
228
+ strapi.log.info("[Apple Pay] MerchantId (mid) from config:", settings.mid || "NOT_SET");
229
+ strapi.log.info("[Apple Pay] MerchantId type:", typeof settings.mid);
230
+ strapi.log.info("[Apple Pay] MerchantId length:", settings.mid ? settings.mid.length : 0);
231
+ strapi.log.info("[Apple Pay] merchantIdentifier from config:", settings.merchantIdentifier || "NOT_SET");
232
+ strapi.log.info("[Apple Pay] portalid from config:", settings.portalid || "NOT_SET");
233
+ strapi.log.info("[Apple Pay] mode from config:", settings.mode || "NOT_SET");
234
+ strapi.log.info("[Apple Pay] ==========================================");
235
+
170
236
  const {
171
237
  validationURL,
172
238
  mid,
@@ -177,9 +243,21 @@ const validateApplePayMerchant = async (strapi, params) => {
177
243
 
178
244
  // Get merchant data from settings (test or live mode)
179
245
  const merchantName = displayName || settings.merchantName || settings.displayName || "Test Store";
246
+
247
+ // Use MerchantId (mid) from config as merchantIdentifier
248
+ // Priority: params.mid > settings.mid > settings.merchantIdentifier
180
249
  const merchantId = mid || settings.mid || settings.merchantIdentifier;
181
250
  const portalId = portalid || settings.portalid;
182
251
 
252
+ strapi.log.info("[Apple Pay] ========== MERCHANT ID SELECTION ==========");
253
+ strapi.log.info("[Apple Pay] mid from params:", mid || "NOT_PROVIDED");
254
+ strapi.log.info("[Apple Pay] settings.mid:", settings.mid || "NOT_SET");
255
+ strapi.log.info("[Apple Pay] settings.merchantIdentifier:", settings.merchantIdentifier || "NOT_SET");
256
+ strapi.log.info("[Apple Pay] Selected merchantId:", merchantId || "NOT_SET");
257
+ strapi.log.info("[Apple Pay] Selected merchantId type:", typeof merchantId);
258
+ strapi.log.info("[Apple Pay] Selected merchantId length:", merchantId ? merchantId.length : 0);
259
+ strapi.log.info("[Apple Pay] ==========================================");
260
+
183
261
  // Get domain from params or settings or server config
184
262
  const domainName = domain || settings.domainName ||
185
263
  (strapi.config.get("server.url") ? new URL(strapi.config.get("server.url")).hostname : null) ||
@@ -205,10 +283,12 @@ const validateApplePayMerchant = async (strapi, params) => {
205
283
  strapi.log.error("[Apple Pay] Failed to initialize session with Payone:", {
206
284
  message: error.message,
207
285
  status: error.response?.status,
208
- data: error.response?.data
286
+ data: error.response?.data,
287
+ stack: error.stack
209
288
  });
210
- // Return empty object on error - Payment Request API will handle it
211
- return {};
289
+ // DO NOT return empty object - throw error instead
290
+ // Empty object causes Apple Pay to close dialog without proper error message
291
+ throw new Error(`Failed to initialize Apple Pay session with Payone: ${error.message}. Please check your Payone configuration and ensure Apple Pay is properly set up in PMI.`);
212
292
  }
213
293
 
214
294
  strapi.log.info("[Apple Pay] Session initialization result:", {
@@ -272,12 +352,21 @@ const validateApplePayMerchant = async (strapi, params) => {
272
352
 
273
353
  // Validate decoded merchant session
274
354
  if (!merchantSession.merchantIdentifier) {
275
- strapi.log.warn("[Apple Pay] Decoded merchant session missing merchantIdentifier, using fallback");
276
- // Use fallback merchant identifier
277
- merchantSession.merchantIdentifier = settings.merchantIdentifier ||
278
- settings.mid ||
279
- settings.portalid ||
280
- `merchant.${domainName}`;
355
+ strapi.log.warn("[Apple Pay] Decoded merchant session missing merchantIdentifier, using MerchantId from config");
356
+ // Use MerchantId (mid) from config as merchantIdentifier
357
+ // Priority: settings.mid (MerchantId) > settings.merchantIdentifier > settings.portalid
358
+ strapi.log.info("[Apple Pay] Available MerchantId values from config:");
359
+ strapi.log.info("[Apple Pay] settings.mid:", settings.mid || "NOT_SET");
360
+ strapi.log.info("[Apple Pay] settings.merchantIdentifier:", settings.merchantIdentifier || "NOT_SET");
361
+ strapi.log.info("[Apple Pay] settings.portalid:", settings.portalid || "NOT_SET");
362
+
363
+ const fallbackMerchantId = settings.mid || settings.merchantIdentifier || settings.portalid;
364
+ merchantSession.merchantIdentifier = fallbackMerchantId || `merchant.${domainName}`;
365
+
366
+ strapi.log.info("[Apple Pay] Selected MerchantId from config:", fallbackMerchantId || "NOT_SET");
367
+ strapi.log.info("[Apple Pay] Final merchantIdentifier set to:", merchantSession.merchantIdentifier);
368
+ } else {
369
+ strapi.log.info("[Apple Pay] Using merchantIdentifier from decoded Payone session:", merchantSession.merchantIdentifier);
281
370
  }
282
371
 
283
372
  // Ensure epochTimestamp and expiresAt are in seconds (not milliseconds)
@@ -332,11 +421,21 @@ const validateApplePayMerchant = async (strapi, params) => {
332
421
  throw new Error("Payone did not return Apple Pay merchant session. Please ensure Apple Pay is properly configured in Payone Merchant Interface (PMI): CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay configuration. The merchant session must come from Payone after successful Apple Pay onboarding.");
333
422
 
334
423
  // Get merchant identifier from settings
424
+ // Use MerchantId (mid) from config as merchantIdentifier
335
425
  // According to Payone docs, merchant identifier should be visible in PMI after onboarding
336
426
  // Path: CONFIGURATION/PAYMENT PORTALS - choose an onboarded Portal - Payment type configuration tab
337
- let merchantIdentifier = settings.merchantIdentifier ||
338
- settings.mid ||
339
- settings.portalid;
427
+ strapi.log.info("[Apple Pay] ========== CREATING MERCHANT SESSION FROM CONFIG ==========");
428
+ strapi.log.info("[Apple Pay] Available MerchantId values from config:");
429
+ strapi.log.info("[Apple Pay] settings.mid:", settings.mid || "NOT_SET");
430
+ strapi.log.info("[Apple Pay] settings.merchantIdentifier:", settings.merchantIdentifier || "NOT_SET");
431
+ strapi.log.info("[Apple Pay] settings.portalid:", settings.portalid || "NOT_SET");
432
+
433
+ // Priority: settings.mid (MerchantId) > settings.merchantIdentifier > settings.portalid
434
+ let merchantIdentifier = settings.mid || settings.merchantIdentifier || settings.portalid;
435
+
436
+ strapi.log.info("[Apple Pay] Selected merchantIdentifier:", merchantIdentifier || "NOT_SET");
437
+ strapi.log.info("[Apple Pay] merchantIdentifier type:", typeof merchantIdentifier);
438
+ strapi.log.info("[Apple Pay] merchantIdentifier length:", merchantIdentifier ? merchantIdentifier.length : 0);
340
439
 
341
440
  // If still no merchant identifier, try to construct one from domain
342
441
  // But this is not ideal - merchant identifier should come from Payone PMI
@@ -355,16 +454,25 @@ const validateApplePayMerchant = async (strapi, params) => {
355
454
  // Create a valid merchant session object
356
455
  // This format is required by Apple Pay Payment Request API
357
456
  // IMPORTANT: epochTimestamp and expiresAt must be in seconds (Unix timestamp), not milliseconds
457
+ // IMPORTANT: merchantIdentifier must be the MerchantId (mid) from Payone config
358
458
  const merchantSession = {
359
459
  epochTimestamp: Math.floor(Date.now() / 1000), // Unix timestamp in seconds
360
460
  expiresAt: Math.floor((Date.now() + (5 * 60 * 1000)) / 1000), // 5 minutes from now, in seconds
361
461
  merchantSessionIdentifier: `merchant.${domainName}`,
362
462
  nonce: generateNonce(),
363
- merchantIdentifier: merchantIdentifier, // Already validated and converted to string
463
+ merchantIdentifier: merchantIdentifier, // MerchantId (mid) from config - already validated and converted to string
364
464
  domainName: domainName,
365
465
  displayName: merchantName
366
466
  };
367
467
 
468
+ strapi.log.info("[Apple Pay] Created merchant session with MerchantId from config:");
469
+ strapi.log.info("[Apple Pay] merchantIdentifier:", merchantSession.merchantIdentifier);
470
+ strapi.log.info("[Apple Pay] domainName:", merchantSession.domainName);
471
+ strapi.log.info("[Apple Pay] displayName:", merchantSession.displayName);
472
+ strapi.log.info("[Apple Pay] epochTimestamp:", merchantSession.epochTimestamp);
473
+ strapi.log.info("[Apple Pay] expiresAt:", merchantSession.expiresAt);
474
+ strapi.log.info("[Apple Pay] ==========================================");
475
+
368
476
  // Validate merchant session before returning
369
477
  if (!merchantSession.merchantIdentifier || merchantSession.merchantIdentifier === 'undefined' || merchantSession.merchantIdentifier === 'null') {
370
478
  strapi.log.error("[Apple Pay] Created merchant session is missing or invalid merchantIdentifier!", {
@@ -395,9 +503,28 @@ const validateApplePayMerchant = async (strapi, params) => {
395
503
  // If initialization failed, we cannot proceed
396
504
  // Payment Request API requires a valid merchant session
397
505
  strapi.log.error("[Apple Pay] Session initialization failed - status:", responseStatus);
506
+ strapi.log.error("[Apple Pay] Full Payone response:", JSON.stringify(sessionResponse, null, 2));
398
507
  strapi.log.error("[Apple Pay] This means merchant validation will fail.");
399
- strapi.log.error("[Apple Pay] Please check Payone PMI configuration and ensure Apple Pay is properly set up.");
400
- throw new Error(`Apple Pay session initialization failed with status: ${responseStatus}. Please check your Payone Apple Pay configuration in PMI.`);
508
+ strapi.log.error("[Apple Pay] Possible causes:");
509
+ strapi.log.error("[Apple Pay] 1. Payone returned ERROR status - check errorcode and errormessage in response");
510
+ strapi.log.error("[Apple Pay] 2. Apple Pay not configured in Payone PMI");
511
+ strapi.log.error("[Apple Pay] 3. Domain not verified in Payone PMI");
512
+ strapi.log.error("[Apple Pay] 4. Merchant identifier not configured correctly");
513
+ strapi.log.error("[Apple Pay] 5. Apple Pay onboarding not completed");
514
+
515
+ // Extract error details from Payone response
516
+ const errorCode = sessionResponse.errorcode || sessionResponse.ErrorCode;
517
+ const errorMessage = sessionResponse.errormessage || sessionResponse.ErrorMessage || sessionResponse.errortxt || sessionResponse.ErrorTxt;
518
+
519
+ if (errorCode || errorMessage) {
520
+ strapi.log.error("[Apple Pay] Payone error details:", {
521
+ errorCode: errorCode,
522
+ errorMessage: errorMessage
523
+ });
524
+ throw new Error(`Payone Apple Pay initialization failed: ${errorCode ? `Error ${errorCode}` : ''} ${errorMessage || 'Unknown error'}. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay).`);
525
+ } else {
526
+ throw new Error(`Apple Pay session initialization failed with status: ${responseStatus || 'UNKNOWN'}. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay).`);
527
+ }
401
528
  } catch (error) {
402
529
  strapi.log.error("[Apple Pay] Merchant validation error:", {
403
530
  message: error.message,