@paydock/client-sdk 1.140.0-beta → 1.141.0-beta

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.
@@ -330,6 +330,7 @@ Class ZipmoneyCheckoutButton is wrapper of CheckoutButton transform usual button
330
330
  * [new ZipmoneyCheckoutButton(selector, publicKey, [gatewayId], [gatewayId])](#user-content-cb_new_ZipmoneyCheckoutButton_new)
331
331
  * [.setSuspendedRedirectUri(string)](#user-content-cb_ZipmoneyCheckoutButton+setSuspendedRedirectUri)
332
332
  * [.setRedirectUrl(string)](#user-content-cb_ZipmoneyCheckoutButton+setRedirectUrl)
333
+ * [.onClick(handler)](#user-content-cb_ZipmoneyCheckoutButton+onClick)
333
334
  * [.on(eventName, cb)](#user-content-cb_CheckoutButton+on)
334
335
  * [.close()](#user-content-cb_CheckoutButton+close)
335
336
  * [.onFinishInsert(selector, dataType)](#user-content-cb_CheckoutButton+onFinishInsert)
@@ -388,6 +389,27 @@ The merchant's customer would be automatically redirected to this URL after the
388
389
  | --- | --- | --- |
389
390
  | string | <code>url</code> | URL for redirect |
390
391
 
392
+ <a name="cb_ZipmoneyCheckoutButton+onClick" id="cb_ZipmoneyCheckoutButton+onClick" href="#user-content-cb_ZipmoneyCheckoutButton+onClick">&nbsp;</a>
393
+
394
+ ### zipmoneyCheckoutButton.onClick(handler)
395
+ Subscribe to the click event with an async handler.
396
+ The checkout flow will wait for the async handler to complete before proceeding.
397
+ If the handler resolves to `false`, the checkout flow will be cancelled.
398
+
399
+ **Kind**: instance method of [<code>ZipmoneyCheckoutButton</code>](#user-content-cb_ZipmoneyCheckoutButton)
400
+
401
+ | Param | Description |
402
+ | --- | --- |
403
+ | handler | Async function to be called when the button is clicked |
404
+
405
+ **Example**
406
+
407
+ ```javascript
408
+ button.onClick(async () => {
409
+ const isValid = await fetchDataFromServer();
410
+ return isValid; // return false to stop checkout
411
+ });
412
+ ```
391
413
  <a name="cb_CheckoutButton+on" id="cb_CheckoutButton+on" href="#user-content-cb_CheckoutButton+on">&nbsp;</a>
392
414
 
393
415
  ### zipmoneyCheckoutButton.on(eventName, cb)
@@ -163,44 +163,37 @@ button.setEnv('sandbox');
163
163
 
164
164
  button.setEnv('sandbox');
165
165
 
166
- button.onUnavailable((data) => {
166
+ button.onUnavailable(({ data }) => {
167
167
  console.log("Apple Pay not available:", data);
168
- // Show alternative payment methods
169
168
  });
170
169
 
171
- button.onClick((data) => {
170
+ button.onClick(() => {
172
171
  console.log("Apple Pay button clicked");
173
- // Perform pre-payment validation
174
172
  });
175
173
 
176
- button.onSuccess((data) => {
174
+ button.onSuccess(({ data }) => {
177
175
  console.log("Payment successful:", data);
178
- // Process the OTT token on your backend
179
176
  processPayment(data.token);
180
177
  });
181
178
 
182
- button.onError((data) => {
179
+ button.onError(({ data }) => {
183
180
  console.error("Payment error:", data);
184
- // Handle error appropriately
185
181
  });
186
182
 
187
- button.onCancel((data) => {
183
+ button.onCancel(() => {
188
184
  console.log("Payment cancelled");
189
- // Handle cancellation
190
185
  });
191
186
 
192
- button.onShippingAddressChange(async (addressData) => {
193
- // Update shipping costs based on address
194
- const response = await updateShippingCosts(addressData);
187
+ button.onShippingAddressChange(async ({ data }) => {
188
+ const response = await updateShippingCosts(data);
195
189
  return {
196
190
  amount: response.newAmount,
197
191
  shipping_options: response.shippingOptions
198
192
  };
199
193
  });
200
194
 
201
- button.onShippingOptionsChange(async (optionData) => {
202
- // Update total based on selected shipping option
203
- const response = await updateTotal(optionData);
195
+ button.onShippingOptionsChange(async ({ data }) => {
196
+ const response = await updateTotal(data);
204
197
  return {
205
198
  amount: response.newAmount
206
199
  };
@@ -232,17 +225,15 @@ button.setEnv('sandbox');
232
225
  };
233
226
  }
234
227
 
235
- async function updateTotal(optionData) {
236
- // Your total calculation logic
228
+ async function updateTotal(shippingOption) {
237
229
  const baseAmount = 100;
238
- const shippingAmount = optionData.amount || optionData.data?.amount;
230
+ const shippingAmount = shippingOption.amount;
239
231
  return {
240
232
  newAmount: baseAmount + shippingAmount
241
233
  };
242
234
  }
243
235
 
244
236
  function processPayment(ottToken) {
245
- // Send OTT token to your backend for payment processing
246
237
  fetch('/api/process-payment', {
247
238
  method: 'POST',
248
239
  headers: { 'Content-Type': 'application/json' },
@@ -295,21 +286,19 @@ let button = new paydock.ApplePayOpenWalletButton(
295
286
  button.load();
296
287
  ```
297
288
 
298
- When supporting shipping, the methods `onShippingAddressChange` and `onShippingOptionsChange` are required to update the shipping address and options.
289
+ When supporting shipping, registering `onShippingAddressChange` and `onShippingOptionsChange` handlers lets you recalculate totals and update shipping options dynamically. If no handler is registered (or the handler throws), the SDK auto-accepts with the current amount and options.
299
290
 
300
291
  ```javascript
301
- button.onShippingAddressChange(async function(data) {
292
+ button.onShippingAddressChange(async function({ data }) {
302
293
  console.log("Shipping address has been updated", data);
303
- // Call your backend to recalculate shipping
304
294
  return {
305
295
  amount: newAmount,
306
296
  shipping_options: updatedShippingOptions
307
297
  };
308
298
  });
309
299
 
310
- button.onShippingOptionsChange(async function(data) {
300
+ button.onShippingOptionsChange(async function({ data }) {
311
301
  console.log("Shipping option selected", data);
312
- // Update total based on selected shipping option
313
302
  return {
314
303
  amount: newTotalAmount
315
304
  };
@@ -563,46 +552,40 @@ The GooglePayOpenWalletButton constructor accepts the following parameters:
563
552
 
564
553
  button.setEnv('sandbox');
565
554
 
566
- // Required handlers
567
- button.onSuccess((data) => {
555
+ button.onSuccess(({ data }) => {
568
556
  console.log("Payment successful:", data);
569
557
  processPayment(data.token);
570
558
  });
571
559
 
572
- button.onShippingAddressChange(async (addressData) => {
573
- const response = await updateShippingCosts(addressData);
560
+ button.onShippingAddressChange(async ({ data }) => {
561
+ const response = await updateShippingCosts(data);
574
562
  return {
575
563
  amount: response.newAmount,
576
564
  shipping_options: response.shippingOptions
577
565
  };
578
566
  });
579
567
 
580
- button.onShippingOptionsChange(async (optionData) => {
581
- const response = await updateTotal(optionData);
568
+ button.onShippingOptionsChange(async ({ data }) => {
569
+ const response = await updateTotal(data);
582
570
  return {
583
571
  amount: response.newAmount
584
572
  };
585
573
  });
586
574
 
587
- // Optional handlers
588
- button.onUnavailable((data) => {
575
+ button.onUnavailable(({ data }) => {
589
576
  console.log("Google Pay not available:", data);
590
- // Show alternative payment methods
591
577
  });
592
578
 
593
- button.onError((data) => {
579
+ button.onError(({ data }) => {
594
580
  console.error("Payment error:", data);
595
- // Handle error appropriately
596
581
  });
597
582
 
598
- button.onCancel((data) => {
583
+ button.onCancel(() => {
599
584
  console.log("Payment cancelled");
600
- // Handle cancellation
601
585
  });
602
586
 
603
- button.onClick((data) => {
587
+ button.onClick(() => {
604
588
  console.log("Google Pay button clicked");
605
- // Perform pre-payment validation
606
589
  });
607
590
 
608
591
  button.load();
@@ -633,9 +616,9 @@ The GooglePayOpenWalletButton constructor accepts the following parameters:
633
616
  };
634
617
  }
635
618
 
636
- async function updateTotal(optionData) {
619
+ async function updateTotal(shippingOption) {
637
620
  const baseAmount = 100;
638
- const shippingAmount = optionData.amount || optionData.data?.amount;
621
+ const shippingAmount = shippingOption.amount;
639
622
  return {
640
623
  newAmount: baseAmount + shippingAmount
641
624
  };
@@ -661,7 +644,7 @@ Both `ApplePayOpenWalletButton` and `GooglePayOpenWalletButton` share the same e
661
644
  If the customer's browser is not supported, or the customer does not have any card added to their wallet, the button will not load. In this case the callback onUnavailable() will be called. You can define the behavior of this function before loading the button.
662
645
 
663
646
  ```javascript
664
- button.onUnavailable((data) => console.log("No wallet button available", data));
647
+ button.onUnavailable(({ data }) => console.log("No wallet button available", data));
665
648
  ```
666
649
 
667
650
  ### Service type validation
@@ -677,7 +660,7 @@ let button = new paydock.GooglePayOpenWalletButton(
677
660
  meta
678
661
  );
679
662
 
680
- button.onError((data) => {
663
+ button.onError(({ data }) => {
681
664
  // Error: Service configuration type 'ApplePay' does not match expected wallet type 'google'.
682
665
  console.error(data.error.message);
683
666
  });
@@ -687,31 +670,26 @@ button.load();
687
670
 
688
671
  ### Performing actions when the wallet button is clicked
689
672
 
690
- You can perform validations or actions when the user clicks on the wallet button. The callback supports both synchronous and asynchronous operations using the `attachResult` method.
673
+ You can perform validations or actions when the user clicks on the wallet button. The callback supports both synchronous and asynchronous operations using its return value: return `false` to abort, return a `Promise` to defer the wallet sheet, or throw an error to abort.
691
674
 
692
675
  ```javascript
693
- // Synchronous example
694
- button.onClick((data) => {
676
+ // Synchronous — continue normally
677
+ button.onClick(() => {
695
678
  console.log("Perform actions on button click");
696
- // Perform validation logic
697
- // Optionally use attachResult to control flow
698
- data.attachResult(true); // Continue with payment
699
- // data.attachResult(false); // Halt payment
700
679
  });
701
680
 
702
- // Asynchronous example
703
- button.onClick((data) => {
704
- // Attach a Promise to control the wallet flow
705
- data.attachResult(
706
- fetch('/api/validate-order')
707
- .then(response => response.json())
708
- .then(result => {
709
- if (!result.valid) {
710
- throw new Error('Order validation failed');
711
- }
712
- return result;
713
- })
714
- );
681
+ // Synchronous — return false to abort the payment flow
682
+ button.onClick(() => {
683
+ if (!isOrderValid()) return false;
684
+ });
685
+
686
+ // Asynchronous — defer the wallet sheet until the promise resolves
687
+ button.onClick(async () => {
688
+ const response = await fetch('/api/validate-order');
689
+ const result = await response.json();
690
+ if (!result.valid) {
691
+ throw new Error('Order validation failed');
692
+ }
715
693
  });
716
694
  ```
717
695
 
@@ -720,13 +698,12 @@ button.onClick((data) => {
720
698
  When the One Time Token (OTT) is successfully created, the onSuccess callback will be called with the token data. **This callback is required** - if no handler is provided, an error will be thrown.
721
699
 
722
700
  ```javascript
723
- button.onSuccess((data) => {
701
+ button.onSuccess(({ data }) => {
724
702
  console.log("OTT created successfully:", data.token);
725
703
  console.log("Amount:", data.amount);
726
704
  console.log("Shipping:", data.shipping);
727
705
  console.log("Billing:", data.billing);
728
706
 
729
- // Use the OTT token to complete payment on your backend
730
707
  fetch('/api/process-payment', {
731
708
  method: 'POST',
732
709
  headers: { 'Content-Type': 'application/json' },
@@ -754,11 +731,10 @@ googlePayButton.setMeta({ ...meta, amount: 29.99, merchant_name: 'Updated Store'
754
731
  Register a callback function to handle errors that occur during wallet operations, including service type mismatches.
755
732
 
756
733
  ```javascript
757
- button.onError((data) => {
734
+ button.onError(({ data }) => {
758
735
  console.error("Open Wallet error:", data.error);
759
736
  console.log("Error context:", data.context);
760
737
 
761
- // Show user-friendly error message
762
738
  showErrorMessage("Payment initialization failed. Please try again.");
763
739
  });
764
740
  ```
@@ -768,10 +744,8 @@ button.onError((data) => {
768
744
  When the user cancels or closes the wallet payment interface, you can perform cleanup operations.
769
745
 
770
746
  ```javascript
771
- button.onCancel((data) => {
772
- console.log("Wallet checkout cancelled", data);
773
-
774
- // Perform cleanup or redirect user
747
+ button.onCancel(() => {
748
+ console.log("Wallet checkout cancelled");
775
749
  window.location.href = '/checkout';
776
750
  });
777
751
  ```
@@ -788,22 +762,24 @@ button.destroy();
788
762
  The above events can be used in a more generic way via the `eventEmitter.subscribe` method internally, but the recommended approach is to use the dedicated event handler methods provided by the button classes.
789
763
 
790
764
  **Available Event Handler Methods:**
791
- - `onClick(handler)` - Button click events (supports attachResult for flow control)
765
+ - `onClick(handler)` - Button click events (return `false` to abort, `Promise` to defer)
792
766
  - `onSuccess(handler)` - **Required** - OTT creation success events
793
767
  - `onUnavailable(handler)` - Wallet unavailable events (supports Promise pattern)
794
768
  - `onError(handler)` - Error events (supports Promise pattern)
795
769
  - `onCancel(handler)` - Checkout cancellation events (supports Promise pattern)
796
770
  - `onLoaded(handler)` - Button loaded/rendered events
797
- - `onShippingAddressChange(handler)` - **Required for shipping** - Address change events
798
- - `onShippingOptionsChange(handler)` - **Required for shipping options** - Option change events
771
+ - `onShippingAddressChange(handler)` - **Recommended for shipping** - Address change events (auto-accepted if not registered)
772
+ - `onShippingOptionsChange(handler)` - **Recommended for shipping options** - Option change events (auto-accepted if not registered)
799
773
 
800
774
  **Event Handler Patterns:**
801
775
 
802
776
  ```javascript
803
- // Required handlers (will throw error if not provided)
777
+ // Required handler
804
778
  button.onSuccess(handler); // Always required
805
- button.onShippingAddressChange(handler); // Required when shipping enabled
806
- button.onShippingOptionsChange(handler); // Required when shipping options provided
779
+
780
+ // Recommended when shipping is enabled (auto-accepted if not registered)
781
+ button.onShippingAddressChange(handler);
782
+ button.onShippingOptionsChange(handler);
807
783
 
808
784
  // Optional handlers with Promise support
809
785
  button.onUnavailable(handler); // or await button.onUnavailable()
@@ -811,7 +787,7 @@ button.onError(handler); // or await button.onError()
811
787
  button.onCancel(handler); // or await button.onCancel()
812
788
 
813
789
  // Click handler with flow control
814
- button.onClick(handler); // Use data.attachResult() for async operations
790
+ button.onClick(handler); // Return false to abort, or a Promise to defer
815
791
 
816
792
  // Loaded handler
817
793
  button.onLoaded(handler); // Notified when button renders
@@ -899,20 +875,14 @@ button.load();
899
875
 
900
876
  ### Error Handling Best Practices
901
877
  ```javascript
902
- button.onError(function(data) {
878
+ button.onError(function({ data }) {
903
879
  console.error('Full error object:', data);
904
880
 
905
- // Check different error properties
906
- const errorMessage = data.error?.message ||
907
- data.message ||
908
- 'Unknown error occurred';
881
+ const errorMessage = data.error?.message || 'Unknown error occurred';
909
882
 
910
- // Handle different error types
911
883
  if (data.context?.operation === 'wallet_operation') {
912
- // Handle wallet-specific errors
913
884
  showWalletError(errorMessage);
914
885
  } else {
915
- // Handle general errors
916
886
  showGeneralError(errorMessage);
917
887
  }
918
888
  });
package/package.json CHANGED
@@ -104,7 +104,7 @@
104
104
  }
105
105
  },
106
106
  "name": "@paydock/client-sdk",
107
- "version": "1.140.0-beta",
107
+ "version": "1.141.0-beta",
108
108
  "scripts": {
109
109
  "build:doc": "node docs/html/marked.js",
110
110
  "build:js": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
@@ -208,7 +208,7 @@
208
208
  "npm-run-all2": "6.2.0",
209
209
  "process": "0.11.10",
210
210
  "rimraf": "5.0.7",
211
- "rollup": "4.53.2",
211
+ "rollup": "4.59.0",
212
212
  "rollup-plugin-dts": "6.1.0",
213
213
  "rxjs": "7.8.1",
214
214
  "tsify": "3.0.4",
@@ -221,7 +221,17 @@
221
221
  "sha.js@>=2.0.0 <=2.4.11": "2.4.12",
222
222
  "pbkdf2": ">=3.1.3",
223
223
  "form-data": ">=4.0.4",
224
- "qs": ">=6.14.1"
224
+ "qs": ">=6.14.1",
225
+ "minimatch@^3": "3.1.5",
226
+ "minimatch@^5": "5.1.9",
227
+ "minimatch@^9": "9.0.9",
228
+ "@isaacs/brace-expansion": ">=5.0.1",
229
+ "bn.js": ">=5.2.3",
230
+ "ajv": "8.18.0",
231
+ "serialize-javascript": ">=7.0.3",
232
+ "underscore": ">=1.13.8",
233
+ "dompurify": ">=3.3.2",
234
+ "immutable": ">=5.1.5"
225
235
  },
226
236
  "engines": {
227
237
  "node": ">=16.0.0"