@swirepay-developer/swirepay-payment-sdk 1.0.4 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirepay-developer/swirepay-payment-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "swirepay sdk for apple and google pay",
5
5
  "main": "swirepayPaypalWalletPayment.js",
6
6
  "scripts": {
@@ -1,9 +1,9 @@
1
1
  class PaypalPaymentMethod {
2
2
  static paypal_sdk_url = "https://www.paypal.com/sdk/js";
3
3
  static intent = "capture";
4
-
4
+
5
5
  // CACHE: Stores active loading promises to prevent race conditions
6
- static _scriptLoadingPromises = {};
6
+ static _scriptLoadingPromises = {};
7
7
 
8
8
  constructor(config) {
9
9
  this.mountId = config.mountId;
@@ -64,13 +64,13 @@ class PaypalPaymentMethod {
64
64
  const loadPromise = new Promise((resolve, reject) => {
65
65
  const script = document.createElement("script");
66
66
  Object.entries(attrs).forEach(([k, v]) => script.setAttribute(k, v));
67
-
67
+
68
68
  script.onload = () => resolve();
69
69
  script.onerror = (err) => {
70
70
  delete PaypalPaymentMethod._scriptLoadingPromises[id]; // Cleanup on fail
71
71
  reject(err);
72
72
  };
73
-
73
+
74
74
  document.head.appendChild(script);
75
75
  });
76
76
 
@@ -120,14 +120,14 @@ class PaypalPaymentMethod {
120
120
  const gateway = this.getEndpoints().gateway;
121
121
  let url = `${gateway}/v1/customer`;
122
122
  const config = { method: 'GET', headers: { 'Content-Type': 'application/json', 'x-api-key': this.apiKey } };
123
-
123
+
124
124
  let params = [];
125
- if(name) params.push(`name.EQ=${name}`);
126
- if(email) params.push(`email.EQ=${email}`);
127
- if(phone) params.push(`phoneNumber.EQ=${phone}`);
128
-
129
- if(params.length > 0) url += `?${params.join('&')}`;
130
-
125
+ if (name) params.push(`name.EQ=${name}`);
126
+ if (email) params.push(`email.EQ=${email}`);
127
+ if (phone) params.push(`phoneNumber.EQ=${phone}`);
128
+
129
+ if (params.length > 0) url += `?${params.join('&')}`;
130
+
131
131
  const response = await fetch(url, config);
132
132
  return await response.json();
133
133
  }
@@ -161,7 +161,7 @@ class PaypalPaymentMethod {
161
161
  let url = `${gateway}/v2/payment-session/${psGid}/mrn`;
162
162
  const config = {
163
163
  method: 'GET',
164
- headers: { 'Content-Type': 'application/json', 'ps-client-secret': psSecret, 'x-api-key': this.apiKey },
164
+ headers: { 'Content-Type': 'application/json', 'ps-client-secret': psSecret },
165
165
  };
166
166
  const response = await fetch(url, config);
167
167
  const data = await response.json();
@@ -173,14 +173,14 @@ class PaypalPaymentMethod {
173
173
  let url = `${gateway}/v2/payment-session/${psGid}/action`;
174
174
  const config = {
175
175
  method: 'POST',
176
- headers: { 'Content-Type': 'application/json', 'ps-client-secret': psSecret, 'x-api-key': this.apiKey },
176
+ headers: { 'Content-Type': 'application/json', 'ps-client-secret': psSecret },
177
177
  body: JSON.stringify({}),
178
178
  };
179
179
  const response = await fetch(url, config);
180
180
  const data = await response.json();
181
181
  return data?.entity;
182
182
  }
183
-
183
+
184
184
  removeAllChildFromMount() {
185
185
  const mount = document.getElementById(this.mountId);
186
186
  if (mount) mount.innerHTML = '';
@@ -192,7 +192,7 @@ class PaypalPaymentMethod {
192
192
  this.removeAllChildFromMount();
193
193
  if (mount) mount.appendChild(loadingSpinner);
194
194
  }
195
-
195
+
196
196
  showEligibilityIssue() {
197
197
  this.removeAllChildFromMount();
198
198
  if (!this.unMountOnError) {
@@ -204,7 +204,7 @@ class PaypalPaymentMethod {
204
204
  }
205
205
  }
206
206
 
207
- export class PaypalGooglePay extends PaypalPaymentMethod {
207
+ export class SwirepayGooglePay extends PaypalPaymentMethod {
208
208
  static google_pay_sdk_url = "https://pay.google.com/gp/p/js/pay.js";
209
209
 
210
210
  constructor(config) {
@@ -214,7 +214,7 @@ export class PaypalGooglePay extends PaypalPaymentMethod {
214
214
  this.paypalGooglePayConfig = null;
215
215
  this.countryCallingCode = config.countryCallingCode;
216
216
  this.amount = null;
217
-
217
+
218
218
  this.initGooglePay = this.initGooglePay.bind(this);
219
219
 
220
220
  if (document.readyState === "complete" || document.readyState === "interactive") {
@@ -264,7 +264,7 @@ export class PaypalGooglePay extends PaypalPaymentMethod {
264
264
 
265
265
  const googleIcon = document.createElement('img');
266
266
  // googleIcon.src = '/assets/imgs/GOOGLE_PAY.svg';
267
- googleIcon.src = `data:image/svg+xml;utf8,${encodeURIComponent(googleSvgString)}`;
267
+ googleIcon.src = `data:image/svg+xml;utf8,${encodeURIComponent(googleSvgString)}`;
268
268
  googleIcon.alt = 'Google Icon';
269
269
  googleIcon.style.height = '20px';
270
270
  googleIcon.style.width = 'auto';
@@ -287,88 +287,146 @@ export class PaypalGooglePay extends PaypalPaymentMethod {
287
287
  return button;
288
288
  }
289
289
 
290
- async handleGooglePayButtonClick() {
291
- if (!this.googlePayPaymentsClient) {
292
- console.error('no paymentsClient');
293
- return;
294
- }
295
-
296
- if (window.swirepayPayableAmount) {
297
- this.amount = window.swirepayPayableAmount;
298
- } else {
299
- alert("Payment Error: Amount not set");
300
- return;
301
- }
290
+ onPaymentAuthorized(paymentData) {
291
+ return new Promise(async (resolve) => {
292
+ try {
293
+ const value = await this.getPayPalClientToken();
294
+ const billingAddress = paymentData?.paymentMethodData?.info?.billingAddress;
295
+ const customerName = billingAddress?.name ?? null;
296
+ const customerEmail = paymentData?.email ?? null;
297
+ const customerPhone = this.getRobustPhoneNumber(this.countryCallingCode, billingAddress?.phoneNumber);
298
+ if (value) {
299
+ let customerGid;
300
+ const customerData = await this.findCustomer(customerName, customerEmail, customerPhone);
301
+ if (customerData.entity.content[0]?.gid) {
302
+ customerGid = customerData.entity.content[0].gid;
303
+ } else {
304
+ const newCustomer = await this.createCustomer(customerName, customerEmail, customerPhone);
305
+ customerGid = newCustomer.entity?.gid;
306
+ }
307
+ const paymentMethod = {
308
+ type: "WALLET",
309
+ subType: "GOOGLE_PAY_US",
310
+ googlePayUS: {
311
+ apiVersionMinor: paymentData.apiVersionMinor,
312
+ apiVersion: paymentData.apiVersion,
313
+ paymentMethodDescription: paymentData.paymentMethodData.description,
314
+ paymentMethodTokenizationDataType: paymentData.paymentMethodData.tokenizationData.type,
315
+ paymentMethodTokenizationDataToken: paymentData.paymentMethodData.tokenizationData.token,
316
+ paymentMethodType: paymentData.paymentMethodData.type,
317
+ paymentMethodInfo: paymentData.paymentMethodData.info
318
+ },
319
+ customerGid: customerGid,
320
+ }
321
+ let result = await this.addPaymentMethod(paymentMethod);
322
+ const gid = result?.entity?.gid;
323
+ const postData = {
324
+ amount: this.amount,
325
+ captureMethod: 'AUTOMATIC',
326
+ confirmMethod: 'AUTOMATIC',
327
+ currencyCode: this.currencyDetail?.code,
328
+ description: 'Online Payment',
329
+ paymentMethodGid: gid,
330
+ paymentMethodType: ['WALLET'],
331
+ receiptEmail: customerEmail || null,
332
+ receiptSms: customerPhone || null,
333
+ statementDescriptor: 'Google Pay Payment',
334
+ };
335
+ const gateway = this.getEndpoints().gateway;
336
+ const res = await fetch(`${gateway}/v1/payment-session`, {
337
+ method: 'POST',
338
+ headers: { 'Content-Type': 'application/json', 'x-api-key': this.apiKey },
339
+ body: JSON.stringify(postData),
340
+ });
341
+ const resData = await res.json();
342
+
343
+ const orderId = await this.getMrn(resData?.entity?.gid, resData?.entity?.psClientSecret);
344
+ if (window?.paypalGoogle) {
345
+ await window?.paypalGoogle?.Googlepay()?.confirmOrder({ orderId, paymentMethodData: paymentData?.paymentMethodData });
346
+ }
347
+ if (window?.paypal) {
348
+ await window?.paypal?.Googlepay()?.confirmOrder({ orderId, paymentMethodData: paymentData?.paymentMethodData });
349
+ }
350
+ await this.action(resData?.entity?.gid, resData?.entity?.psClientSecret);
351
+ resolve({ transactionState: "SUCCESS" });
352
+ if (this.successCallback) await this.successCallback(resData?.entity);
353
+ }
354
+ } catch (err) {
355
+ resolve({ transactionState: "ERROR" });
356
+ }
357
+ });
358
+ }
359
+
360
+
361
+ getGooglePaymentsClient() {
362
+ const usageMode = this.test ? 'TEST' : 'PRODUCTION';
363
+ return new window.google.payments.api.PaymentsClient({
364
+ environment: usageMode,
365
+ paymentDataCallbacks: {
366
+ onPaymentAuthorized: this.onPaymentAuthorized.bind(this),
367
+ }
368
+ });
369
+ }
302
370
 
303
- if (this.processStartCallback) this.processStartCallback();
304
371
 
305
- const { paymentDataRequest } = this.constructGooglePayPaymentDataRequest();
372
+ async initGooglePay() {
306
373
  try {
307
- const paymentData = await this.googlePayPaymentsClient?.loadPaymentData(paymentDataRequest);
308
- const value = await this.getPayPalClientToken();
309
- const billingAddress = paymentData?.paymentMethodData?.info?.billingAddress;
310
- const customerName = billingAddress?.name ?? null;
311
- const customerEmail = paymentData?.email ?? null;
312
- const customerPhone = this.getRobustPhoneNumber(this.countryCallingCode, billingAddress?.phoneNumber);
313
-
314
- if (value) {
315
- let customerGid;
316
- const customerData = await this.findCustomer(customerName, customerEmail, customerPhone);
317
- if (customerData.entity.content[0]?.gid) {
318
- customerGid = customerData.entity.content[0].gid;
319
- } else {
320
- const newCustomer = await this.createCustomer(customerName, customerEmail, customerPhone);
321
- customerGid = newCustomer.entity?.gid;
322
- }
323
- const paymentMethod = {
324
- type: "WALLET",
325
- subType: "GOOGLE_PAY_US",
326
- googlePayUS: {
327
- apiVersionMinor: paymentData.apiVersionMinor,
328
- apiVersion: paymentData.apiVersion,
329
- paymentMethodDescription: paymentData.paymentMethodData.description,
330
- paymentMethodTokenizationDataType: paymentData.paymentMethodData.tokenizationData.type,
331
- paymentMethodTokenizationDataToken: paymentData.paymentMethodData.tokenizationData.token,
332
- paymentMethodType: paymentData.paymentMethodData.type,
333
- paymentMethodInfo: paymentData.paymentMethodData.info
334
- },
335
- customerGid: customerGid,
374
+ const token = await this.getPayPalClientToken();
375
+ const tokenJson = JSON.parse(atob(token));
376
+
377
+ // load PayPal SDK
378
+ await this.script_to_head({
379
+ id: 'paypalSDK-google',
380
+ src: `${PaypalPaymentMethod.paypal_sdk_url}?client-id=${tokenJson.clientId}&currency=${this.currencyDetail.code}&intent=${PaypalPaymentMethod.intent}&components=buttons,googlepay`,
381
+ "data-namespace": "paypalGoogle"
382
+ });
383
+
384
+ // load Google Pay SDK
385
+ await this.script_to_head({
386
+ id: 'googlePaySDK',
387
+ src: SwirepayGooglePay.google_pay_sdk_url,
388
+ async: true
389
+ });
390
+
391
+ const interval = setInterval(() => {
392
+ if (window.google?.payments?.api && window.paypalGoogle) {
393
+ clearInterval(interval);
394
+ this.setupGooglePay();
336
395
  }
337
- let result = await this.addPaymentMethod(paymentMethod);
338
- const gid = result?.entity?.gid;
339
-
340
- const postData = {
341
- amount: this.amount,
342
- captureMethod: 'AUTOMATIC',
343
- confirmMethod: 'AUTOMATIC',
344
- currencyCode: this.currencyDetail?.code,
345
- description: 'Online Payment',
346
- paymentMethodGid: gid,
347
- paymentMethodType: ['WALLET'],
348
- receiptEmail: customerEmail || null,
349
- receiptSms: customerPhone || null,
350
- statementDescriptor: 'Google Pay Payment',
351
- };
352
-
353
- const gateway = this.getEndpoints().gateway;
354
- const res = await fetch(`${gateway}/v1/payment-session`, {
355
- method: 'POST',
356
- headers: { 'Content-Type': 'application/json', 'x-api-key': this.apiKey },
357
- body: JSON.stringify(postData),
358
- });
359
- const resData = await res.json();
360
-
361
- const orderId = await this.getMrn(resData?.entity?.gid, resData?.entity?.psClientSecret);
362
- await window?.paypal?.Googlepay()?.confirmOrder({ orderId, paymentMethodData: paymentData?.paymentMethodData });
363
- await this.action(resData?.entity?.gid, resData?.entity?.psClientSecret);
364
- if (this.successCallback) await this.successCallback(resData?.entity);
365
- }
396
+ }, 50);
397
+
366
398
  } catch (err) {
367
- console.error('Google Pay Error:', err);
368
- if (this.failCallback) await this.failCallback(err);
399
+ console.error(err);
400
+ this.showEligibilityIssue();
369
401
  }
370
402
  }
371
403
 
404
+ setupGooglePay() {
405
+ this.googlePayPaymentsClient = new window.google.payments.api.PaymentsClient({
406
+ environment: this.test ? "TEST" : "PRODUCTION",
407
+ });
408
+
409
+ // get PayPal googlepay config
410
+ window.paypalGoogle.Googlepay().config().then(cfg => {
411
+ this.paypalGooglePayConfig = cfg;
412
+
413
+ const { allowedPaymentMethods } = this.constructGooglePayPaymentDataRequest();
414
+
415
+ this.googlePayPaymentsClient.isReadyToPay({
416
+ apiVersion: cfg.apiVersion,
417
+ apiVersionMinor: cfg.apiVersionMinor,
418
+ allowedPaymentMethods
419
+ }).then(res => {
420
+ if (res.result && cfg.isEligible) {
421
+ this.showGooglePayButton();
422
+ } else {
423
+ this.showEligibilityIssue();
424
+ }
425
+ });
426
+
427
+ }).catch(() => this.showEligibilityIssue());
428
+ }
429
+
372
430
  showGooglePayButton() {
373
431
  const googlePayButton = this.GooglePayButton({
374
432
  onClick: () => this.handleGooglePayButtonClick(),
@@ -380,118 +438,64 @@ export class PaypalGooglePay extends PaypalPaymentMethod {
380
438
  if (mount) mount.appendChild(googlePayButton);
381
439
  }
382
440
 
383
- getPaypalGooglePayConfig() {
384
- const paymentsClient = this.getGooglePaymentsClient();
385
- this.googlePayPaymentsClient = paymentsClient;
386
-
387
- this.paypalSDK?.Googlepay?.()?.config()?.then((currentPaypalGooglePayConfig) => {
388
- this.paypalGooglePayConfig = currentPaypalGooglePayConfig;
389
- const { allowedPaymentMethods, baseRequest } = this.constructGooglePayPaymentDataRequest();
390
-
391
- paymentsClient?.isReadyToPay({ ...baseRequest, allowedPaymentMethods })
392
- ?.then((response) => {
393
- if (response.result && currentPaypalGooglePayConfig.isEligible) {
394
- this.showGooglePayButton();
395
- return;
396
- }
397
- this.showEligibilityIssue();
398
- })?.catch((err) => { this.showEligibilityIssue(); });
399
- })?.catch((err) => { this.showEligibilityIssue(); });
400
- }
401
-
402
- getGooglePaymentsClient() {
403
- const usageMode = this.test ? 'TEST' : 'PRODUCTION';
404
- return new window.google.payments.api.PaymentsClient({ environment: String(usageMode) });
405
- }
406
-
407
441
  constructGooglePayPaymentDataRequest() {
408
- const currentAmount = window.swirepayPayableAmount || 0;
409
- if (!this.paypalGooglePayConfig || !this.currencyDetail) return {};
442
+ const amount = window.swirepayPayableAmount || 0;
443
+ if (!this.paypalGooglePayConfig) return {};
444
+
445
+ const cfg = this.paypalGooglePayConfig;
446
+ const baseRequest = {
447
+ apiVersion: cfg.apiVersion,
448
+ apiVersionMinor: cfg.apiVersionMinor,
449
+ };
410
450
 
411
451
  const paymentDataRequest = {
412
- apiVersion: this.paypalGooglePayConfig?.apiVersion,
413
- apiVersionMinor: this.paypalGooglePayConfig?.apiVersionMinor,
414
- emailRequired: true,
415
- merchantInfo: {
416
- merchantName: 'Swirepay',
417
- merchantId: this.paypalGooglePayConfig?.merchantInfo?.merchantId,
418
- },
419
- allowedPaymentMethods: [{
420
- type: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.type,
421
- parameters: {
422
- allowedAuthMethods: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.parameters?.allowedAuthMethods,
423
- allowedCardNetworks: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.parameters?.allowedCardNetworks,
424
- billingAddressRequired: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.parameters?.billingAddressRequired,
425
- billingAddressParameters: {
426
- format: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.parameters?.billingAddressParameters?.format,
427
- phoneNumberRequired: true,
428
- },
429
- },
430
- tokenizationSpecification: {
431
- type: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.tokenizationSpecification?.type,
432
- parameters: {
433
- gateway: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.tokenizationSpecification?.parameters?.gateway,
434
- gatewayMerchantId: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.tokenizationSpecification?.parameters?.gatewayMerchantId,
435
- },
436
- },
437
- }],
452
+ ...baseRequest,
453
+ merchantInfo: cfg.merchantInfo,
438
454
  transactionInfo: {
439
- countryCode: this.currencyDetail?.countryAlpha2,
440
- currencyCode: this.currencyDetail?.code,
441
- totalPriceStatus: 'FINAL',
442
- totalPrice: this.AmountDivideByHundred(currentAmount),
443
- checkoutOption: 'COMPLETE_IMMEDIATE_PURCHASE',
444
- }
445
- };
446
- return {
447
- allowedPaymentMethods: this.paypalGooglePayConfig?.allowedPaymentMethods,
448
- paymentDataRequest,
449
- baseRequest: { apiVersion: this.paypalGooglePayConfig?.apiVersion, apiVersionMinor: this.paypalGooglePayConfig?.apiVersionMinor },
450
- tokenizationSpecification: this.paypalGooglePayConfig?.allowedPaymentMethods?.[0]?.tokenizationSpecification,
455
+ countryCode: this.currencyDetail.countryAlpha2,
456
+ currencyCode: this.currencyDetail.code,
457
+ totalPriceStatus: "FINAL",
458
+ totalPrice: this.AmountDivideByHundred(amount),
459
+ checkoutOption: "COMPLETE_IMMEDIATE_PURCHASE",
460
+ },
461
+ allowedPaymentMethods: cfg.allowedPaymentMethods,
451
462
  };
452
- }
453
463
 
454
- async initGooglePay() {
455
- if (!this.accountGid) return;
456
-
457
- this.showLoading();
458
- try {
459
- const data = await this.getPayPalClientToken();
460
- const value = atob(data);
461
- const value_json = JSON.parse(value);
462
-
463
- // Unified Request: buttons,googlepay,applepay
464
- await this.script_to_head({
465
- id: 'paypalSDK-google',
466
- src: this.test ? `${PaypalPaymentMethod.paypal_sdk_url}?client-id=${value_json?.clientId}&enable-funding=venmo&currency=${this.currencyDetail?.code}&intent=${PaypalPaymentMethod.intent}&buyer-country=${this.currencyDetail.countryAlpha2}&merchant-id=${value_json?.merchantId}&components=buttons,googlepay,applepay` : `${PaypalPaymentMethod.paypal_sdk_url}?client-id=${value_json?.clientId}&enable-funding=venmo&currency=${this.currencyDetail?.code}&intent=${PaypalPaymentMethod.intent}&merchant-id=${value_json?.merchantId}&components=buttons,googlepay,applepay`, // Added applepay
467
- "data-client-token": value_json?.token?.client_token,
468
- "data-namespace": "paypalGoogle",
469
- });
464
+ return { baseRequest, paymentDataRequest, allowedPaymentMethods: cfg.allowedPaymentMethods };
465
+ }
470
466
 
471
- await this.script_to_head({
472
- id: 'googlePaySDK',
473
- src: PaypalGooglePay.google_pay_sdk_url,
474
- async: true,
475
- });
476
467
 
477
- const checkGooglePaySDKInterval = setInterval(() => {
478
- if (window.google?.payments?.api && this.paypalSDK) {
479
- this.getPaypalGooglePayConfig();
480
- clearInterval(checkGooglePaySDKInterval);
481
- }
482
- }, 50);
468
+ async handleGooglePayButtonClick() {
469
+ if (!this.googlePayPaymentsClient) {
470
+ console.error('no paymentsClient');
471
+ return;
472
+ }
473
+ if (window.swirepayPayableAmount) {
474
+ this.amount = window.swirepayPayableAmount;
475
+ } else {
476
+ alert("Payment Error: Amount not set");
477
+ return;
478
+ }
479
+ if (this.processStartCallback) this.processStartCallback();
480
+ try {
481
+ const { paymentDataRequest } = this.constructGooglePayPaymentDataRequest();
482
+ paymentDataRequest.callbackIntents = ["PAYMENT_AUTHORIZATION"];
483
+ const paymentsClient = this.getGooglePaymentsClient();
484
+ await paymentsClient.loadPaymentData(paymentDataRequest);
483
485
  } catch (err) {
484
- console.error(err);
485
- this.showEligibilityIssue();
486
+ console.error("Google Pay Error:", err);
487
+ this.failCallback?.(err);
486
488
  }
487
489
  }
488
490
  }
489
491
 
490
- export class PaypalApplePay extends PaypalPaymentMethod {
492
+
493
+ export class SwirepayApplePay extends PaypalPaymentMethod {
491
494
  constructor(config) {
492
495
  super({ ...config, namespace: 'paypalApple' });
493
496
  this.isApplePayEligible = false;
494
-
497
+ this.shopName = config.shopName;
498
+
495
499
  this.checkAppleEligible = this.checkAppleEligible.bind(this);
496
500
  this.handleClick = this.handleClick.bind(this);
497
501
 
@@ -506,7 +510,7 @@ export class PaypalApplePay extends PaypalPaymentMethod {
506
510
  waitForPayPalComponent(componentName, timeout = 5000) {
507
511
  return new Promise((resolve, reject) => {
508
512
  const startTime = Date.now();
509
-
513
+
510
514
  const check = () => {
511
515
  // Check if paypal exists AND the specific component exists
512
516
  if (this.paypalSDK && this.paypalSDK[componentName]) {
@@ -518,7 +522,7 @@ export class PaypalApplePay extends PaypalPaymentMethod {
518
522
  setTimeout(check, 50);
519
523
  }
520
524
  };
521
-
525
+
522
526
  check();
523
527
  });
524
528
  }
@@ -533,7 +537,7 @@ export class PaypalApplePay extends PaypalPaymentMethod {
533
537
  this.showLoading();
534
538
  const enabled = await this.existsApplePayJsApi();
535
539
  if (!enabled || !this.accountGid) {
536
- if(this.failCallback && !this.unMountOnError) this.failCallback('Payment method not supported...!');
540
+ if (this.failCallback && !this.unMountOnError) this.failCallback('Payment method not supported...!');
537
541
  this.showEligibilityIssue();
538
542
  return;
539
543
  }
@@ -542,17 +546,14 @@ export class PaypalApplePay extends PaypalPaymentMethod {
542
546
  const data = await this.getPayPalClientToken();
543
547
  const value = window.atob(data);
544
548
  const value_json = JSON.parse(value);
545
-
549
+
546
550
  // Unified Request: buttons,googlepay,applepay
547
551
  await this.script_to_head({
548
- id: 'paypalSDK-apple',
552
+ id: 'paypalSDK-apple',
549
553
  src: `${PaypalPaymentMethod.paypal_sdk_url}?client-id=${value_json?.clientId}&enable-funding=venmo&currency=${this.currencyDetail?.code}&intent=${PaypalPaymentMethod.intent}&merchant-id=${value_json?.merchantId}&components=buttons,googlepay,applepay`, // Added googlepay
550
- "data-client-token": value_json?.token?.client_token,
554
+ // "data-client-token": value_json?.token?.client_token,
551
555
  "data-namespace": "paypalApple",
552
556
  });
553
-
554
-
555
- // confirm the paypal sdk has loaded in before proceeding (5secs time limit)
556
557
  try {
557
558
  await this.waitForPayPalComponent('Applepay');
558
559
  } catch (waitError) {
@@ -596,8 +597,8 @@ export class PaypalApplePay extends PaypalPaymentMethod {
596
597
 
597
598
  const button = document.createElement('div');
598
599
  button.className = 'apple-pay-button';
599
- button.onclick = this.handleClick;
600
-
600
+ button.onclick = this.handleClick;
601
+
601
602
  const mount = document.getElementById(this.mountId);
602
603
  this.removeAllChildFromMount();
603
604
  if (mount) mount.appendChild(button);
@@ -626,15 +627,15 @@ export class PaypalApplePay extends PaypalPaymentMethod {
626
627
 
627
628
  return new Promise((resolve, reject) => {
628
629
  const session = new window.ApplePaySession(4, paymentRequest);
629
-
630
+
630
631
  session.oncancel = (e) => reject("Payment cancelled");
631
-
632
+
632
633
  session.onvalidatemerchant = async (event) => {
633
634
  try {
634
635
  const applepay = this.paypalSDK.Applepay();
635
636
  const payload = await applepay.validateMerchant({
636
637
  validationUrl: event.validationURL,
637
- displayName: "My Shop",
638
+ displayName: this.shopName,
638
639
  });
639
640
  session.completeMerchantValidation(payload.merchantSession);
640
641
  } catch (err) {
@@ -688,7 +689,7 @@ export class PaypalApplePay extends PaypalPaymentMethod {
688
689
  const gid = pmResult?.entity?.gid;
689
690
 
690
691
  const postData = {
691
- amount: window.swirepayPayableAmount,
692
+ amount: window.swirepayPayableAmount,
692
693
  captureMethod: 'AUTOMATIC',
693
694
  confirmMethod: 'AUTOMATIC',
694
695
  currencyCode: this.currencyDetail.code,
@@ -707,16 +708,16 @@ export class PaypalApplePay extends PaypalPaymentMethod {
707
708
  body: JSON.stringify(postData),
708
709
  });
709
710
  const resData = await res.json();
710
-
711
+
711
712
  const orderId = await this.getMrn(resData?.entity?.gid, resData?.entity?.psClientSecret);
712
713
  await this.paypalSDK?.Applepay().confirmOrder({
713
714
  orderId,
714
715
  token: payment.token,
715
716
  billingContact: payment.billingContact,
716
717
  });
717
-
718
+
718
719
  await this.action(resData?.entity?.gid, resData?.entity?.psClientSecret);
719
-
720
+
720
721
  session.completePayment(window.ApplePaySession.STATUS_SUCCESS);
721
722
  resolve({ orderId, ...resData });
722
723
  } catch (err) {
@@ -748,10 +749,9 @@ export class PaypalApplePay extends PaypalPaymentMethod {
748
749
  [{ label: 'Total', amount: payableAmount }],
749
750
  'Total'
750
751
  ).then((result) => {
751
- if(this.successCallback) this.successCallback(result);
752
- // console.log("Payment success:", result);
752
+ if (this.successCallback) this.successCallback(result);
753
753
  }).catch((err) => {
754
- if(this.failCallback) this.failCallback(err);
754
+ if (this.failCallback) this.failCallback(err);
755
755
  console.error("Payment failed:", err);
756
756
  });
757
757
  }