@paydock/client-sdk 1.140.0-beta → 1.140.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.
- package/README.md +57 -87
- package/bundles/index.cjs +1 -1
- package/bundles/index.mjs +1 -1
- package/bundles/widget.umd.js +1 -1
- package/bundles/widget.umd.min.js +1 -1
- package/docs/open-wallet-buttons-examples.md +57 -87
- package/package.json +1 -1
- package/slate.md +57 -87
|
@@ -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((
|
|
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((
|
|
183
|
+
button.onCancel(() => {
|
|
188
184
|
console.log("Payment cancelled");
|
|
189
|
-
// Handle cancellation
|
|
190
185
|
});
|
|
191
186
|
|
|
192
|
-
button.onShippingAddressChange(async (
|
|
193
|
-
|
|
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 (
|
|
202
|
-
|
|
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(
|
|
236
|
-
// Your total calculation logic
|
|
228
|
+
async function updateTotal(shippingOption) {
|
|
237
229
|
const baseAmount = 100;
|
|
238
|
-
const shippingAmount =
|
|
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,
|
|
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
|
-
|
|
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 (
|
|
573
|
-
const response = await updateShippingCosts(
|
|
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 (
|
|
581
|
-
const response = await updateTotal(
|
|
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
|
-
|
|
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((
|
|
583
|
+
button.onCancel(() => {
|
|
599
584
|
console.log("Payment cancelled");
|
|
600
|
-
// Handle cancellation
|
|
601
585
|
});
|
|
602
586
|
|
|
603
|
-
button.onClick((
|
|
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(
|
|
619
|
+
async function updateTotal(shippingOption) {
|
|
637
620
|
const baseAmount = 100;
|
|
638
|
-
const shippingAmount =
|
|
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
|
|
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
|
|
694
|
-
button.onClick((
|
|
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
|
-
//
|
|
703
|
-
button.onClick((
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
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((
|
|
772
|
-
console.log("Wallet checkout cancelled"
|
|
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 (
|
|
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)` - **
|
|
798
|
-
- `onShippingOptionsChange(handler)` - **
|
|
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
|
|
777
|
+
// Required handler
|
|
804
778
|
button.onSuccess(handler); // Always required
|
|
805
|
-
|
|
806
|
-
|
|
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); //
|
|
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
|
-
|
|
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.
|
|
107
|
+
"version": "1.140.1",
|
|
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",
|