@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.
- package/README.md +79 -87
- package/bundles/index.cjs +2164 -97
- package/bundles/index.cjs.d.ts +24 -9
- package/bundles/index.mjs +2164 -97
- package/bundles/index.mjs.d.ts +24 -9
- package/bundles/types/checkout-button/checkout-button.d.ts.map +1 -1
- package/bundles/types/checkout-button/zipmoney/zipmoney-checkout-button.d.ts +24 -10
- package/bundles/types/checkout-button/zipmoney/zipmoney-checkout-button.d.ts.map +1 -1
- package/bundles/types/checkout-button/zipmoney/zipmoney-contextual.runner.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts +1 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts.map +1 -1
- package/bundles/types/wallet-buttons/wallet-services/apple.wallet-service.d.ts +1 -0
- package/bundles/types/wallet-buttons/wallet-services/apple.wallet-service.d.ts.map +1 -1
- package/bundles/types/wallet-buttons-express/services/apple-pay/apple-pay.wallet-button-express.d.ts +1 -0
- package/bundles/types/wallet-buttons-express/services/apple-pay/apple-pay.wallet-button-express.d.ts.map +1 -1
- package/bundles/widget.umd.js +2164 -97
- package/bundles/widget.umd.js.d.ts +24 -9
- package/bundles/widget.umd.js.min.d.ts +24 -9
- package/bundles/widget.umd.min.js +1 -1
- package/docs/api-checkout-button.md +22 -0
- package/docs/open-wallet-buttons-examples.md +57 -87
- package/package.json +13 -3
- package/slate.md +57 -87
package/slate.md
CHANGED
|
@@ -2229,44 +2229,37 @@ button.setEnv('sandbox');
|
|
|
2229
2229
|
|
|
2230
2230
|
button.setEnv('sandbox');
|
|
2231
2231
|
|
|
2232
|
-
button.onUnavailable((data) => {
|
|
2232
|
+
button.onUnavailable(({ data }) => {
|
|
2233
2233
|
console.log("Apple Pay not available:", data);
|
|
2234
|
-
// Show alternative payment methods
|
|
2235
2234
|
});
|
|
2236
2235
|
|
|
2237
|
-
button.onClick((
|
|
2236
|
+
button.onClick(() => {
|
|
2238
2237
|
console.log("Apple Pay button clicked");
|
|
2239
|
-
// Perform pre-payment validation
|
|
2240
2238
|
});
|
|
2241
2239
|
|
|
2242
|
-
button.onSuccess((data) => {
|
|
2240
|
+
button.onSuccess(({ data }) => {
|
|
2243
2241
|
console.log("Payment successful:", data);
|
|
2244
|
-
// Process the OTT token on your backend
|
|
2245
2242
|
processPayment(data.token);
|
|
2246
2243
|
});
|
|
2247
2244
|
|
|
2248
|
-
button.onError((data) => {
|
|
2245
|
+
button.onError(({ data }) => {
|
|
2249
2246
|
console.error("Payment error:", data);
|
|
2250
|
-
// Handle error appropriately
|
|
2251
2247
|
});
|
|
2252
2248
|
|
|
2253
|
-
button.onCancel((
|
|
2249
|
+
button.onCancel(() => {
|
|
2254
2250
|
console.log("Payment cancelled");
|
|
2255
|
-
// Handle cancellation
|
|
2256
2251
|
});
|
|
2257
2252
|
|
|
2258
|
-
button.onShippingAddressChange(async (
|
|
2259
|
-
|
|
2260
|
-
const response = await updateShippingCosts(addressData);
|
|
2253
|
+
button.onShippingAddressChange(async ({ data }) => {
|
|
2254
|
+
const response = await updateShippingCosts(data);
|
|
2261
2255
|
return {
|
|
2262
2256
|
amount: response.newAmount,
|
|
2263
2257
|
shipping_options: response.shippingOptions
|
|
2264
2258
|
};
|
|
2265
2259
|
});
|
|
2266
2260
|
|
|
2267
|
-
button.onShippingOptionsChange(async (
|
|
2268
|
-
|
|
2269
|
-
const response = await updateTotal(optionData);
|
|
2261
|
+
button.onShippingOptionsChange(async ({ data }) => {
|
|
2262
|
+
const response = await updateTotal(data);
|
|
2270
2263
|
return {
|
|
2271
2264
|
amount: response.newAmount
|
|
2272
2265
|
};
|
|
@@ -2298,17 +2291,15 @@ button.setEnv('sandbox');
|
|
|
2298
2291
|
};
|
|
2299
2292
|
}
|
|
2300
2293
|
|
|
2301
|
-
async function updateTotal(
|
|
2302
|
-
// Your total calculation logic
|
|
2294
|
+
async function updateTotal(shippingOption) {
|
|
2303
2295
|
const baseAmount = 100;
|
|
2304
|
-
const shippingAmount =
|
|
2296
|
+
const shippingAmount = shippingOption.amount;
|
|
2305
2297
|
return {
|
|
2306
2298
|
newAmount: baseAmount + shippingAmount
|
|
2307
2299
|
};
|
|
2308
2300
|
}
|
|
2309
2301
|
|
|
2310
2302
|
function processPayment(ottToken) {
|
|
2311
|
-
// Send OTT token to your backend for payment processing
|
|
2312
2303
|
fetch('/api/process-payment', {
|
|
2313
2304
|
method: 'POST',
|
|
2314
2305
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -2361,21 +2352,19 @@ let button = new paydock.ApplePayOpenWalletButton(
|
|
|
2361
2352
|
button.load();
|
|
2362
2353
|
```
|
|
2363
2354
|
|
|
2364
|
-
When supporting shipping,
|
|
2355
|
+
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.
|
|
2365
2356
|
|
|
2366
2357
|
```javascript
|
|
2367
|
-
button.onShippingAddressChange(async function(data) {
|
|
2358
|
+
button.onShippingAddressChange(async function({ data }) {
|
|
2368
2359
|
console.log("Shipping address has been updated", data);
|
|
2369
|
-
// Call your backend to recalculate shipping
|
|
2370
2360
|
return {
|
|
2371
2361
|
amount: newAmount,
|
|
2372
2362
|
shipping_options: updatedShippingOptions
|
|
2373
2363
|
};
|
|
2374
2364
|
});
|
|
2375
2365
|
|
|
2376
|
-
button.onShippingOptionsChange(async function(data) {
|
|
2366
|
+
button.onShippingOptionsChange(async function({ data }) {
|
|
2377
2367
|
console.log("Shipping option selected", data);
|
|
2378
|
-
// Update total based on selected shipping option
|
|
2379
2368
|
return {
|
|
2380
2369
|
amount: newTotalAmount
|
|
2381
2370
|
};
|
|
@@ -2629,46 +2618,40 @@ The GooglePayOpenWalletButton constructor accepts the following parameters:
|
|
|
2629
2618
|
|
|
2630
2619
|
button.setEnv('sandbox');
|
|
2631
2620
|
|
|
2632
|
-
|
|
2633
|
-
button.onSuccess((data) => {
|
|
2621
|
+
button.onSuccess(({ data }) => {
|
|
2634
2622
|
console.log("Payment successful:", data);
|
|
2635
2623
|
processPayment(data.token);
|
|
2636
2624
|
});
|
|
2637
2625
|
|
|
2638
|
-
button.onShippingAddressChange(async (
|
|
2639
|
-
const response = await updateShippingCosts(
|
|
2626
|
+
button.onShippingAddressChange(async ({ data }) => {
|
|
2627
|
+
const response = await updateShippingCosts(data);
|
|
2640
2628
|
return {
|
|
2641
2629
|
amount: response.newAmount,
|
|
2642
2630
|
shipping_options: response.shippingOptions
|
|
2643
2631
|
};
|
|
2644
2632
|
});
|
|
2645
2633
|
|
|
2646
|
-
button.onShippingOptionsChange(async (
|
|
2647
|
-
const response = await updateTotal(
|
|
2634
|
+
button.onShippingOptionsChange(async ({ data }) => {
|
|
2635
|
+
const response = await updateTotal(data);
|
|
2648
2636
|
return {
|
|
2649
2637
|
amount: response.newAmount
|
|
2650
2638
|
};
|
|
2651
2639
|
});
|
|
2652
2640
|
|
|
2653
|
-
|
|
2654
|
-
button.onUnavailable((data) => {
|
|
2641
|
+
button.onUnavailable(({ data }) => {
|
|
2655
2642
|
console.log("Google Pay not available:", data);
|
|
2656
|
-
// Show alternative payment methods
|
|
2657
2643
|
});
|
|
2658
2644
|
|
|
2659
|
-
button.onError((data) => {
|
|
2645
|
+
button.onError(({ data }) => {
|
|
2660
2646
|
console.error("Payment error:", data);
|
|
2661
|
-
// Handle error appropriately
|
|
2662
2647
|
});
|
|
2663
2648
|
|
|
2664
|
-
button.onCancel((
|
|
2649
|
+
button.onCancel(() => {
|
|
2665
2650
|
console.log("Payment cancelled");
|
|
2666
|
-
// Handle cancellation
|
|
2667
2651
|
});
|
|
2668
2652
|
|
|
2669
|
-
button.onClick((
|
|
2653
|
+
button.onClick(() => {
|
|
2670
2654
|
console.log("Google Pay button clicked");
|
|
2671
|
-
// Perform pre-payment validation
|
|
2672
2655
|
});
|
|
2673
2656
|
|
|
2674
2657
|
button.load();
|
|
@@ -2699,9 +2682,9 @@ The GooglePayOpenWalletButton constructor accepts the following parameters:
|
|
|
2699
2682
|
};
|
|
2700
2683
|
}
|
|
2701
2684
|
|
|
2702
|
-
async function updateTotal(
|
|
2685
|
+
async function updateTotal(shippingOption) {
|
|
2703
2686
|
const baseAmount = 100;
|
|
2704
|
-
const shippingAmount =
|
|
2687
|
+
const shippingAmount = shippingOption.amount;
|
|
2705
2688
|
return {
|
|
2706
2689
|
newAmount: baseAmount + shippingAmount
|
|
2707
2690
|
};
|
|
@@ -2727,7 +2710,7 @@ Both `ApplePayOpenWalletButton` and `GooglePayOpenWalletButton` share the same e
|
|
|
2727
2710
|
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.
|
|
2728
2711
|
|
|
2729
2712
|
```javascript
|
|
2730
|
-
button.onUnavailable((data) => console.log("No wallet button available", data));
|
|
2713
|
+
button.onUnavailable(({ data }) => console.log("No wallet button available", data));
|
|
2731
2714
|
```
|
|
2732
2715
|
|
|
2733
2716
|
### Service type validation
|
|
@@ -2743,7 +2726,7 @@ let button = new paydock.GooglePayOpenWalletButton(
|
|
|
2743
2726
|
meta
|
|
2744
2727
|
);
|
|
2745
2728
|
|
|
2746
|
-
button.onError((data) => {
|
|
2729
|
+
button.onError(({ data }) => {
|
|
2747
2730
|
// Error: Service configuration type 'ApplePay' does not match expected wallet type 'google'.
|
|
2748
2731
|
console.error(data.error.message);
|
|
2749
2732
|
});
|
|
@@ -2753,31 +2736,26 @@ button.load();
|
|
|
2753
2736
|
|
|
2754
2737
|
### Performing actions when the wallet button is clicked
|
|
2755
2738
|
|
|
2756
|
-
You can perform validations or actions when the user clicks on the wallet button. The callback supports both synchronous and asynchronous operations using
|
|
2739
|
+
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.
|
|
2757
2740
|
|
|
2758
2741
|
```javascript
|
|
2759
|
-
// Synchronous
|
|
2760
|
-
button.onClick((
|
|
2742
|
+
// Synchronous — continue normally
|
|
2743
|
+
button.onClick(() => {
|
|
2761
2744
|
console.log("Perform actions on button click");
|
|
2762
|
-
// Perform validation logic
|
|
2763
|
-
// Optionally use attachResult to control flow
|
|
2764
|
-
data.attachResult(true); // Continue with payment
|
|
2765
|
-
// data.attachResult(false); // Halt payment
|
|
2766
2745
|
});
|
|
2767
2746
|
|
|
2768
|
-
//
|
|
2769
|
-
button.onClick((
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
);
|
|
2747
|
+
// Synchronous — return false to abort the payment flow
|
|
2748
|
+
button.onClick(() => {
|
|
2749
|
+
if (!isOrderValid()) return false;
|
|
2750
|
+
});
|
|
2751
|
+
|
|
2752
|
+
// Asynchronous — defer the wallet sheet until the promise resolves
|
|
2753
|
+
button.onClick(async () => {
|
|
2754
|
+
const response = await fetch('/api/validate-order');
|
|
2755
|
+
const result = await response.json();
|
|
2756
|
+
if (!result.valid) {
|
|
2757
|
+
throw new Error('Order validation failed');
|
|
2758
|
+
}
|
|
2781
2759
|
});
|
|
2782
2760
|
```
|
|
2783
2761
|
|
|
@@ -2786,13 +2764,12 @@ button.onClick((data) => {
|
|
|
2786
2764
|
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.
|
|
2787
2765
|
|
|
2788
2766
|
```javascript
|
|
2789
|
-
button.onSuccess((data) => {
|
|
2767
|
+
button.onSuccess(({ data }) => {
|
|
2790
2768
|
console.log("OTT created successfully:", data.token);
|
|
2791
2769
|
console.log("Amount:", data.amount);
|
|
2792
2770
|
console.log("Shipping:", data.shipping);
|
|
2793
2771
|
console.log("Billing:", data.billing);
|
|
2794
2772
|
|
|
2795
|
-
// Use the OTT token to complete payment on your backend
|
|
2796
2773
|
fetch('/api/process-payment', {
|
|
2797
2774
|
method: 'POST',
|
|
2798
2775
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -2820,11 +2797,10 @@ googlePayButton.setMeta({ ...meta, amount: 29.99, merchant_name: 'Updated Store'
|
|
|
2820
2797
|
Register a callback function to handle errors that occur during wallet operations, including service type mismatches.
|
|
2821
2798
|
|
|
2822
2799
|
```javascript
|
|
2823
|
-
button.onError((data) => {
|
|
2800
|
+
button.onError(({ data }) => {
|
|
2824
2801
|
console.error("Open Wallet error:", data.error);
|
|
2825
2802
|
console.log("Error context:", data.context);
|
|
2826
2803
|
|
|
2827
|
-
// Show user-friendly error message
|
|
2828
2804
|
showErrorMessage("Payment initialization failed. Please try again.");
|
|
2829
2805
|
});
|
|
2830
2806
|
```
|
|
@@ -2834,10 +2810,8 @@ button.onError((data) => {
|
|
|
2834
2810
|
When the user cancels or closes the wallet payment interface, you can perform cleanup operations.
|
|
2835
2811
|
|
|
2836
2812
|
```javascript
|
|
2837
|
-
button.onCancel((
|
|
2838
|
-
console.log("Wallet checkout cancelled"
|
|
2839
|
-
|
|
2840
|
-
// Perform cleanup or redirect user
|
|
2813
|
+
button.onCancel(() => {
|
|
2814
|
+
console.log("Wallet checkout cancelled");
|
|
2841
2815
|
window.location.href = '/checkout';
|
|
2842
2816
|
});
|
|
2843
2817
|
```
|
|
@@ -2854,22 +2828,24 @@ button.destroy();
|
|
|
2854
2828
|
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.
|
|
2855
2829
|
|
|
2856
2830
|
**Available Event Handler Methods:**
|
|
2857
|
-
- `onClick(handler)` - Button click events (
|
|
2831
|
+
- `onClick(handler)` - Button click events (return `false` to abort, `Promise` to defer)
|
|
2858
2832
|
- `onSuccess(handler)` - **Required** - OTT creation success events
|
|
2859
2833
|
- `onUnavailable(handler)` - Wallet unavailable events (supports Promise pattern)
|
|
2860
2834
|
- `onError(handler)` - Error events (supports Promise pattern)
|
|
2861
2835
|
- `onCancel(handler)` - Checkout cancellation events (supports Promise pattern)
|
|
2862
2836
|
- `onLoaded(handler)` - Button loaded/rendered events
|
|
2863
|
-
- `onShippingAddressChange(handler)` - **
|
|
2864
|
-
- `onShippingOptionsChange(handler)` - **
|
|
2837
|
+
- `onShippingAddressChange(handler)` - **Recommended for shipping** - Address change events (auto-accepted if not registered)
|
|
2838
|
+
- `onShippingOptionsChange(handler)` - **Recommended for shipping options** - Option change events (auto-accepted if not registered)
|
|
2865
2839
|
|
|
2866
2840
|
**Event Handler Patterns:**
|
|
2867
2841
|
|
|
2868
2842
|
```javascript
|
|
2869
|
-
// Required
|
|
2843
|
+
// Required handler
|
|
2870
2844
|
button.onSuccess(handler); // Always required
|
|
2871
|
-
|
|
2872
|
-
|
|
2845
|
+
|
|
2846
|
+
// Recommended when shipping is enabled (auto-accepted if not registered)
|
|
2847
|
+
button.onShippingAddressChange(handler);
|
|
2848
|
+
button.onShippingOptionsChange(handler);
|
|
2873
2849
|
|
|
2874
2850
|
// Optional handlers with Promise support
|
|
2875
2851
|
button.onUnavailable(handler); // or await button.onUnavailable()
|
|
@@ -2877,7 +2853,7 @@ button.onError(handler); // or await button.onError()
|
|
|
2877
2853
|
button.onCancel(handler); // or await button.onCancel()
|
|
2878
2854
|
|
|
2879
2855
|
// Click handler with flow control
|
|
2880
|
-
button.onClick(handler); //
|
|
2856
|
+
button.onClick(handler); // Return false to abort, or a Promise to defer
|
|
2881
2857
|
|
|
2882
2858
|
// Loaded handler
|
|
2883
2859
|
button.onLoaded(handler); // Notified when button renders
|
|
@@ -2965,20 +2941,14 @@ button.load();
|
|
|
2965
2941
|
|
|
2966
2942
|
### Error Handling Best Practices
|
|
2967
2943
|
```javascript
|
|
2968
|
-
button.onError(function(data) {
|
|
2944
|
+
button.onError(function({ data }) {
|
|
2969
2945
|
console.error('Full error object:', data);
|
|
2970
2946
|
|
|
2971
|
-
|
|
2972
|
-
const errorMessage = data.error?.message ||
|
|
2973
|
-
data.message ||
|
|
2974
|
-
'Unknown error occurred';
|
|
2947
|
+
const errorMessage = data.error?.message || 'Unknown error occurred';
|
|
2975
2948
|
|
|
2976
|
-
// Handle different error types
|
|
2977
2949
|
if (data.context?.operation === 'wallet_operation') {
|
|
2978
|
-
// Handle wallet-specific errors
|
|
2979
2950
|
showWalletError(errorMessage);
|
|
2980
2951
|
} else {
|
|
2981
|
-
// Handle general errors
|
|
2982
2952
|
showGeneralError(errorMessage);
|
|
2983
2953
|
}
|
|
2984
2954
|
});
|