@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/README.md
CHANGED
|
@@ -1977,6 +1977,7 @@ Class ZipmoneyCheckoutButton is wrapper of CheckoutButton transform usual button
|
|
|
1977
1977
|
* [new ZipmoneyCheckoutButton(selector, publicKey, [gatewayId], [gatewayId])](#user-content-cb_new_ZipmoneyCheckoutButton_new)
|
|
1978
1978
|
* [.setSuspendedRedirectUri(string)](#user-content-cb_ZipmoneyCheckoutButton+setSuspendedRedirectUri)
|
|
1979
1979
|
* [.setRedirectUrl(string)](#user-content-cb_ZipmoneyCheckoutButton+setRedirectUrl)
|
|
1980
|
+
* [.onClick(handler)](#user-content-cb_ZipmoneyCheckoutButton+onClick)
|
|
1980
1981
|
* [.on(eventName, cb)](#user-content-cb_CheckoutButton+on)
|
|
1981
1982
|
* [.close()](#user-content-cb_CheckoutButton+close)
|
|
1982
1983
|
* [.onFinishInsert(selector, dataType)](#user-content-cb_CheckoutButton+onFinishInsert)
|
|
@@ -2035,6 +2036,27 @@ The merchant's customer would be automatically redirected to this URL after the
|
|
|
2035
2036
|
| --- | --- | --- |
|
|
2036
2037
|
| string | <code>url</code> | URL for redirect |
|
|
2037
2038
|
|
|
2039
|
+
<a name="cb_ZipmoneyCheckoutButton+onClick" id="cb_ZipmoneyCheckoutButton+onClick" href="#user-content-cb_ZipmoneyCheckoutButton+onClick"> </a>
|
|
2040
|
+
|
|
2041
|
+
### zipmoneyCheckoutButton.onClick(handler)
|
|
2042
|
+
Subscribe to the click event with an async handler.
|
|
2043
|
+
The checkout flow will wait for the async handler to complete before proceeding.
|
|
2044
|
+
If the handler resolves to `false`, the checkout flow will be cancelled.
|
|
2045
|
+
|
|
2046
|
+
**Kind**: instance method of [<code>ZipmoneyCheckoutButton</code>](#user-content-cb_ZipmoneyCheckoutButton)
|
|
2047
|
+
|
|
2048
|
+
| Param | Description |
|
|
2049
|
+
| --- | --- |
|
|
2050
|
+
| handler | Async function to be called when the button is clicked |
|
|
2051
|
+
|
|
2052
|
+
**Example**
|
|
2053
|
+
|
|
2054
|
+
```javascript
|
|
2055
|
+
button.onClick(async () => {
|
|
2056
|
+
const isValid = await fetchDataFromServer();
|
|
2057
|
+
return isValid; // return false to stop checkout
|
|
2058
|
+
});
|
|
2059
|
+
```
|
|
2038
2060
|
<a name="cb_CheckoutButton+on" id="cb_CheckoutButton+on" href="#user-content-cb_CheckoutButton+on"> </a>
|
|
2039
2061
|
|
|
2040
2062
|
### zipmoneyCheckoutButton.on(eventName, cb)
|
|
@@ -5627,44 +5649,37 @@ button.setEnv('sandbox');
|
|
|
5627
5649
|
|
|
5628
5650
|
button.setEnv('sandbox');
|
|
5629
5651
|
|
|
5630
|
-
button.onUnavailable((data) => {
|
|
5652
|
+
button.onUnavailable(({ data }) => {
|
|
5631
5653
|
console.log("Apple Pay not available:", data);
|
|
5632
|
-
// Show alternative payment methods
|
|
5633
5654
|
});
|
|
5634
5655
|
|
|
5635
|
-
button.onClick((
|
|
5656
|
+
button.onClick(() => {
|
|
5636
5657
|
console.log("Apple Pay button clicked");
|
|
5637
|
-
// Perform pre-payment validation
|
|
5638
5658
|
});
|
|
5639
5659
|
|
|
5640
|
-
button.onSuccess((data) => {
|
|
5660
|
+
button.onSuccess(({ data }) => {
|
|
5641
5661
|
console.log("Payment successful:", data);
|
|
5642
|
-
// Process the OTT token on your backend
|
|
5643
5662
|
processPayment(data.token);
|
|
5644
5663
|
});
|
|
5645
5664
|
|
|
5646
|
-
button.onError((data) => {
|
|
5665
|
+
button.onError(({ data }) => {
|
|
5647
5666
|
console.error("Payment error:", data);
|
|
5648
|
-
// Handle error appropriately
|
|
5649
5667
|
});
|
|
5650
5668
|
|
|
5651
|
-
button.onCancel((
|
|
5669
|
+
button.onCancel(() => {
|
|
5652
5670
|
console.log("Payment cancelled");
|
|
5653
|
-
// Handle cancellation
|
|
5654
5671
|
});
|
|
5655
5672
|
|
|
5656
|
-
button.onShippingAddressChange(async (
|
|
5657
|
-
|
|
5658
|
-
const response = await updateShippingCosts(addressData);
|
|
5673
|
+
button.onShippingAddressChange(async ({ data }) => {
|
|
5674
|
+
const response = await updateShippingCosts(data);
|
|
5659
5675
|
return {
|
|
5660
5676
|
amount: response.newAmount,
|
|
5661
5677
|
shipping_options: response.shippingOptions
|
|
5662
5678
|
};
|
|
5663
5679
|
});
|
|
5664
5680
|
|
|
5665
|
-
button.onShippingOptionsChange(async (
|
|
5666
|
-
|
|
5667
|
-
const response = await updateTotal(optionData);
|
|
5681
|
+
button.onShippingOptionsChange(async ({ data }) => {
|
|
5682
|
+
const response = await updateTotal(data);
|
|
5668
5683
|
return {
|
|
5669
5684
|
amount: response.newAmount
|
|
5670
5685
|
};
|
|
@@ -5696,17 +5711,15 @@ button.setEnv('sandbox');
|
|
|
5696
5711
|
};
|
|
5697
5712
|
}
|
|
5698
5713
|
|
|
5699
|
-
async function updateTotal(
|
|
5700
|
-
// Your total calculation logic
|
|
5714
|
+
async function updateTotal(shippingOption) {
|
|
5701
5715
|
const baseAmount = 100;
|
|
5702
|
-
const shippingAmount =
|
|
5716
|
+
const shippingAmount = shippingOption.amount;
|
|
5703
5717
|
return {
|
|
5704
5718
|
newAmount: baseAmount + shippingAmount
|
|
5705
5719
|
};
|
|
5706
5720
|
}
|
|
5707
5721
|
|
|
5708
5722
|
function processPayment(ottToken) {
|
|
5709
|
-
// Send OTT token to your backend for payment processing
|
|
5710
5723
|
fetch('/api/process-payment', {
|
|
5711
5724
|
method: 'POST',
|
|
5712
5725
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -5759,21 +5772,19 @@ let button = new paydock.ApplePayOpenWalletButton(
|
|
|
5759
5772
|
button.load();
|
|
5760
5773
|
```
|
|
5761
5774
|
|
|
5762
|
-
When supporting shipping,
|
|
5775
|
+
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.
|
|
5763
5776
|
|
|
5764
5777
|
```javascript
|
|
5765
|
-
button.onShippingAddressChange(async function(data) {
|
|
5778
|
+
button.onShippingAddressChange(async function({ data }) {
|
|
5766
5779
|
console.log("Shipping address has been updated", data);
|
|
5767
|
-
// Call your backend to recalculate shipping
|
|
5768
5780
|
return {
|
|
5769
5781
|
amount: newAmount,
|
|
5770
5782
|
shipping_options: updatedShippingOptions
|
|
5771
5783
|
};
|
|
5772
5784
|
});
|
|
5773
5785
|
|
|
5774
|
-
button.onShippingOptionsChange(async function(data) {
|
|
5786
|
+
button.onShippingOptionsChange(async function({ data }) {
|
|
5775
5787
|
console.log("Shipping option selected", data);
|
|
5776
|
-
// Update total based on selected shipping option
|
|
5777
5788
|
return {
|
|
5778
5789
|
amount: newTotalAmount
|
|
5779
5790
|
};
|
|
@@ -6027,46 +6038,40 @@ The GooglePayOpenWalletButton constructor accepts the following parameters:
|
|
|
6027
6038
|
|
|
6028
6039
|
button.setEnv('sandbox');
|
|
6029
6040
|
|
|
6030
|
-
|
|
6031
|
-
button.onSuccess((data) => {
|
|
6041
|
+
button.onSuccess(({ data }) => {
|
|
6032
6042
|
console.log("Payment successful:", data);
|
|
6033
6043
|
processPayment(data.token);
|
|
6034
6044
|
});
|
|
6035
6045
|
|
|
6036
|
-
button.onShippingAddressChange(async (
|
|
6037
|
-
const response = await updateShippingCosts(
|
|
6046
|
+
button.onShippingAddressChange(async ({ data }) => {
|
|
6047
|
+
const response = await updateShippingCosts(data);
|
|
6038
6048
|
return {
|
|
6039
6049
|
amount: response.newAmount,
|
|
6040
6050
|
shipping_options: response.shippingOptions
|
|
6041
6051
|
};
|
|
6042
6052
|
});
|
|
6043
6053
|
|
|
6044
|
-
button.onShippingOptionsChange(async (
|
|
6045
|
-
const response = await updateTotal(
|
|
6054
|
+
button.onShippingOptionsChange(async ({ data }) => {
|
|
6055
|
+
const response = await updateTotal(data);
|
|
6046
6056
|
return {
|
|
6047
6057
|
amount: response.newAmount
|
|
6048
6058
|
};
|
|
6049
6059
|
});
|
|
6050
6060
|
|
|
6051
|
-
|
|
6052
|
-
button.onUnavailable((data) => {
|
|
6061
|
+
button.onUnavailable(({ data }) => {
|
|
6053
6062
|
console.log("Google Pay not available:", data);
|
|
6054
|
-
// Show alternative payment methods
|
|
6055
6063
|
});
|
|
6056
6064
|
|
|
6057
|
-
button.onError((data) => {
|
|
6065
|
+
button.onError(({ data }) => {
|
|
6058
6066
|
console.error("Payment error:", data);
|
|
6059
|
-
// Handle error appropriately
|
|
6060
6067
|
});
|
|
6061
6068
|
|
|
6062
|
-
button.onCancel((
|
|
6069
|
+
button.onCancel(() => {
|
|
6063
6070
|
console.log("Payment cancelled");
|
|
6064
|
-
// Handle cancellation
|
|
6065
6071
|
});
|
|
6066
6072
|
|
|
6067
|
-
button.onClick((
|
|
6073
|
+
button.onClick(() => {
|
|
6068
6074
|
console.log("Google Pay button clicked");
|
|
6069
|
-
// Perform pre-payment validation
|
|
6070
6075
|
});
|
|
6071
6076
|
|
|
6072
6077
|
button.load();
|
|
@@ -6097,9 +6102,9 @@ The GooglePayOpenWalletButton constructor accepts the following parameters:
|
|
|
6097
6102
|
};
|
|
6098
6103
|
}
|
|
6099
6104
|
|
|
6100
|
-
async function updateTotal(
|
|
6105
|
+
async function updateTotal(shippingOption) {
|
|
6101
6106
|
const baseAmount = 100;
|
|
6102
|
-
const shippingAmount =
|
|
6107
|
+
const shippingAmount = shippingOption.amount;
|
|
6103
6108
|
return {
|
|
6104
6109
|
newAmount: baseAmount + shippingAmount
|
|
6105
6110
|
};
|
|
@@ -6125,7 +6130,7 @@ Both `ApplePayOpenWalletButton` and `GooglePayOpenWalletButton` share the same e
|
|
|
6125
6130
|
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.
|
|
6126
6131
|
|
|
6127
6132
|
```javascript
|
|
6128
|
-
button.onUnavailable((data) => console.log("No wallet button available", data));
|
|
6133
|
+
button.onUnavailable(({ data }) => console.log("No wallet button available", data));
|
|
6129
6134
|
```
|
|
6130
6135
|
|
|
6131
6136
|
### Service type validation
|
|
@@ -6141,7 +6146,7 @@ let button = new paydock.GooglePayOpenWalletButton(
|
|
|
6141
6146
|
meta
|
|
6142
6147
|
);
|
|
6143
6148
|
|
|
6144
|
-
button.onError((data) => {
|
|
6149
|
+
button.onError(({ data }) => {
|
|
6145
6150
|
// Error: Service configuration type 'ApplePay' does not match expected wallet type 'google'.
|
|
6146
6151
|
console.error(data.error.message);
|
|
6147
6152
|
});
|
|
@@ -6151,31 +6156,26 @@ button.load();
|
|
|
6151
6156
|
|
|
6152
6157
|
### Performing actions when the wallet button is clicked
|
|
6153
6158
|
|
|
6154
|
-
You can perform validations or actions when the user clicks on the wallet button. The callback supports both synchronous and asynchronous operations using
|
|
6159
|
+
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.
|
|
6155
6160
|
|
|
6156
6161
|
```javascript
|
|
6157
|
-
// Synchronous
|
|
6158
|
-
button.onClick((
|
|
6162
|
+
// Synchronous — continue normally
|
|
6163
|
+
button.onClick(() => {
|
|
6159
6164
|
console.log("Perform actions on button click");
|
|
6160
|
-
// Perform validation logic
|
|
6161
|
-
// Optionally use attachResult to control flow
|
|
6162
|
-
data.attachResult(true); // Continue with payment
|
|
6163
|
-
// data.attachResult(false); // Halt payment
|
|
6164
6165
|
});
|
|
6165
6166
|
|
|
6166
|
-
//
|
|
6167
|
-
button.onClick((
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
);
|
|
6167
|
+
// Synchronous — return false to abort the payment flow
|
|
6168
|
+
button.onClick(() => {
|
|
6169
|
+
if (!isOrderValid()) return false;
|
|
6170
|
+
});
|
|
6171
|
+
|
|
6172
|
+
// Asynchronous — defer the wallet sheet until the promise resolves
|
|
6173
|
+
button.onClick(async () => {
|
|
6174
|
+
const response = await fetch('/api/validate-order');
|
|
6175
|
+
const result = await response.json();
|
|
6176
|
+
if (!result.valid) {
|
|
6177
|
+
throw new Error('Order validation failed');
|
|
6178
|
+
}
|
|
6179
6179
|
});
|
|
6180
6180
|
```
|
|
6181
6181
|
|
|
@@ -6184,13 +6184,12 @@ button.onClick((data) => {
|
|
|
6184
6184
|
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.
|
|
6185
6185
|
|
|
6186
6186
|
```javascript
|
|
6187
|
-
button.onSuccess((data) => {
|
|
6187
|
+
button.onSuccess(({ data }) => {
|
|
6188
6188
|
console.log("OTT created successfully:", data.token);
|
|
6189
6189
|
console.log("Amount:", data.amount);
|
|
6190
6190
|
console.log("Shipping:", data.shipping);
|
|
6191
6191
|
console.log("Billing:", data.billing);
|
|
6192
6192
|
|
|
6193
|
-
// Use the OTT token to complete payment on your backend
|
|
6194
6193
|
fetch('/api/process-payment', {
|
|
6195
6194
|
method: 'POST',
|
|
6196
6195
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -6218,11 +6217,10 @@ googlePayButton.setMeta({ ...meta, amount: 29.99, merchant_name: 'Updated Store'
|
|
|
6218
6217
|
Register a callback function to handle errors that occur during wallet operations, including service type mismatches.
|
|
6219
6218
|
|
|
6220
6219
|
```javascript
|
|
6221
|
-
button.onError((data) => {
|
|
6220
|
+
button.onError(({ data }) => {
|
|
6222
6221
|
console.error("Open Wallet error:", data.error);
|
|
6223
6222
|
console.log("Error context:", data.context);
|
|
6224
6223
|
|
|
6225
|
-
// Show user-friendly error message
|
|
6226
6224
|
showErrorMessage("Payment initialization failed. Please try again.");
|
|
6227
6225
|
});
|
|
6228
6226
|
```
|
|
@@ -6232,10 +6230,8 @@ button.onError((data) => {
|
|
|
6232
6230
|
When the user cancels or closes the wallet payment interface, you can perform cleanup operations.
|
|
6233
6231
|
|
|
6234
6232
|
```javascript
|
|
6235
|
-
button.onCancel((
|
|
6236
|
-
console.log("Wallet checkout cancelled"
|
|
6237
|
-
|
|
6238
|
-
// Perform cleanup or redirect user
|
|
6233
|
+
button.onCancel(() => {
|
|
6234
|
+
console.log("Wallet checkout cancelled");
|
|
6239
6235
|
window.location.href = '/checkout';
|
|
6240
6236
|
});
|
|
6241
6237
|
```
|
|
@@ -6252,22 +6248,24 @@ button.destroy();
|
|
|
6252
6248
|
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.
|
|
6253
6249
|
|
|
6254
6250
|
**Available Event Handler Methods:**
|
|
6255
|
-
- `onClick(handler)` - Button click events (
|
|
6251
|
+
- `onClick(handler)` - Button click events (return `false` to abort, `Promise` to defer)
|
|
6256
6252
|
- `onSuccess(handler)` - **Required** - OTT creation success events
|
|
6257
6253
|
- `onUnavailable(handler)` - Wallet unavailable events (supports Promise pattern)
|
|
6258
6254
|
- `onError(handler)` - Error events (supports Promise pattern)
|
|
6259
6255
|
- `onCancel(handler)` - Checkout cancellation events (supports Promise pattern)
|
|
6260
6256
|
- `onLoaded(handler)` - Button loaded/rendered events
|
|
6261
|
-
- `onShippingAddressChange(handler)` - **
|
|
6262
|
-
- `onShippingOptionsChange(handler)` - **
|
|
6257
|
+
- `onShippingAddressChange(handler)` - **Recommended for shipping** - Address change events (auto-accepted if not registered)
|
|
6258
|
+
- `onShippingOptionsChange(handler)` - **Recommended for shipping options** - Option change events (auto-accepted if not registered)
|
|
6263
6259
|
|
|
6264
6260
|
**Event Handler Patterns:**
|
|
6265
6261
|
|
|
6266
6262
|
```javascript
|
|
6267
|
-
// Required
|
|
6263
|
+
// Required handler
|
|
6268
6264
|
button.onSuccess(handler); // Always required
|
|
6269
|
-
|
|
6270
|
-
|
|
6265
|
+
|
|
6266
|
+
// Recommended when shipping is enabled (auto-accepted if not registered)
|
|
6267
|
+
button.onShippingAddressChange(handler);
|
|
6268
|
+
button.onShippingOptionsChange(handler);
|
|
6271
6269
|
|
|
6272
6270
|
// Optional handlers with Promise support
|
|
6273
6271
|
button.onUnavailable(handler); // or await button.onUnavailable()
|
|
@@ -6275,7 +6273,7 @@ button.onError(handler); // or await button.onError()
|
|
|
6275
6273
|
button.onCancel(handler); // or await button.onCancel()
|
|
6276
6274
|
|
|
6277
6275
|
// Click handler with flow control
|
|
6278
|
-
button.onClick(handler); //
|
|
6276
|
+
button.onClick(handler); // Return false to abort, or a Promise to defer
|
|
6279
6277
|
|
|
6280
6278
|
// Loaded handler
|
|
6281
6279
|
button.onLoaded(handler); // Notified when button renders
|
|
@@ -6363,20 +6361,14 @@ button.load();
|
|
|
6363
6361
|
|
|
6364
6362
|
### Error Handling Best Practices
|
|
6365
6363
|
```javascript
|
|
6366
|
-
button.onError(function(data) {
|
|
6364
|
+
button.onError(function({ data }) {
|
|
6367
6365
|
console.error('Full error object:', data);
|
|
6368
6366
|
|
|
6369
|
-
|
|
6370
|
-
const errorMessage = data.error?.message ||
|
|
6371
|
-
data.message ||
|
|
6372
|
-
'Unknown error occurred';
|
|
6367
|
+
const errorMessage = data.error?.message || 'Unknown error occurred';
|
|
6373
6368
|
|
|
6374
|
-
// Handle different error types
|
|
6375
6369
|
if (data.context?.operation === 'wallet_operation') {
|
|
6376
|
-
// Handle wallet-specific errors
|
|
6377
6370
|
showWalletError(errorMessage);
|
|
6378
6371
|
} else {
|
|
6379
|
-
// Handle general errors
|
|
6380
6372
|
showGeneralError(errorMessage);
|
|
6381
6373
|
}
|
|
6382
6374
|
});
|