@paydock/client-sdk 1.139.0 → 1.140.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.
Files changed (73) hide show
  1. package/README.md +2573 -0
  2. package/bundles/index.cjs +1296 -508
  3. package/bundles/index.cjs.d.ts +1377 -200
  4. package/bundles/index.mjs +1295 -509
  5. package/bundles/index.mjs.d.ts +1377 -200
  6. package/bundles/types/checkout/checkout.d.ts.map +1 -1
  7. package/bundles/types/checkout/v1/instructions/instruction.card_form.show.d.ts.map +1 -1
  8. package/bundles/types/checkout/v3/instructions/instruction.card_form.show.d.ts.map +1 -1
  9. package/bundles/types/checkout/v3/instructions/instruction.payment_methods.show.d.ts.map +1 -1
  10. package/bundles/types/checkout-button/zipmoney/zipmoney-contextual.runner.d.ts +1 -2
  11. package/bundles/types/checkout-button/zipmoney/zipmoney-contextual.runner.d.ts.map +1 -1
  12. package/bundles/types/open-wallets/apple-pay-open-wallet-button.d.ts +70 -0
  13. package/bundles/types/open-wallets/apple-pay-open-wallet-button.d.ts.map +1 -0
  14. package/bundles/types/open-wallets/base/open-wallet-buttons.d.ts +242 -74
  15. package/bundles/types/open-wallets/base/open-wallet-buttons.d.ts.map +1 -1
  16. package/bundles/types/open-wallets/base/open-wallet.service.d.ts +62 -4
  17. package/bundles/types/open-wallets/base/open-wallet.service.d.ts.map +1 -1
  18. package/bundles/types/open-wallets/enum/error-operation.enum.d.ts +15 -0
  19. package/bundles/types/open-wallets/enum/error-operation.enum.d.ts.map +1 -0
  20. package/bundles/types/open-wallets/enum/event.enum.d.ts +11 -3
  21. package/bundles/types/open-wallets/enum/event.enum.d.ts.map +1 -1
  22. package/bundles/types/open-wallets/enum/token-type.enum.d.ts +10 -0
  23. package/bundles/types/open-wallets/enum/token-type.enum.d.ts.map +1 -0
  24. package/bundles/types/open-wallets/google-pay-open-wallet-button.d.ts +65 -0
  25. package/bundles/types/open-wallets/google-pay-open-wallet-button.d.ts.map +1 -0
  26. package/bundles/types/open-wallets/index.d.ts +293 -0
  27. package/bundles/types/open-wallets/index.d.ts.map +1 -1
  28. package/bundles/types/open-wallets/interfaces/events.interface.d.ts +87 -14
  29. package/bundles/types/open-wallets/interfaces/events.interface.d.ts.map +1 -1
  30. package/bundles/types/open-wallets/interfaces/google-pay/google-pay-meta.interface.d.ts +6 -0
  31. package/bundles/types/open-wallets/interfaces/google-pay/google-pay-meta.interface.d.ts.map +1 -1
  32. package/bundles/types/open-wallets/interfaces/index.d.ts +2 -2
  33. package/bundles/types/open-wallets/interfaces/index.d.ts.map +1 -1
  34. package/bundles/types/open-wallets/interfaces/open-wallet-meta.interface.d.ts +12 -0
  35. package/bundles/types/open-wallets/interfaces/open-wallet-meta.interface.d.ts.map +1 -1
  36. package/bundles/types/open-wallets/interfaces/payment-source.interface.d.ts +28 -2
  37. package/bundles/types/open-wallets/interfaces/payment-source.interface.d.ts.map +1 -1
  38. package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts +27 -2
  39. package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts.map +1 -1
  40. package/bundles/types/open-wallets/services/google-pay/constants/google-pay.constants.d.ts +9 -0
  41. package/bundles/types/open-wallets/services/google-pay/constants/google-pay.constants.d.ts.map +1 -1
  42. package/bundles/types/open-wallets/services/google-pay/google-pay.open-wallet.service.d.ts +20 -9
  43. package/bundles/types/open-wallets/services/google-pay/google-pay.open-wallet.service.d.ts.map +1 -1
  44. package/bundles/types/open-wallets/services/google-pay/utils/google-pay.utils.d.ts +45 -0
  45. package/bundles/types/open-wallets/services/google-pay/utils/google-pay.utils.d.ts.map +1 -1
  46. package/bundles/types/open-wallets/services/google-pay/utils/index.d.ts +1 -1
  47. package/bundles/types/open-wallets/services/google-pay/utils/index.d.ts.map +1 -1
  48. package/bundles/types/open-wallets/services/google-pay/validation/google-pay.validation.d.ts +13 -0
  49. package/bundles/types/open-wallets/services/google-pay/validation/google-pay.validation.d.ts.map +1 -1
  50. package/bundles/types/open-wallets/types/base-event-data.interface.d.ts +24 -2
  51. package/bundles/types/open-wallets/types/base-event-data.interface.d.ts.map +1 -1
  52. package/bundles/types/open-wallets/types/index.d.ts +2 -1
  53. package/bundles/types/open-wallets/types/index.d.ts.map +1 -1
  54. package/bundles/types/open-wallets/types/on-shipping-address-change-event-data.interface.d.ts +16 -2
  55. package/bundles/types/open-wallets/types/on-shipping-address-change-event-data.interface.d.ts.map +1 -1
  56. package/bundles/types/open-wallets/types/on-shipping-address-change-event-response.interface.d.ts +20 -2
  57. package/bundles/types/open-wallets/types/on-shipping-address-change-event-response.interface.d.ts.map +1 -1
  58. package/bundles/types/open-wallets/types/on-shipping-option-change-event-data.interface.d.ts +13 -2
  59. package/bundles/types/open-wallets/types/on-shipping-option-change-event-data.interface.d.ts.map +1 -1
  60. package/bundles/types/open-wallets/types/on-shipping-option-change-event-response.interface.d.ts +12 -0
  61. package/bundles/types/open-wallets/types/on-shipping-option-change-event-response.interface.d.ts.map +1 -1
  62. package/bundles/types/open-wallets/types/payment-source.type.d.ts +3 -2
  63. package/bundles/types/open-wallets/types/payment-source.type.d.ts.map +1 -1
  64. package/bundles/types/open-wallets/types/shipping-event-to-response.type.d.ts +8 -0
  65. package/bundles/types/open-wallets/types/shipping-event-to-response.type.d.ts.map +1 -1
  66. package/bundles/widget.umd.js +1296 -508
  67. package/bundles/widget.umd.js.d.ts +1377 -200
  68. package/bundles/widget.umd.js.min.d.ts +1377 -200
  69. package/bundles/widget.umd.min.js +1 -1
  70. package/docs/open-wallet-buttons-examples.md +561 -830
  71. package/docs/open-wallet-buttons.md +1652 -0
  72. package/package.json +1 -1
  73. package/slate.md +1673 -0
package/README.md CHANGED
@@ -5462,6 +5462,2579 @@ Callback for onError method.
5462
5462
  | data | [<code>OnErrorEventData</code>](#OnErrorEventData) |
5463
5463
 
5464
5464
 
5465
+ ## Open Wallet Buttons
5466
+ You can find description of all methods and parameters [here](https://www.npmjs.com/package/@paydock/client-sdk#open-wallet-buttons-simple-example)
5467
+
5468
+ Open Wallet Buttons provide a next-generation approach to integrating E-Wallets into your checkout with improved event handling and more granular control over wallet interactions.
5469
+
5470
+ Each wallet type has its own dedicated class with fully typed metadata:
5471
+ - [ApplePayOpenWalletButton](#ApplePayOpenWalletButton) - for Apple Pay integration
5472
+ - [GooglePayOpenWalletButton](#GooglePayOpenWalletButton) - for Google Pay integration
5473
+
5474
+ On `load()`, each button fetches the service configuration from PayDock and validates that the service type matches the expected wallet. If there is a mismatch (e.g. using an Apple Pay service ID with `GooglePayOpenWalletButton`), an error will be raised via the `onError` callback.
5475
+
5476
+ If available in your client environment, you will display a simple button that upon clicking it the user will follow the standard flow for the appropriate Wallet. If not available an event will be raised and no button will be displayed.
5477
+
5478
+ ## Apple Pay Open Wallet Button
5479
+
5480
+ ### Container
5481
+
5482
+ ```html
5483
+ <div id="widget"></div>
5484
+ ```
5485
+
5486
+ You must create a container for the Open Wallet Button. Inside this tag, the button will be initialized.
5487
+
5488
+ Before initializing the button, you must configure your Apple Pay wallet service through the PayDock dashboard and obtain the service ID that will be used to load the button configuration.
5489
+
5490
+ ### Initialization
5491
+
5492
+ ```javascript
5493
+ let button = new paydock.ApplePayOpenWalletButton(
5494
+ "#widget",
5495
+ publicKeyOrAccessToken,
5496
+ serviceId,
5497
+ {
5498
+ amount: 100,
5499
+ currency: "AUD",
5500
+ country: "AU",
5501
+ amount_label: "TOTAL",
5502
+ store_name: "My Store",
5503
+ apple_pay_capabilities: ['credentials_available', 'credentials_status_unknown', 'credentials_unavailable'],
5504
+ }
5505
+ );
5506
+ button.load();
5507
+ ```
5508
+
5509
+ ```javascript
5510
+ // ES2015 | TypeScript
5511
+ import { ApplePayOpenWalletButton } from '@paydock/client-sdk';
5512
+
5513
+ var button = new ApplePayOpenWalletButton(
5514
+ '#widget',
5515
+ publicKeyOrAccessToken,
5516
+ serviceId,
5517
+ {
5518
+ amount: 100,
5519
+ currency: 'AUD',
5520
+ country: 'AU',
5521
+ amount_label: 'TOTAL',
5522
+ store_name: 'My Store',
5523
+ }
5524
+ );
5525
+ button.load();
5526
+ ```
5527
+
5528
+ ### Constructor Parameters
5529
+
5530
+ The ApplePayOpenWalletButton constructor accepts the following parameters:
5531
+
5532
+ 1. **selector** (string): CSS selector for the container element
5533
+ 2. **publicKeyOrAccessToken** (string): Your PayDock public key or access token
5534
+ 3. **serviceId** (string): The Apple Pay service ID configured in PayDock dashboard
5535
+ 4. **meta** (ApplePayOpenWalletMeta): Apple Pay-specific configuration object
5536
+
5537
+ > **Note:** Required meta fields (`amount`, `currency`, `country`, `amount_label`, `store_name`) are validated automatically by the `ApplePayOpenWalletButton` class. You do not need to specify them manually.
5538
+
5539
+ ### Setting environment
5540
+
5541
+ Current method can change environment. By default environment = sandbox.
5542
+ Bear in mind that you must set an environment before calling `button.load()`.
5543
+
5544
+ ```javascript
5545
+ button.setEnv('sandbox');
5546
+ ```
5547
+
5548
+ ### Full Apple Pay example
5549
+
5550
+ ```html
5551
+ <!DOCTYPE html>
5552
+ <html lang="en">
5553
+ <head>
5554
+ <meta charset="UTF-8">
5555
+ <title>Apple Pay with Open Wallets</title>
5556
+ </head>
5557
+ <body>
5558
+ <h2>Payment using PayDock Apple Pay Open Wallet Button!</h2>
5559
+ <div id="widget"></div>
5560
+ </body>
5561
+ <script src="https://widget.paydock.com/sdk/latest/widget.umd.min.js" ></script>
5562
+ <script>
5563
+ let button = new paydock.ApplePayOpenWalletButton(
5564
+ "#widget",
5565
+ publicKeyOrAccessToken,
5566
+ serviceId,
5567
+ {
5568
+ amount: 100,
5569
+ currency: "AUD",
5570
+ country: "AU",
5571
+ amount_label: "TOTAL",
5572
+ store_name: "My Store",
5573
+ request_shipping: true,
5574
+ request_payer_name: true,
5575
+ request_payer_email: true,
5576
+ request_payer_phone: true,
5577
+ show_billing_address: true,
5578
+ style: {
5579
+ button_type: 'buy',
5580
+ button_style: 'black'
5581
+ },
5582
+ shipping_options: [
5583
+ {
5584
+ id: "standard",
5585
+ label: "Standard Shipping",
5586
+ detail: "Arrives in 5 to 7 days",
5587
+ amount: 5.00,
5588
+ date_components_range: {
5589
+ start_date_components: {
5590
+ years: 0,
5591
+ months: 0,
5592
+ days: 5,
5593
+ hours: 0,
5594
+ },
5595
+ end_date_components: {
5596
+ years: 0,
5597
+ months: 0,
5598
+ days: 7,
5599
+ hours: 0,
5600
+ }
5601
+ }
5602
+ },
5603
+ {
5604
+ id: "express",
5605
+ label: "Express Shipping",
5606
+ detail: "Arrives in 1 to 2 days",
5607
+ amount: 15.00,
5608
+ date_components_range: {
5609
+ start_date_components: {
5610
+ years: 0,
5611
+ months: 0,
5612
+ days: 1,
5613
+ hours: 0,
5614
+ },
5615
+ end_date_components: {
5616
+ years: 0,
5617
+ months: 0,
5618
+ days: 2,
5619
+ hours: 0,
5620
+ }
5621
+ }
5622
+ }
5623
+ ],
5624
+ apple_pay_capabilities: ['credentials_available', 'credentials_status_unknown', 'credentials_unavailable']
5625
+ }
5626
+ );
5627
+
5628
+ button.setEnv('sandbox');
5629
+
5630
+ button.onUnavailable((data) => {
5631
+ console.log("Apple Pay not available:", data);
5632
+ // Show alternative payment methods
5633
+ });
5634
+
5635
+ button.onClick((data) => {
5636
+ console.log("Apple Pay button clicked");
5637
+ // Perform pre-payment validation
5638
+ });
5639
+
5640
+ button.onSuccess((data) => {
5641
+ console.log("Payment successful:", data);
5642
+ // Process the OTT token on your backend
5643
+ processPayment(data.token);
5644
+ });
5645
+
5646
+ button.onError((data) => {
5647
+ console.error("Payment error:", data);
5648
+ // Handle error appropriately
5649
+ });
5650
+
5651
+ button.onCancel((data) => {
5652
+ console.log("Payment cancelled");
5653
+ // Handle cancellation
5654
+ });
5655
+
5656
+ button.onShippingAddressChange(async (addressData) => {
5657
+ // Update shipping costs based on address
5658
+ const response = await updateShippingCosts(addressData);
5659
+ return {
5660
+ amount: response.newAmount,
5661
+ shipping_options: response.shippingOptions
5662
+ };
5663
+ });
5664
+
5665
+ button.onShippingOptionsChange(async (optionData) => {
5666
+ // Update total based on selected shipping option
5667
+ const response = await updateTotal(optionData);
5668
+ return {
5669
+ amount: response.newAmount
5670
+ };
5671
+ });
5672
+
5673
+ button.load();
5674
+
5675
+ async function updateShippingCosts(addressData) {
5676
+ // Your shipping calculation logic based on address
5677
+ const baseAmount = 100;
5678
+ const updatedShippingOptions = [
5679
+ {
5680
+ id: "updated-standard",
5681
+ label: "Updated Standard Shipping",
5682
+ detail: "Based on your location",
5683
+ amount: 8.00
5684
+ },
5685
+ {
5686
+ id: "updated-express",
5687
+ label: "Updated Express Shipping",
5688
+ detail: "Fast delivery to your area",
5689
+ amount: 18.00
5690
+ }
5691
+ ];
5692
+
5693
+ return {
5694
+ newAmount: baseAmount + updatedShippingOptions[0].amount,
5695
+ shippingOptions: updatedShippingOptions
5696
+ };
5697
+ }
5698
+
5699
+ async function updateTotal(optionData) {
5700
+ // Your total calculation logic
5701
+ const baseAmount = 100;
5702
+ const shippingAmount = optionData.amount || optionData.data?.amount;
5703
+ return {
5704
+ newAmount: baseAmount + shippingAmount
5705
+ };
5706
+ }
5707
+
5708
+ function processPayment(ottToken) {
5709
+ // Send OTT token to your backend for payment processing
5710
+ fetch('/api/process-payment', {
5711
+ method: 'POST',
5712
+ headers: { 'Content-Type': 'application/json' },
5713
+ body: JSON.stringify({ ott_token: ottToken })
5714
+ });
5715
+ }
5716
+ </script>
5717
+ </html>
5718
+ ```
5719
+
5720
+ ### Apple Pay with Shipping
5721
+
5722
+ For Apple Pay with shipping enabled:
5723
+ ```javascript
5724
+ let button = new paydock.ApplePayOpenWalletButton(
5725
+ "#widget",
5726
+ publicKeyOrAccessToken,
5727
+ serviceId,
5728
+ {
5729
+ amount: 100,
5730
+ currency: "AUD",
5731
+ country: "AU",
5732
+ amount_label: "TOTAL",
5733
+ store_name: "My Store",
5734
+ request_shipping: true,
5735
+ shipping_editing_mode: 'available',
5736
+ required_shipping_contact_fields: [
5737
+ 'postalAddress',
5738
+ 'name',
5739
+ 'phone',
5740
+ 'email',
5741
+ ],
5742
+ shipping_options: [
5743
+ {
5744
+ id: "standard",
5745
+ label: "Standard Shipping",
5746
+ detail: "5-7 business days",
5747
+ amount: 5.00
5748
+ },
5749
+ {
5750
+ id: "express",
5751
+ label: "Express Shipping",
5752
+ detail: "1-2 business days",
5753
+ amount: 15.00
5754
+ }
5755
+ ],
5756
+ apple_pay_capabilities: ['credentials_available', 'credentials_status_unknown', 'credentials_unavailable']
5757
+ }
5758
+ );
5759
+ button.load();
5760
+ ```
5761
+
5762
+ When supporting shipping, the methods `onShippingAddressChange` and `onShippingOptionsChange` are required to update the shipping address and options.
5763
+
5764
+ ```javascript
5765
+ button.onShippingAddressChange(async function(data) {
5766
+ console.log("Shipping address has been updated", data);
5767
+ // Call your backend to recalculate shipping
5768
+ return {
5769
+ amount: newAmount,
5770
+ shipping_options: updatedShippingOptions
5771
+ };
5772
+ });
5773
+
5774
+ button.onShippingOptionsChange(async function(data) {
5775
+ console.log("Shipping option selected", data);
5776
+ // Update total based on selected shipping option
5777
+ return {
5778
+ amount: newTotalAmount
5779
+ };
5780
+ });
5781
+ ```
5782
+
5783
+ ### Supported Shipping Cases
5784
+
5785
+ #### Injected Shipping Address, non-editable by the customer
5786
+
5787
+ This is the case where the shipping address is injected by the merchant and is not editable by the customer. The customer can only select the shipping option.
5788
+
5789
+ The required meta parameters for this case are:
5790
+ - shipping_editing_mode: 'store_pickup'
5791
+ - required_shipping_contact_fields: ['postalAddress'] <-- At least one of the fields is required so the shipping address is shown at Apple Pay.
5792
+
5793
+ ```javascript
5794
+ meta: {
5795
+ apple_pay_capabilities: ['credentials_available', 'credentials_status_unknown', 'credentials_unavailable'],
5796
+ amount_label: 'TOTAL',
5797
+ country: 'AU',
5798
+ currency: 'AUD',
5799
+ amount: 10,
5800
+ shipping_editing_mode: 'store_pickup',
5801
+ required_shipping_contact_fields: [
5802
+ 'postalAddress',
5803
+ 'name',
5804
+ 'phone',
5805
+ 'email',
5806
+ ],
5807
+ shipping: {
5808
+ amount: 5,
5809
+ address_line1: "Address Line 1",
5810
+ address_city: "Test Locality",
5811
+ address_state: "NSW",
5812
+ address_country: "Australia",
5813
+ address_country_code: "AU",
5814
+ address_postcode: "3000",
5815
+ contact: {
5816
+ phone: "+61400245562",
5817
+ email: "test@example.com",
5818
+ first_name: "QA",
5819
+ last_name: "QA",
5820
+ },
5821
+ options: [
5822
+ {
5823
+ label: "Test 1",
5824
+ detail: "This is a test 1 shipping methods",
5825
+ amount: 10,
5826
+ id: "randomId1",
5827
+ }
5828
+ ],
5829
+ },
5830
+ }
5831
+ ```
5832
+
5833
+ #### Injected Shipping Address, editable by the customer
5834
+
5835
+ This is the case where the shipping address is injected by the merchant and is editable by the customer. The customer can edit the shipping address and select the shipping option.
5836
+
5837
+ The required meta parameters for this case are:
5838
+ - shipping_editing_mode: 'available'
5839
+ - required_shipping_contact_fields: ['postalAddress'] <-- At least one of the fields is required so the shipping address is shown at Apple Pay.
5840
+
5841
+ ```javascript
5842
+ meta: {
5843
+ apple_pay_capabilities: ['credentials_available', 'credentials_status_unknown', 'credentials_unavailable'],
5844
+ amount_label: 'TOTAL',
5845
+ country: 'AU',
5846
+ currency: 'AUD',
5847
+ amount: 10,
5848
+ shipping_editing_mode: 'available',
5849
+ required_shipping_contact_fields: [
5850
+ 'postalAddress',
5851
+ 'name',
5852
+ 'phone',
5853
+ 'email',
5854
+ ],
5855
+ shipping: {
5856
+ amount: 5,
5857
+ address_line1: "Address Line 1",
5858
+ address_city: "Test Locality",
5859
+ address_state: "NSW",
5860
+ address_country: "Australia",
5861
+ address_country_code: "AU",
5862
+ address_postcode: "3000",
5863
+ contact: {
5864
+ phone: "+61400245562",
5865
+ email: "test@example.com",
5866
+ first_name: "QA",
5867
+ last_name: "QA",
5868
+ },
5869
+ options: [
5870
+ {
5871
+ label: "Test 1",
5872
+ detail: "This is a test 1 shipping methods",
5873
+ amount: 10,
5874
+ id: "randomId1",
5875
+ }
5876
+ ],
5877
+ },
5878
+ }
5879
+ ```
5880
+
5881
+ #### Shipping address editable by the customer (no pre-filled address)
5882
+
5883
+ This is the case where the shipping address is not injected by the merchant and is editable by the customer. The customer can edit the shipping address and select the shipping option.
5884
+
5885
+ The required meta parameters for this case are:
5886
+ - shipping_editing_mode: 'available'
5887
+ - required_shipping_contact_fields: ['postalAddress'] <-- At least one of the fields is required so the shipping address is shown at Apple Pay.
5888
+
5889
+ ```javascript
5890
+ meta: {
5891
+ apple_pay_capabilities: ['credentials_available', 'credentials_status_unknown', 'credentials_unavailable'],
5892
+ amount_label: 'TOTAL',
5893
+ country: 'AU',
5894
+ currency: 'AUD',
5895
+ amount: 10,
5896
+ shipping_editing_mode: 'available',
5897
+ required_shipping_contact_fields: [
5898
+ 'postalAddress',
5899
+ 'name',
5900
+ 'phone',
5901
+ 'email',
5902
+ ],
5903
+ }
5904
+ ```
5905
+
5906
+ #### No shipping address
5907
+
5908
+ This is the case where no shipping address is required at all in the popup (e.g., digital goods, services, or virtual products, or Shipping Address collected separately by the merchant). The "Send to" UI field will not be shown in the Apple Pay sheet, it will be hidden.
5909
+
5910
+ **Important:**
5911
+ - No shipping address should be provided in the meta object.
5912
+ - Shipping address could be provided in the initial POST `/v1/charges/wallet` endpoint, if collected previously.
5913
+
5914
+ The required meta parameters for this case are:
5915
+ - `required_shipping_contact_fields`: Only include contact fields if needed (phone, email), but NOT `postalAddress`.
5916
+
5917
+ ```javascript
5918
+ meta: {
5919
+ amount_label: "TOTAL",
5920
+ country: "AU",
5921
+ currency: "AUD",
5922
+ amount: 10,
5923
+ shipping_editing_mode: "available",
5924
+ required_shipping_contact_fields: ["phone", "email"],
5925
+ apple_pay_capabilities: ["credentials_available", "credentials_status_unknown", "credentials_unavailable"]
5926
+ }
5927
+ ```
5928
+
5929
+ ## Google Pay Open Wallet Button
5930
+
5931
+ ### Initialization
5932
+
5933
+ ```javascript
5934
+ let button = new paydock.GooglePayOpenWalletButton(
5935
+ "#widget",
5936
+ publicKeyOrAccessToken,
5937
+ serviceId,
5938
+ {
5939
+ amount: 100,
5940
+ currency: "AUD",
5941
+ country: "AU",
5942
+ merchant_name: "Your Store",
5943
+ }
5944
+ );
5945
+ button.load();
5946
+ ```
5947
+
5948
+ ```javascript
5949
+ // ES2015 | TypeScript
5950
+ import { GooglePayOpenWalletButton } from '@paydock/client-sdk';
5951
+
5952
+ var button = new GooglePayOpenWalletButton(
5953
+ '#widget',
5954
+ publicKeyOrAccessToken,
5955
+ serviceId,
5956
+ {
5957
+ amount: 100,
5958
+ currency: 'AUD',
5959
+ country: 'AU',
5960
+ merchant_name: 'Your Store',
5961
+ }
5962
+ );
5963
+ button.load();
5964
+ ```
5965
+
5966
+ ### Constructor Parameters
5967
+
5968
+ The GooglePayOpenWalletButton constructor accepts the following parameters:
5969
+
5970
+ 1. **selector** (string): CSS selector for the container element
5971
+ 2. **publicKeyOrAccessToken** (string): Your PayDock public key or access token
5972
+ 3. **serviceId** (string): The Google Pay service ID configured in PayDock dashboard
5973
+ 4. **meta** (GooglePayOpenWalletMeta): Google Pay-specific configuration object
5974
+
5975
+ > **Note:** Required meta fields (`amount`, `currency`, `country`) are validated automatically by the `GooglePayOpenWalletButton` class. You do not need to specify them manually.
5976
+
5977
+ ### Full Google Pay Example
5978
+
5979
+ ```html
5980
+ <!DOCTYPE html>
5981
+ <html lang="en">
5982
+ <head>
5983
+ <meta charset="UTF-8">
5984
+ <title>Google Pay with Open Wallets</title>
5985
+ </head>
5986
+ <body>
5987
+ <h2>Payment using PayDock Google Pay Open Wallet Button!</h2>
5988
+ <div id="widget"></div>
5989
+ </body>
5990
+ <script src="https://widget.paydock.com/sdk/latest/widget.umd.min.js" ></script>
5991
+ <script>
5992
+ let button = new paydock.GooglePayOpenWalletButton(
5993
+ "#widget",
5994
+ publicKeyOrAccessToken,
5995
+ serviceId,
5996
+ {
5997
+ amount: 100,
5998
+ currency: "AUD",
5999
+ country: "AU",
6000
+ amount_label: "Total",
6001
+ request_shipping: true,
6002
+ show_billing_address: true,
6003
+ merchant_name: 'Test Merchant',
6004
+ style: {
6005
+ button_type: 'buy',
6006
+ button_color: 'default',
6007
+ button_size_mode: 'fill'
6008
+ },
6009
+ shipping_options: [
6010
+ {
6011
+ id: "standard",
6012
+ label: "Standard Shipping",
6013
+ detail: "Arrives in 5 to 7 days",
6014
+ amount: 5.00,
6015
+ type: "ELECTRONIC"
6016
+ },
6017
+ {
6018
+ id: "express",
6019
+ label: "Express Shipping",
6020
+ detail: "Arrives in 1 to 2 days",
6021
+ amount: 15.00,
6022
+ type: "PICKUP"
6023
+ }
6024
+ ]
6025
+ }
6026
+ );
6027
+
6028
+ button.setEnv('sandbox');
6029
+
6030
+ // Required handlers
6031
+ button.onSuccess((data) => {
6032
+ console.log("Payment successful:", data);
6033
+ processPayment(data.token);
6034
+ });
6035
+
6036
+ button.onShippingAddressChange(async (addressData) => {
6037
+ const response = await updateShippingCosts(addressData);
6038
+ return {
6039
+ amount: response.newAmount,
6040
+ shipping_options: response.shippingOptions
6041
+ };
6042
+ });
6043
+
6044
+ button.onShippingOptionsChange(async (optionData) => {
6045
+ const response = await updateTotal(optionData);
6046
+ return {
6047
+ amount: response.newAmount
6048
+ };
6049
+ });
6050
+
6051
+ // Optional handlers
6052
+ button.onUnavailable((data) => {
6053
+ console.log("Google Pay not available:", data);
6054
+ // Show alternative payment methods
6055
+ });
6056
+
6057
+ button.onError((data) => {
6058
+ console.error("Payment error:", data);
6059
+ // Handle error appropriately
6060
+ });
6061
+
6062
+ button.onCancel((data) => {
6063
+ console.log("Payment cancelled");
6064
+ // Handle cancellation
6065
+ });
6066
+
6067
+ button.onClick((data) => {
6068
+ console.log("Google Pay button clicked");
6069
+ // Perform pre-payment validation
6070
+ });
6071
+
6072
+ button.load();
6073
+
6074
+ // Helper functions
6075
+ async function updateShippingCosts(addressData) {
6076
+ const baseAmount = 100;
6077
+ const updatedShippingOptions = [
6078
+ {
6079
+ id: "updated-standard",
6080
+ label: "Updated Standard Shipping",
6081
+ detail: "Based on your location",
6082
+ amount: 8.00,
6083
+ type: "ELECTRONIC"
6084
+ },
6085
+ {
6086
+ id: "updated-express",
6087
+ label: "Updated Express Shipping",
6088
+ detail: "Fast delivery to your area",
6089
+ amount: 18.00,
6090
+ type: "PICKUP"
6091
+ }
6092
+ ];
6093
+
6094
+ return {
6095
+ newAmount: baseAmount + updatedShippingOptions[0].amount,
6096
+ shippingOptions: updatedShippingOptions
6097
+ };
6098
+ }
6099
+
6100
+ async function updateTotal(optionData) {
6101
+ const baseAmount = 100;
6102
+ const shippingAmount = optionData.amount || optionData.data?.amount;
6103
+ return {
6104
+ newAmount: baseAmount + shippingAmount
6105
+ };
6106
+ }
6107
+
6108
+ function processPayment(ottToken) {
6109
+ fetch('/api/process-payment', {
6110
+ method: 'POST',
6111
+ headers: { 'Content-Type': 'application/json' },
6112
+ body: JSON.stringify({ ott_token: ottToken })
6113
+ });
6114
+ }
6115
+ </script>
6116
+ </html>
6117
+ ```
6118
+
6119
+ ## Common API
6120
+
6121
+ Both `ApplePayOpenWalletButton` and `GooglePayOpenWalletButton` share the same event handler API inherited from the base class.
6122
+
6123
+ ### Checking for button availability
6124
+
6125
+ 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
+
6127
+ ```javascript
6128
+ button.onUnavailable((data) => console.log("No wallet button available", data));
6129
+ ```
6130
+
6131
+ ### Service type validation
6132
+
6133
+ Each button validates that the service configuration matches its expected wallet type. If you use an Apple Pay service ID with `GooglePayOpenWalletButton` (or vice versa), an error will be emitted via `onError`:
6134
+
6135
+ ```javascript
6136
+ // This will raise an error if the service ID does not correspond to a Google Pay service
6137
+ let button = new paydock.GooglePayOpenWalletButton(
6138
+ "#widget",
6139
+ publicKeyOrAccessToken,
6140
+ applePayServiceId, // Wrong! This is an Apple Pay service ID
6141
+ meta
6142
+ );
6143
+
6144
+ button.onError((data) => {
6145
+ // Error: Service configuration type 'ApplePay' does not match expected wallet type 'google'.
6146
+ console.error(data.error.message);
6147
+ });
6148
+
6149
+ button.load();
6150
+ ```
6151
+
6152
+ ### Performing actions when the wallet button is clicked
6153
+
6154
+ 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.
6155
+
6156
+ ```javascript
6157
+ // Synchronous example
6158
+ button.onClick((data) => {
6159
+ 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
+
6166
+ // Asynchronous example
6167
+ button.onClick((data) => {
6168
+ // Attach a Promise to control the wallet flow
6169
+ data.attachResult(
6170
+ fetch('/api/validate-order')
6171
+ .then(response => response.json())
6172
+ .then(result => {
6173
+ if (!result.valid) {
6174
+ throw new Error('Order validation failed');
6175
+ }
6176
+ return result;
6177
+ })
6178
+ );
6179
+ });
6180
+ ```
6181
+
6182
+ ### Handling successful OTT creation
6183
+
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
+
6186
+ ```javascript
6187
+ button.onSuccess((data) => {
6188
+ console.log("OTT created successfully:", data.token);
6189
+ console.log("Amount:", data.amount);
6190
+ console.log("Shipping:", data.shipping);
6191
+ console.log("Billing:", data.billing);
6192
+
6193
+ // Use the OTT token to complete payment on your backend
6194
+ fetch('/api/process-payment', {
6195
+ method: 'POST',
6196
+ headers: { 'Content-Type': 'application/json' },
6197
+ body: JSON.stringify({ ott_token: data.token })
6198
+ });
6199
+ });
6200
+ ```
6201
+
6202
+ **Important**: The `onSuccess` event handler is mandatory. Not providing one will result in an error.
6203
+
6204
+ ### Updating meta after initialization
6205
+
6206
+ If the screen where the button is rendered allows for cart/amount changes, call `setMeta` method to update the meta information. The `setMeta` method is fully typed for each wallet:
6207
+
6208
+ ```javascript
6209
+ // For Apple Pay - accepts ApplePayOpenWalletMeta
6210
+ applePayButton.setMeta({ ...meta, amount: 29.99, amount_label: 'NEW TOTAL' });
6211
+
6212
+ // For Google Pay - accepts GooglePayOpenWalletMeta
6213
+ googlePayButton.setMeta({ ...meta, amount: 29.99, merchant_name: 'Updated Store' });
6214
+ ```
6215
+
6216
+ ### Handling errors
6217
+
6218
+ Register a callback function to handle errors that occur during wallet operations, including service type mismatches.
6219
+
6220
+ ```javascript
6221
+ button.onError((data) => {
6222
+ console.error("Open Wallet error:", data.error);
6223
+ console.log("Error context:", data.context);
6224
+
6225
+ // Show user-friendly error message
6226
+ showErrorMessage("Payment initialization failed. Please try again.");
6227
+ });
6228
+ ```
6229
+
6230
+ ### Handling checkout cancellation
6231
+
6232
+ When the user cancels or closes the wallet payment interface, you can perform cleanup operations.
6233
+
6234
+ ```javascript
6235
+ button.onCancel((data) => {
6236
+ console.log("Wallet checkout cancelled", data);
6237
+
6238
+ // Perform cleanup or redirect user
6239
+ window.location.href = '/checkout';
6240
+ });
6241
+ ```
6242
+
6243
+ ### Cleaning up
6244
+
6245
+ Remove the wallet button from the DOM when it is no longer needed:
6246
+
6247
+ ```javascript
6248
+ button.destroy();
6249
+ ```
6250
+
6251
+ ### Events
6252
+ 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
+
6254
+ **Available Event Handler Methods:**
6255
+ - `onClick(handler)` - Button click events (supports attachResult for flow control)
6256
+ - `onSuccess(handler)` - **Required** - OTT creation success events
6257
+ - `onUnavailable(handler)` - Wallet unavailable events (supports Promise pattern)
6258
+ - `onError(handler)` - Error events (supports Promise pattern)
6259
+ - `onCancel(handler)` - Checkout cancellation events (supports Promise pattern)
6260
+ - `onLoaded(handler)` - Button loaded/rendered events
6261
+ - `onShippingAddressChange(handler)` - **Required for shipping** - Address change events
6262
+ - `onShippingOptionsChange(handler)` - **Required for shipping options** - Option change events
6263
+
6264
+ **Event Handler Patterns:**
6265
+
6266
+ ```javascript
6267
+ // Required handlers (will throw error if not provided)
6268
+ button.onSuccess(handler); // Always required
6269
+ button.onShippingAddressChange(handler); // Required when shipping enabled
6270
+ button.onShippingOptionsChange(handler); // Required when shipping options provided
6271
+
6272
+ // Optional handlers with Promise support
6273
+ button.onUnavailable(handler); // or await button.onUnavailable()
6274
+ button.onError(handler); // or await button.onError()
6275
+ button.onCancel(handler); // or await button.onCancel()
6276
+
6277
+ // Click handler with flow control
6278
+ button.onClick(handler); // Use data.attachResult() for async operations
6279
+
6280
+ // Loaded handler
6281
+ button.onLoaded(handler); // Notified when button renders
6282
+ ```
6283
+
6284
+ ### Apple Pay-Specific Meta Properties
6285
+
6286
+ A full description of the [ApplePayOpenWalletMeta](#ApplePayOpenWalletMeta) properties:
6287
+
6288
+ **Required:**
6289
+ - `amount`: The payment amount (number)
6290
+ - `currency`: The currency code (string, e.g., "AUD")
6291
+ - `country`: The country code (string, e.g., "AU")
6292
+ - `amount_label`: Label for the total amount (string)
6293
+ - `store_name`: Merchant store name (string)
6294
+
6295
+ **Optional:**
6296
+ - `request_shipping?: boolean`: Enable shipping address collection
6297
+ - `shipping_options?: IApplePayShippingOption[]`: Array of shipping options
6298
+ - `show_billing_address?: boolean`: Show billing address fields
6299
+ - `apple_pay_capabilities?: string[]`: Device capabilities
6300
+ - `merchant_capabilities?: string[]`: Merchant capabilities
6301
+ - `supported_networks?: string[]`: Supported payment networks
6302
+ - `required_billing_contact_fields?: string[]`: Required billing contact fields
6303
+ - `required_shipping_contact_fields?: string[]`: Required shipping contact fields
6304
+ - `supported_countries?: string[]`: Supported countries
6305
+ - `shipping_editing_mode?: 'available' | 'store_pickup'`: Shipping address editing mode
6306
+ - `style?: { button_type?: ApplePayButtonType, button_style?: ApplePayButtonStyle }`: Button styling
6307
+
6308
+ ### Google Pay-Specific Meta Properties
6309
+
6310
+ A full description of the [GooglePayOpenWalletMeta](#GooglePayOpenWalletMeta) properties:
6311
+
6312
+ **Required:**
6313
+ - `amount`: The payment amount (number)
6314
+ - `currency`: The currency code (string, e.g., "AUD")
6315
+ - `country`: The country code (string, e.g., "AU")
6316
+
6317
+ **Optional:**
6318
+ - `amount_label?: string`: Label for the total amount
6319
+ - `merchant_name?: string`: Display name for the merchant
6320
+ - `request_shipping?: boolean`: Enable shipping address collection
6321
+ - `shipping_options?: IGooglePayShippingOption[]`: Array of shipping options
6322
+ - `show_billing_address?: boolean`: Show billing address fields
6323
+ - `card_config?: GooglePayCardConfig`: Card configuration (auth methods, networks, tokenization)
6324
+ - `style?: { button_type?: GooglePayButtonType, button_color?: GooglePayButtonColor, button_size_mode?: GooglePayButtonSizeMode }`: Button styling
6325
+
6326
+ ### Shipping Options Format
6327
+ ```javascript
6328
+ shipping_options: [
6329
+ {
6330
+ id: "option_id", // Unique identifier (string)
6331
+ label: "Option Name", // Display name (string)
6332
+ detail: "Description", // Optional description (string)
6333
+ amount: 10.00, // Shipping cost as number
6334
+ date_components_range: { // Optional: delivery date range (Apple Pay only)
6335
+ start_date_components: {
6336
+ years: 0,
6337
+ months: 0,
6338
+ days: 5,
6339
+ hours: 0,
6340
+ },
6341
+ end_date_components: {
6342
+ years: 0,
6343
+ months: 0,
6344
+ days: 10,
6345
+ hours: 0,
6346
+ }
6347
+ }
6348
+ }
6349
+ ]
6350
+ ```
6351
+
6352
+ **Important**:
6353
+ - `amount` should be a **number**, not a string
6354
+ - `date_components_range` is optional but provides delivery estimates (Apple Pay only)
6355
+ - Updated shipping options returned from event handlers don't require `date_components_range`
6356
+
6357
+ ### Environment Setup
6358
+ ```javascript
6359
+ // Always set environment before loading
6360
+ button.setEnv('sandbox');
6361
+ button.load();
6362
+ ```
6363
+
6364
+ ### Error Handling Best Practices
6365
+ ```javascript
6366
+ button.onError(function(data) {
6367
+ console.error('Full error object:', data);
6368
+
6369
+ // Check different error properties
6370
+ const errorMessage = data.error?.message ||
6371
+ data.message ||
6372
+ 'Unknown error occurred';
6373
+
6374
+ // Handle different error types
6375
+ if (data.context?.operation === 'wallet_operation') {
6376
+ // Handle wallet-specific errors
6377
+ showWalletError(errorMessage);
6378
+ } else {
6379
+ // Handle general errors
6380
+ showGeneralError(errorMessage);
6381
+ }
6382
+ });
6383
+ ```
6384
+
6385
+ ## Classes
6386
+
6387
+ <dl>
6388
+ <dt><a href="#ApplePayOpenWalletButton">ApplePayOpenWalletButton</a> ⇐ <code><a href="#OpenWalletButtons">OpenWalletButtons</a></code></dt>
6389
+ <dd><p>Apple Pay wallet button that creates One-Time Tokens (OTT) via Apple Pay.</p>
6390
+ <p>Provides a fully typed Apple Pay integration with Apple Pay-specific metadata
6391
+ and validates that the service configuration corresponds to an Apple Pay service.
6392
+ On <code>load()</code>, the button fetches the service configuration and raises an error via <code>onError</code>
6393
+ if the service type does not match Apple Pay.</p>
6394
+ </dd>
6395
+ <dt><a href="#GooglePayOpenWalletButton">GooglePayOpenWalletButton</a> ⇐ <code><a href="#OpenWalletButtons">OpenWalletButtons</a></code></dt>
6396
+ <dd><p>Google Pay wallet button that creates One-Time Tokens (OTT) via Google Pay.</p>
6397
+ <p>Provides a fully typed Google Pay integration with Google Pay-specific metadata
6398
+ and validates that the service configuration corresponds to a Google Pay service.
6399
+ On <code>load()</code>, the button fetches the service configuration and raises an error via <code>onError</code>
6400
+ if the service type does not match Google Pay.</p>
6401
+ </dd>
6402
+ <dt><a href="#OpenWalletButtons">OpenWalletButtons</a></dt>
6403
+ <dd><p>Abstract base class for Open Wallet buttons. <strong>Do not instantiate directly.</strong>
6404
+ Use <a href="#ApplePayOpenWalletButton">ApplePayOpenWalletButton</a> or <a href="#GooglePayOpenWalletButton">GooglePayOpenWalletButton</a> instead.</p>
6405
+ <p>Use one of the concrete implementations instead:</p>
6406
+ <ul>
6407
+ <li><a href="#ApplePayOpenWalletButton">ApplePayOpenWalletButton</a> for Apple Pay integration</li>
6408
+ <li><a href="#GooglePayOpenWalletButton">GooglePayOpenWalletButton</a> for Google Pay integration</li>
6409
+ </ul>
6410
+ <p>These subclasses inherit all event handlers and lifecycle methods documented below.</p>
6411
+ </dd>
6412
+ </dl>
6413
+
6414
+ ## Constants
6415
+
6416
+ <dl>
6417
+ <dt><a href="#EVENT">EVENT</a> : <code>object</code></dt>
6418
+ <dd><p>List of available event names in the Open Wallet button lifecycle.</p>
6419
+ </dd>
6420
+ <dt><a href="#WALLET_TYPES">WALLET_TYPES</a> : <code>object</code></dt>
6421
+ <dd><p>Enum of available wallet types.</p>
6422
+ </dd>
6423
+ <dt><a href="#TOKEN_TYPE">TOKEN_TYPE</a> : <code>object</code></dt>
6424
+ <dd><p>Token types returned in the OTT (One-Time Token) creation response.</p>
6425
+ </dd>
6426
+ <dt><a href="#ERROR_OPERATION">ERROR_OPERATION</a> : <code>object</code></dt>
6427
+ <dd><p>Operations that can fail during the wallet lifecycle.
6428
+ Used in the <code>context.operation</code> field of <a href="#OnErrorEventData">OnErrorEventData</a>.</p>
6429
+ </dd>
6430
+ </dl>
6431
+
6432
+ ## Typedefs
6433
+
6434
+ <dl>
6435
+ <dt><a href="#OnClickCallback">OnClickCallback</a> ⇒ <code>boolean</code> | <code>void</code> | <code>Promise.&lt;(boolean|void)&gt;</code></dt>
6436
+ <dd><p>Callback for onClick method.</p>
6437
+ </dd>
6438
+ <dt><a href="#OnSuccessCallback">OnSuccessCallback</a> : <code>function</code></dt>
6439
+ <dd><p>Callback for onSuccess method.</p>
6440
+ </dd>
6441
+ <dt><a href="#OnUnavailableCallback">OnUnavailableCallback</a> : <code>function</code></dt>
6442
+ <dd><p>Callback for onUnavailable method.</p>
6443
+ </dd>
6444
+ <dt><a href="#OnErrorCallback">OnErrorCallback</a> : <code>function</code></dt>
6445
+ <dd><p>Callback for onError method.</p>
6446
+ </dd>
6447
+ <dt><a href="#OnCancelCallback">OnCancelCallback</a> : <code>function</code></dt>
6448
+ <dd><p>Callback for onCancel method.</p>
6449
+ </dd>
6450
+ <dt><a href="#OnShippingAddressChangeCallback">OnShippingAddressChangeCallback</a> ⇒ <code><a href="#OnShippingAddressChangeEventResponse">OnShippingAddressChangeEventResponse</a></code> | <code><a href="#OnShippingAddressChangeEventResponse">Promise.&lt;OnShippingAddressChangeEventResponse&gt;</a></code></dt>
6451
+ <dd><p>Callback for onShippingAddressChange method.</p>
6452
+ </dd>
6453
+ <dt><a href="#OnShippingOptionsChangeCallback">OnShippingOptionsChangeCallback</a> ⇒ <code><a href="#OnShippingOptionChangeEventResponse">OnShippingOptionChangeEventResponse</a></code> | <code><a href="#OnShippingOptionChangeEventResponse">Promise.&lt;OnShippingOptionChangeEventResponse&gt;</a></code></dt>
6454
+ <dd><p>Callback for onShippingOptionsChange method.</p>
6455
+ </dd>
6456
+ </dl>
6457
+
6458
+ ## Interfaces
6459
+
6460
+ <dl>
6461
+ <dt><a href="#ApplePayOpenWalletMeta">ApplePayOpenWalletMeta</a> : <code>object</code></dt>
6462
+ <dd><p>Interface for Apple Pay-specific metadata.</p>
6463
+ <p>For further information about ApplePay Capabilities refer to <a href="https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/4440085-applepaycapabilities">the documentation</a>.
6464
+ Apple will determine if the device has an ApplePay wallet available and at least one active payment.</p>
6465
+ </dd>
6466
+ <dt><a href="#GooglePayOpenWalletMeta">GooglePayOpenWalletMeta</a> : <code>object</code></dt>
6467
+ <dd><p>Interface for Google Pay-specific metadata.</p>
6468
+ </dd>
6469
+ <dt><a href="#OnClickEventData">OnClickEventData</a> : <code>object</code></dt>
6470
+ <dd><p>Interface for OnClickEventData.
6471
+ Emitted when the wallet button is clicked.</p>
6472
+ <p>The merchant&#39;s <code>onClick</code> handler controls the payment flow via its return value:</p>
6473
+ <ul>
6474
+ <li>Return <code>void</code> / <code>undefined</code> to continue normally.</li>
6475
+ <li>Return <code>false</code> to abort the payment flow.</li>
6476
+ <li>Return a <code>Promise&lt;void&gt;</code> to defer the wallet sheet until the promise resolves.</li>
6477
+ <li>Return a <code>Promise&lt;boolean&gt;</code> — if it resolves to <code>false</code>, the flow is aborted.</li>
6478
+ <li>Throwing an error (sync or async) also aborts the flow.</li>
6479
+ </ul>
6480
+ </dd>
6481
+ <dt><a href="#OnCreateOTTSuccessfulEventData">OnCreateOTTSuccessfulEventData</a> : <code>object</code></dt>
6482
+ <dd><p>Interface for OnCreateOTTSuccessfulEventData.
6483
+ Emitted when the One-Time Token is successfully created.</p>
6484
+ </dd>
6485
+ <dt><a href="#OnCreateOTTErrorEventData">OnCreateOTTErrorEventData</a> : <code>object</code></dt>
6486
+ <dd><p>Interface for OnCreateOTTErrorEventData.
6487
+ Emitted when OTT creation fails. The error details are in the <code>data</code> payload.</p>
6488
+ </dd>
6489
+ <dt><a href="#OnUnavailableEventData">OnUnavailableEventData</a> : <code>object</code></dt>
6490
+ <dd><p>Interface for OnUnavailableEventData.
6491
+ Emitted when the wallet is not available on the current device or browser.</p>
6492
+ </dd>
6493
+ <dt><a href="#OnErrorEventData">OnErrorEventData</a> : <code>object</code></dt>
6494
+ <dd><p>Interface for OnErrorEventData.
6495
+ Emitted when an error occurs during wallet operation, including configuration issues, service type mismatches, and OTT creation failures.</p>
6496
+ </dd>
6497
+ <dt><a href="#OnLoadedEventData">OnLoadedEventData</a> : <code>object</code></dt>
6498
+ <dd><p>Interface for OnLoadedEventData.
6499
+ Emitted when the wallet button has been loaded and rendered in the DOM.
6500
+ No payload — the specific wallet type is determined by the concrete button class
6501
+ (<a href="#ApplePayOpenWalletButton">ApplePayOpenWalletButton</a> or <a href="#GooglePayOpenWalletButton">GooglePayOpenWalletButton</a>).</p>
6502
+ </dd>
6503
+ <dt><a href="#OnCancelEventData">OnCancelEventData</a> : <code>object</code></dt>
6504
+ <dd><p>Interface for OnCancelEventData.
6505
+ Emitted when the wallet checkout is cancelled or closed by the user. No payload data.</p>
6506
+ </dd>
6507
+ <dt><a href="#OnShippingAddressChangeEventData">OnShippingAddressChangeEventData</a> : <code>object</code></dt>
6508
+ <dd><p>Interface for OnShippingAddressChangeEventData.
6509
+ Emitted when the customer selects or updates their shipping address in the wallet payment sheet.
6510
+ This event is also emitted when the payment sheet first opens (INITIALIZE) with the initial shipping address, if present in the User&#39;s wallet.</p>
6511
+ <p>If no handler is registered for this event, the SDK auto-accepts with the current transaction data.</p>
6512
+ </dd>
6513
+ <dt><a href="#OnShippingAddressChangeEventResponse">OnShippingAddressChangeEventResponse</a> : <code>object</code></dt>
6514
+ <dd><p>Interface for OnShippingAddressChangeEventResponse.
6515
+ Returned by the merchant&#39;s <code>onShippingAddressChange</code> handler.</p>
6516
+ </dd>
6517
+ <dt><a href="#OnShippingOptionChangeEventData">OnShippingOptionChangeEventData</a> : <code>object</code></dt>
6518
+ <dd><p>Interface for OnShippingOptionChangeEventData.
6519
+ Emitted when the customer selects a shipping option in the wallet payment sheet.</p>
6520
+ <p>If no handler is registered for this event, the SDK auto-accepts with the current transaction data.</p>
6521
+ </dd>
6522
+ <dt><a href="#OnShippingOptionChangeEventResponse">OnShippingOptionChangeEventResponse</a> : <code>object</code></dt>
6523
+ <dd><p>Interface for OnShippingOptionChangeEventResponse.
6524
+ Returned by the merchant&#39;s <code>onShippingOptionsChange</code> handler.</p>
6525
+ </dd>
6526
+ <dt><a href="#IApplePayShippingOption">IApplePayShippingOption</a> : <code>object</code></dt>
6527
+ <dd><p>Interface for IApplePayShippingOption.
6528
+ Used for shipping options in Apple Pay wallets.</p>
6529
+ </dd>
6530
+ <dt><a href="#IGooglePayShippingOption">IGooglePayShippingOption</a> : <code>object</code></dt>
6531
+ <dd><p>Interface for IGooglePayShippingOption.
6532
+ Used for shipping options in Google Pay wallets.</p>
6533
+ </dd>
6534
+ </dl>
6535
+
6536
+ <a name="ApplePayOpenWalletMeta" id="ApplePayOpenWalletMeta" href="#ApplePayOpenWalletMeta">&nbsp;</a>
6537
+
6538
+ ## ApplePayOpenWalletMeta : <code>object</code>
6539
+ Interface for Apple Pay-specific metadata.
6540
+
6541
+ For further information about ApplePay Capabilities refer to [the documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/4440085-applepaycapabilities).
6542
+ Apple will determine if the device has an ApplePay wallet available and at least one active payment.
6543
+
6544
+ **Kind**: global interface
6545
+
6546
+ | Param | Type | Description |
6547
+ | --- | --- | --- |
6548
+ | amount | <code>number</code> | The payment amount. |
6549
+ | currency | <code>string</code> | The ISO 4217 currency code. |
6550
+ | country | <code>string</code> | The ISO 3166-1 alpha-2 country code. |
6551
+ | amount_label | <code>string</code> | Label shown next to the total amount (e.g. `'TOTAL'`). Used in the Apple Pay payment sheet. |
6552
+ | [request_shipping] | <code>boolean</code> | Enable shipping address collection in the Apple Pay sheet. |
6553
+ | [shipping_options] | [<code>Array.&lt;IApplePayShippingOption&gt;</code>](#IApplePayShippingOption) | Array of available shipping options. The first item is used as the default selected option. Requires `request_shipping` to be `true`. |
6554
+ | [show_billing_address] | <code>boolean</code> | Show billing address fields in the Apple Pay sheet. |
6555
+ | store_name | <code>string</code> | The merchant's store name displayed during payment. |
6556
+ | [apple_pay_capabilities] | <code>Array.&lt;(&#x27;credentials\_available&#x27;\|&#x27;credentials\_status\_unknown&#x27;\|&#x27;credentials\_unavailable&#x27;)&gt;</code> | Device capabilities needed for the wallet button to be available. |
6557
+ | [merchant_capabilities] | <code>Array.&lt;(&#x27;supports3DS&#x27;\|&#x27;supportsEMV&#x27;\|&#x27;supportsCredit&#x27;\|&#x27;supportsDebit&#x27;)&gt;</code> | Array of merchant capabilities influencing the transaction processing features available. |
6558
+ | [supported_networks] | <code>Array.&lt;(&#x27;visa&#x27;\|&#x27;masterCard&#x27;\|&#x27;amex&#x27;\|&#x27;chinaUnionPay&#x27;\|&#x27;discover&#x27;\|&#x27;interac&#x27;\|&#x27;jcb&#x27;\|&#x27;privateLabel&#x27;)&gt;</code> | List of payment networks supported for Apple Pay transactions. |
6559
+ | [required_billing_contact_fields] | <code>Array.&lt;(&#x27;email&#x27;\|&#x27;name&#x27;\|&#x27;phone&#x27;\|&#x27;postalAddress&#x27;)&gt;</code> | Contact fields required from the user for billing purposes. Phone and email are currently not returned by Apple. |
6560
+ | [required_shipping_contact_fields] | <code>Array.&lt;(&#x27;email&#x27;\|&#x27;phone&#x27;\|&#x27;postalAddress&#x27;\|&#x27;name&#x27;)&gt;</code> | Shipping contact fields required to complete the transaction. Include `'postalAddress'` to show address fields in the Apple Pay sheet. Required handling of onShippingAddressChange callback. |
6561
+ | [supported_countries] | <code>Array.&lt;string&gt;</code> | List of countries where Apple Pay is supported by the merchant. |
6562
+ | [shipping_editing_mode] | <code>&#x27;available&#x27;</code> \| <code>&#x27;store\_pickup&#x27;</code> | `'available'` for editable shipping, `'store_pickup'` for non-editable. |
6563
+ | [style] | <code>object</code> | Styling configuration for the Apple Pay button. |
6564
+ | [style.button_type] | <code>ApplePayButtonType</code> | The type of Apple Pay button (e.g. `'buy'`, `'donate'`, `'plain'`). |
6565
+ | [style.button_style] | <code>ApplePayButtonStyle</code> | The style of the Apple Pay button (`'black'`, `'white'`, `'white-outline'`). |
6566
+
6567
+ <a name="GooglePayOpenWalletMeta" id="GooglePayOpenWalletMeta" href="#GooglePayOpenWalletMeta">&nbsp;</a>
6568
+
6569
+ ## GooglePayOpenWalletMeta : <code>object</code>
6570
+ Interface for Google Pay-specific metadata.
6571
+
6572
+ **Kind**: global interface
6573
+
6574
+ | Param | Type | Description |
6575
+ | --- | --- | --- |
6576
+ | amount | <code>number</code> | The payment amount. |
6577
+ | currency | <code>string</code> | The ISO 4217 currency code. |
6578
+ | country | <code>string</code> | The ISO 3166-1 alpha-2 country code. |
6579
+ | [amount_label] | <code>string</code> | Label shown next to the total amount. |
6580
+ | [merchant_name] | <code>string</code> | Display name for the merchant in the Google Pay sheet. |
6581
+ | [request_shipping] | <code>boolean</code> | Enable shipping address collection. |
6582
+ | [shipping_options] | [<code>Array.&lt;IGooglePayShippingOption&gt;</code>](#IGooglePayShippingOption) | Array of available shipping options. The first item is used as the default selected option. Requires `request_shipping` to be `true`. |
6583
+ | [show_billing_address] | <code>boolean</code> | Show billing address fields. |
6584
+ | [card_config] | <code>object</code> | Google Pay card configuration for custom auth methods, card networks, and tokenization. |
6585
+ | [style] | <code>object</code> | Styling configuration for the Google Pay button. |
6586
+ | [style.button_type] | <code>GooglePayButtonType</code> | The type of Google Pay button (`'book'`, `'buy'`, `'checkout'`, `'donate'`, `'order'`, `'pay'`, `'plain'`, `'subscribe'`). |
6587
+ | [style.button_color] | <code>GooglePayButtonColor</code> | The color of the Google Pay button (`'default'`, `'black'`, `'white'`). |
6588
+ | [style.button_size_mode] | <code>GooglePayButtonSizeMode</code> | The size mode (`'static'`, `'fill'`). |
6589
+
6590
+ <a name="OnClickEventData" id="OnClickEventData" href="#OnClickEventData">&nbsp;</a>
6591
+
6592
+ ## OnClickEventData : <code>object</code>
6593
+ Interface for OnClickEventData.
6594
+ Emitted when the wallet button is clicked.
6595
+
6596
+ The merchant's `onClick` handler controls the payment flow via its return value:
6597
+ - Return `void` / `undefined` to continue normally.
6598
+ - Return `false` to abort the payment flow.
6599
+ - Return a `Promise<void>` to defer the wallet sheet until the promise resolves.
6600
+ - Return a `Promise<boolean>` — if it resolves to `false`, the flow is aborted.
6601
+ - Throwing an error (sync or async) also aborts the flow.
6602
+
6603
+ **Kind**: global interface
6604
+
6605
+ | Param | Type | Description |
6606
+ | --- | --- | --- |
6607
+ | event | <code>string</code> | Always `'onClick'`. |
6608
+
6609
+ <a name="OnCreateOTTSuccessfulEventData" id="OnCreateOTTSuccessfulEventData" href="#OnCreateOTTSuccessfulEventData">&nbsp;</a>
6610
+
6611
+ ## OnCreateOTTSuccessfulEventData : <code>object</code>
6612
+ Interface for OnCreateOTTSuccessfulEventData.
6613
+ Emitted when the One-Time Token is successfully created.
6614
+
6615
+ **Kind**: global interface
6616
+
6617
+ | Param | Type | Description |
6618
+ | --- | --- | --- |
6619
+ | event | <code>string</code> | Always `'success'`. |
6620
+ | [data] | <code>object</code> | OTT success payload. |
6621
+ | data.token | <code>object</code> | The created OTT response. |
6622
+ | data.token.temp_token | <code>string</code> | The temporary one-time token string. |
6623
+ | data.token.token_type | [<code>TOKEN\_TYPE</code>](#TOKEN_TYPE) | The type of the token. `TOKEN_TYPE.CARD` for FPAN (Google Pay only), `TOKEN_TYPE.CARD_SCHEME_TOKEN` for DPAN (Apple Pay & Google Pay). |
6624
+ | data.amount | <code>number</code> | The payment amount. |
6625
+ | [data.shipping] | <code>object</code> | The shipping address and contact information, if provided. |
6626
+ | [data.shipping.method] | <code>string</code> | The shipping method. |
6627
+ | [data.shipping.options] | <code>Array.&lt;(IApplePayShippingOption\|IGooglePayShippingOption)&gt;</code> | The selected shipping options. |
6628
+ | [data.shipping.address_line1] | <code>string</code> | Shipping address line 1. |
6629
+ | [data.shipping.address_line2] | <code>string</code> | Shipping address line 2. |
6630
+ | [data.shipping.address_city] | <code>string</code> | Shipping address city. |
6631
+ | [data.shipping.address_postcode] | <code>string</code> | Shipping address postal code. |
6632
+ | [data.shipping.address_state] | <code>string</code> | Shipping address state or province. |
6633
+ | [data.shipping.address_country] | <code>string</code> | Shipping address country code. |
6634
+ | [data.shipping.address_company] | <code>string</code> | Shipping company name. |
6635
+ | [data.shipping.address_origin_postcode] | <code>string</code> | Origin postal code. |
6636
+ | [data.shipping.contact] | <code>object</code> | Shipping contact information. |
6637
+ | [data.shipping.contact.first_name] | <code>string</code> | Contact first name. |
6638
+ | [data.shipping.contact.last_name] | <code>string</code> | Contact last name. |
6639
+ | [data.shipping.contact.email] | <code>string</code> | Contact email address. |
6640
+ | [data.shipping.contact.phone] | <code>string</code> | Contact phone number. |
6641
+ | [data.shipping.contact.phone2] | <code>string</code> | Contact secondary phone number. |
6642
+ | [data.billing] | <code>object</code> | The billing address, if provided. |
6643
+ | data.billing.address_line1 | <code>string</code> | Billing address line 1. |
6644
+ | data.billing.address_line2 | <code>string</code> | Billing address line 2. |
6645
+ | data.billing.address_country | <code>string</code> | Billing address country code. |
6646
+ | data.billing.address_city | <code>string</code> | Billing address city. |
6647
+ | data.billing.address_postcode | <code>string</code> | Billing address postal code. |
6648
+ | data.billing.address_state | <code>string</code> | Billing address state or province. |
6649
+
6650
+ <a name="OnCreateOTTErrorEventData" id="OnCreateOTTErrorEventData" href="#OnCreateOTTErrorEventData">&nbsp;</a>
6651
+
6652
+ ## OnCreateOTTErrorEventData : <code>object</code>
6653
+ Interface for OnCreateOTTErrorEventData.
6654
+ Emitted when OTT creation fails. The error details are in the `data` payload.
6655
+
6656
+ **Kind**: global interface
6657
+
6658
+ | Param | Type | Description |
6659
+ | --- | --- | --- |
6660
+ | event | <code>string</code> | Always `'error'`. |
6661
+ | [data] | <code>object</code> | Error details payload. |
6662
+ | [data.message] | <code>string</code> | Error message. |
6663
+ | [data.code] | <code>string</code> | Error code. |
6664
+
6665
+ <a name="OnUnavailableEventData" id="OnUnavailableEventData" href="#OnUnavailableEventData">&nbsp;</a>
6666
+
6667
+ ## OnUnavailableEventData : <code>object</code>
6668
+ Interface for OnUnavailableEventData.
6669
+ Emitted when the wallet is not available on the current device or browser.
6670
+
6671
+ **Kind**: global interface
6672
+
6673
+ | Param | Type | Description |
6674
+ | --- | --- | --- |
6675
+ | event | <code>string</code> | Always `'unavailable'`. |
6676
+ | [data] | <code>object</code> | Unavailability details payload. |
6677
+ | data.reason | <code>string</code> | A human-readable reason why the wallet is unavailable. |
6678
+ | [data.details] | <code>object</code> | Additional details about the unavailability. |
6679
+ | data.details.service_id | <code>string</code> | The service ID that was checked. |
6680
+
6681
+ <a name="OnErrorEventData" id="OnErrorEventData" href="#OnErrorEventData">&nbsp;</a>
6682
+
6683
+ ## OnErrorEventData : <code>object</code>
6684
+ Interface for OnErrorEventData.
6685
+ Emitted when an error occurs during wallet operation, including configuration issues, service type mismatches, and OTT creation failures.
6686
+
6687
+ **Kind**: global interface
6688
+
6689
+ | Param | Type | Description |
6690
+ | --- | --- | --- |
6691
+ | event | <code>string</code> | Always `'error'`. |
6692
+ | [data] | <code>object</code> | Error payload. |
6693
+ | data.error | <code>Error</code> | The Error object describing what went wrong. |
6694
+ | [data.context] | <code>object</code> | Context about the error. |
6695
+ | [data.context.operation] | [<code>ERROR\_OPERATION</code>](#ERROR_OPERATION) | The operation that failed. See [ERROR_OPERATION](#ERROR_OPERATION) enum for possible values. |
6696
+
6697
+ <a name="OnLoadedEventData" id="OnLoadedEventData" href="#OnLoadedEventData">&nbsp;</a>
6698
+
6699
+ ## OnLoadedEventData : <code>object</code>
6700
+ Interface for OnLoadedEventData.
6701
+ Emitted when the wallet button has been loaded and rendered in the DOM.
6702
+ No payload — the specific wallet type is determined by the concrete button class
6703
+ ([ApplePayOpenWalletButton](#ApplePayOpenWalletButton) or [GooglePayOpenWalletButton](#GooglePayOpenWalletButton)).
6704
+
6705
+ **Kind**: global interface
6706
+
6707
+ | Param | Type | Description |
6708
+ | --- | --- | --- |
6709
+ | event | <code>string</code> | Always `'loaded'`. |
6710
+
6711
+ <a name="OnCancelEventData" id="OnCancelEventData" href="#OnCancelEventData">&nbsp;</a>
6712
+
6713
+ ## OnCancelEventData : <code>object</code>
6714
+ Interface for OnCancelEventData.
6715
+ Emitted when the wallet checkout is cancelled or closed by the user. No payload data.
6716
+
6717
+ **Kind**: global interface
6718
+
6719
+ | Param | Type | Description |
6720
+ | --- | --- | --- |
6721
+ | event | <code>string</code> | Always `'checkoutClose'`. |
6722
+
6723
+ <a name="OnShippingAddressChangeEventData" id="OnShippingAddressChangeEventData" href="#OnShippingAddressChangeEventData">&nbsp;</a>
6724
+
6725
+ ## OnShippingAddressChangeEventData : <code>object</code>
6726
+ Interface for OnShippingAddressChangeEventData.
6727
+ Emitted when the customer selects or updates their shipping address in the wallet payment sheet.
6728
+ This event is also emitted when the payment sheet first opens (INITIALIZE) with the initial shipping address, if present in the User's wallet.
6729
+
6730
+ If no handler is registered for this event, the SDK auto-accepts with the current transaction data.
6731
+
6732
+ **Kind**: global interface
6733
+
6734
+ | Param | Type | Description |
6735
+ | --- | --- | --- |
6736
+ | event | <code>string</code> | Always `'onShippingAddressChange'`. |
6737
+ | [data] | <code>object</code> | Shipping address data. |
6738
+ | [data.address_city] | <code>string</code> | Shipping address city. |
6739
+ | [data.address_state] | <code>string</code> | Shipping address state. |
6740
+ | [data.address_postcode] | <code>string</code> | Shipping address postal code. |
6741
+ | [data.address_country] | <code>string</code> | Shipping address country code. |
6742
+ | [data.address_line1] | <code>string</code> | Apple Pay only - Shipping address line 1. |
6743
+ | [data.address_line2] | <code>string</code> | Apple Pay only - Shipping address line 2. |
6744
+ | [data.contact.phone] | <code>string</code> | Apple Pay only - Shipping contact phone. |
6745
+ | [data.contact.email] | <code>string</code> | Apple Pay only - Shipping contact email. |
6746
+ | [data.contact.first_name] | <code>string</code> | Apple Pay only - Shipping contact first name. |
6747
+ | [data.contact.last_name] | <code>string</code> | Apple Pay only - Shipping contact last name. |
6748
+
6749
+ <a name="OnShippingAddressChangeEventResponse" id="OnShippingAddressChangeEventResponse" href="#OnShippingAddressChangeEventResponse">&nbsp;</a>
6750
+
6751
+ ## OnShippingAddressChangeEventResponse : <code>object</code>
6752
+ Interface for OnShippingAddressChangeEventResponse.
6753
+ Returned by the merchant's `onShippingAddressChange` handler.
6754
+
6755
+ **Kind**: global interface
6756
+
6757
+ | Param | Type | Description |
6758
+ | --- | --- | --- |
6759
+ | [amount] | <code>number</code> | Updated payment amount based on the new shipping address. |
6760
+ | [shipping_options] | <code>Array.&lt;(IApplePayShippingOption\|IGooglePayShippingOption)&gt;</code> | Updated list of available shipping options. The first item is used as the default selected option. |
6761
+ | [error] | <code>object</code> | Error object to display in the wallet payment sheet if the address is invalid. |
6762
+ | error.code | <code>string</code> | Error code. Possible values: `'address_error'`, `'country_error'`, `'state_error'`, `'zip_error'`, `'shipping_contact_invalid'`, `'billing_contact_invalid'`. |
6763
+ | [error.field] | <code>string</code> | Apple Pay only - The specific field that caused the error. Possible values: `'phone'`, `'email'`, `'name'`, `'phonetic_name'`, `'address_lines'`, `'locality'`, `'postal_code'`, `'administrative_area'`, `'country'`, `'country_code'`. |
6764
+ | [error.message] | <code>string</code> | A human-readable error message to display to the customer. |
6765
+
6766
+ <a name="OnShippingOptionChangeEventData" id="OnShippingOptionChangeEventData" href="#OnShippingOptionChangeEventData">&nbsp;</a>
6767
+
6768
+ ## OnShippingOptionChangeEventData : <code>object</code>
6769
+ Interface for OnShippingOptionChangeEventData.
6770
+ Emitted when the customer selects a shipping option in the wallet payment sheet.
6771
+
6772
+ If no handler is registered for this event, the SDK auto-accepts with the current transaction data.
6773
+
6774
+ **Kind**: global interface
6775
+
6776
+ | Param | Type | Description |
6777
+ | --- | --- | --- |
6778
+ | event | <code>string</code> | Always `'onShippingOptionsChange'`. |
6779
+ | [data] | <code>object</code> | Shipping option data. |
6780
+ | [data.shipping_option_id] | <code>string</code> | Selected shipping option ID. |
6781
+ | [data.label] | <code>string</code> | Selected shipping option label. |
6782
+ | [data.detail] | <code>string</code> | Selected shipping option detail. |
6783
+ | [data.amount] | <code>string</code> | Apple Pay only - Selected shipping option amount. |
6784
+
6785
+ <a name="OnShippingOptionChangeEventResponse" id="OnShippingOptionChangeEventResponse" href="#OnShippingOptionChangeEventResponse">&nbsp;</a>
6786
+
6787
+ ## OnShippingOptionChangeEventResponse : <code>object</code>
6788
+ Interface for OnShippingOptionChangeEventResponse.
6789
+ Returned by the merchant's `onShippingOptionsChange` handler.
6790
+
6791
+ **Kind**: global interface
6792
+
6793
+ | Param | Type | Description |
6794
+ | --- | --- | --- |
6795
+ | [amount] | <code>number</code> | Updated total payment amount based on the selected shipping option. |
6796
+ | [error] | <code>object</code> | Error object to display if the shipping option is invalid. |
6797
+ | error.code | <code>string</code> | Error code. Possible values: `'method_unavailable'`, `'store_unavailable'`. |
6798
+ | [error.message] | <code>string</code> | A human-readable error message. |
6799
+
6800
+ <a name="IApplePayShippingOption" id="IApplePayShippingOption" href="#IApplePayShippingOption">&nbsp;</a>
6801
+
6802
+ ## IApplePayShippingOption : <code>object</code>
6803
+ Interface for IApplePayShippingOption.
6804
+ Used for shipping options in Apple Pay wallets.
6805
+
6806
+ **Kind**: global interface
6807
+
6808
+ | Param | Type | Description |
6809
+ | --- | --- | --- |
6810
+ | id | <code>string</code> | Unique identifier for the shipping option. |
6811
+ | label | <code>string</code> | Display name for the shipping option. |
6812
+ | amount | <code>number</code> | Shipping cost amount. |
6813
+ | [detail] | <code>string</code> | Optional description or detail text. |
6814
+ | [date_components_range] | <code>object</code> | Apple Pay only - Delivery date range estimate. |
6815
+ | [date_components_range.start_date_components] | <code>object</code> | Start date for the delivery estimate. |
6816
+ | [date_components_range.start_date_components.years] | <code>number</code> | Years from now. |
6817
+ | [date_components_range.start_date_components.months] | <code>number</code> | Months from now. |
6818
+ | [date_components_range.start_date_components.days] | <code>number</code> | Days from now. |
6819
+ | [date_components_range.start_date_components.hours] | <code>number</code> | Hours from now. |
6820
+ | [date_components_range.end_date_components] | <code>object</code> | End date for the delivery estimate. |
6821
+ | [date_components_range.end_date_components.years] | <code>number</code> | Years from now. |
6822
+ | [date_components_range.end_date_components.months] | <code>number</code> | Months from now. |
6823
+ | [date_components_range.end_date_components.days] | <code>number</code> | Days from now. |
6824
+ | [date_components_range.end_date_components.hours] | <code>number</code> | Hours from now. |
6825
+
6826
+ <a name="IGooglePayShippingOption" id="IGooglePayShippingOption" href="#IGooglePayShippingOption">&nbsp;</a>
6827
+
6828
+ ## IGooglePayShippingOption : <code>object</code>
6829
+ Interface for IGooglePayShippingOption.
6830
+ Used for shipping options in Google Pay wallets.
6831
+
6832
+ **Kind**: global interface
6833
+
6834
+ | Param | Type | Description |
6835
+ | --- | --- | --- |
6836
+ | id | <code>string</code> | Unique identifier for the shipping option. |
6837
+ | label | <code>string</code> | Display name for the shipping option. |
6838
+ | [detail] | <code>string</code> | Optional description or detail text. |
6839
+ | [type] | <code>&#x27;ELECTRONIC&#x27;</code> \| <code>&#x27;GROUND&#x27;</code> \| <code>&#x27;NOT\_SHIPPED&#x27;</code> \| <code>&#x27;OVERNIGHT&#x27;</code> \| <code>&#x27;PICKUP&#x27;</code> \| <code>&#x27;PRIORITY&#x27;</code> \| <code>&#x27;SAME\_DAY&#x27;</code> | The shipping type. |
6840
+
6841
+ <a name="ApplePayOpenWalletButton" id="ApplePayOpenWalletButton" href="#ApplePayOpenWalletButton">&nbsp;</a>
6842
+
6843
+ ## ApplePayOpenWalletButton ⇐ [<code>OpenWalletButtons</code>](#OpenWalletButtons)
6844
+ Apple Pay wallet button that creates One-Time Tokens (OTT) via Apple Pay.
6845
+
6846
+ Provides a fully typed Apple Pay integration with Apple Pay-specific metadata
6847
+ and validates that the service configuration corresponds to an Apple Pay service.
6848
+ On `load()`, the button fetches the service configuration and raises an error via `onError`
6849
+ if the service type does not match Apple Pay.
6850
+
6851
+ **Kind**: global class
6852
+ **Extends**: [<code>OpenWalletButtons</code>](#OpenWalletButtons)
6853
+
6854
+ * [ApplePayOpenWalletButton](#ApplePayOpenWalletButton) ⇐ [<code>OpenWalletButtons</code>](#OpenWalletButtons)
6855
+ * [new ApplePayOpenWalletButton(selector, publicKeyOrAccessToken, serviceId, meta)](#new_ApplePayOpenWalletButton_new)
6856
+ * [.load()](#OpenWalletButtons+load)
6857
+ * [.setEnv(env, [alias])](#OpenWalletButtons+setEnv)
6858
+ * [.setMeta(meta)](#OpenWalletButtons+setMeta)
6859
+ * [.destroy()](#OpenWalletButtons+destroy)
6860
+ * [.onClick(handler)](#OpenWalletButtons+onClick)
6861
+ * [.onSuccess(handler)](#OpenWalletButtons+onSuccess)
6862
+ * [.onUnavailable(handler)](#OpenWalletButtons+onUnavailable)
6863
+ * [.onError(handler)](#OpenWalletButtons+onError)
6864
+ * [.onCancel(handler)](#OpenWalletButtons+onCancel)
6865
+ * [.onLoaded(handler)](#OpenWalletButtons+onLoaded)
6866
+ * [.onShippingAddressChange(handler)](#OpenWalletButtons+onShippingAddressChange)
6867
+ * [.onShippingOptionsChange(handler)](#OpenWalletButtons+onShippingOptionsChange)
6868
+
6869
+ <a name="new_ApplePayOpenWalletButton_new" id="new_ApplePayOpenWalletButton_new" href="#new_ApplePayOpenWalletButton_new">&nbsp;</a>
6870
+
6871
+ ### new ApplePayOpenWalletButton(selector, publicKeyOrAccessToken, serviceId, meta)
6872
+
6873
+ | Param | Type | Description |
6874
+ | --- | --- | --- |
6875
+ | selector | <code>string</code> | CSS selector of the HTML element that will contain the Apple Pay button. |
6876
+ | publicKeyOrAccessToken | <code>string</code> | Public key or access token for API authentication. |
6877
+ | serviceId | <code>string</code> | The Apple Pay service ID configured in PayDock dashboard. |
6878
+ | meta | [<code>ApplePayOpenWalletMeta</code>](#ApplePayOpenWalletMeta) | Apple Pay-specific metadata (amount, currency, country, amount_label, store_name, style, apple_pay_capabilities, etc.). |
6879
+
6880
+ **Example**
6881
+ ```js
6882
+ const button = new ApplePayOpenWalletButton(
6883
+ '#wallet-container',
6884
+ publicKeyOrAccessToken,
6885
+ serviceId,
6886
+ {
6887
+ amount: 100,
6888
+ currency: 'AUD',
6889
+ country: 'AU',
6890
+ amount_label: 'TOTAL',
6891
+ store_name: 'My Store',
6892
+ apple_pay_capabilities: ['credentials_available'],
6893
+ },
6894
+ );
6895
+ button.setEnv('sandbox');
6896
+ button.onSuccess((data) => console.log('OTT:', data.token));
6897
+ button.onError((error) => console.error('Error:', error));
6898
+ button.load();
6899
+ ```
6900
+ <a name="OpenWalletButtons+load" id="OpenWalletButtons+load" href="#OpenWalletButtons+load">&nbsp;</a>
6901
+
6902
+ ### applePayOpenWalletButton.load()
6903
+ Loads and initializes the wallet button based on the service configuration.
6904
+ This method fetches the wallet service configuration, validates that the service
6905
+ type matches the expected wallet, and creates the appropriate wallet service instance.
6906
+ Bear in mind that you must call this method after setting up all event handlers.
6907
+
6908
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
6909
+ **Example**
6910
+ ```js
6911
+ button.onClick((data) => { ... });
6912
+ button.onSuccess((data) => { ... });
6913
+ button.onError((error) => { ... });
6914
+ button.load();
6915
+ ```
6916
+ <a name="OpenWalletButtons+setEnv" id="OpenWalletButtons+setEnv" href="#OpenWalletButtons+setEnv">&nbsp;</a>
6917
+
6918
+ ### applePayOpenWalletButton.setEnv(env, [alias])
6919
+ Current method can change environment. By default environment = sandbox.
6920
+ Also we can change domain alias for this environment. By default domain_alias = paydock.com
6921
+ Bear in mind that you must set an environment before calling `button.load()`.
6922
+
6923
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
6924
+
6925
+ | Param | Type | Description |
6926
+ | --- | --- | --- |
6927
+ | env | <code>string</code> | The target environment: `'sandbox'` or `'production'`. |
6928
+ | [alias] | <code>string</code> | Own domain alias. |
6929
+
6930
+ **Example**
6931
+ ```js
6932
+ button.setEnv('production', 'paydock.com');
6933
+ ```
6934
+ <a name="OpenWalletButtons+setMeta" id="OpenWalletButtons+setMeta" href="#OpenWalletButtons+setMeta">&nbsp;</a>
6935
+
6936
+ ### applePayOpenWalletButton.setMeta(meta)
6937
+ Updates the wallet metadata after initialization.
6938
+ Use this when order information changes (e.g. amount, currency) after the button has been rendered.
6939
+ Bear in mind that this must be called before the next payment attempt takes effect.
6940
+
6941
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
6942
+
6943
+ | Param | Type | Description |
6944
+ | --- | --- | --- |
6945
+ | meta | [<code>ApplePayOpenWalletMeta</code>](#ApplePayOpenWalletMeta) \| [<code>GooglePayOpenWalletMeta</code>](#GooglePayOpenWalletMeta) | The updated metadata object. The concrete type depends on the button class. |
6946
+
6947
+ **Example**
6948
+ ```js
6949
+ button.setMeta({ ...meta, amount: 29.99 });
6950
+ ```
6951
+ <a name="OpenWalletButtons+destroy" id="OpenWalletButtons+destroy" href="#OpenWalletButtons+destroy">&nbsp;</a>
6952
+
6953
+ ### applePayOpenWalletButton.destroy()
6954
+ Removes the wallet button from the DOM and cleans up resources.
6955
+ Call this method when the wallet button is no longer needed (e.g. navigating away from the payment page).
6956
+
6957
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
6958
+ **Example**
6959
+ ```js
6960
+ button.destroy();
6961
+ ```
6962
+ <a name="OpenWalletButtons+onClick" id="OpenWalletButtons+onClick" href="#OpenWalletButtons+onClick">&nbsp;</a>
6963
+
6964
+ ### applePayOpenWalletButton.onClick(handler)
6965
+ Registers a callback function to be invoked when the wallet button gets clicked.
6966
+ The handler controls the wallet payment flow via its return value:
6967
+
6968
+ - Return `void` (or nothing) to continue the payment flow normally.
6969
+ - Return `false` to abort the payment flow.
6970
+ - Return a `Promise<void>` to defer the wallet sheet until the promise resolves.
6971
+ - Return a `Promise<boolean>` — if it resolves to `false`, the flow is aborted.
6972
+ - Throwing an error (sync or async) also aborts the flow.
6973
+
6974
+ Both synchronous and asynchronous (async) handlers are supported.
6975
+
6976
+ **Note:** this callback may be called multiple times as the customer closes the payment
6977
+ checkout and re-clicks the button.
6978
+
6979
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
6980
+
6981
+ | Param | Type | Description |
6982
+ | --- | --- | --- |
6983
+ | handler | [<code>OnClickCallback</code>](#OnClickCallback) | Function to be called when the wallet button is clicked. |
6984
+
6985
+ **Example**
6986
+ ```js
6987
+ // Synchronous usage — continue normally
6988
+ button.onClick((event) => {
6989
+ performValidationLogic();
6990
+ });
6991
+ ```
6992
+ **Example**
6993
+ ```js
6994
+ // Synchronous abort — return false to cancel the payment
6995
+ button.onClick((event) => {
6996
+ if (!isOrderValid()) return false;
6997
+ });
6998
+ ```
6999
+ **Example**
7000
+ ```js
7001
+ // Asynchronous usage — defer wallet sheet until the promise resolves
7002
+ button.onClick(async (event) => {
7003
+ await fetch('/validate-order').then(res => res.json());
7004
+ });
7005
+ ```
7006
+ <a name="OpenWalletButtons+onSuccess" id="OpenWalletButtons+onSuccess" href="#OpenWalletButtons+onSuccess">&nbsp;</a>
7007
+
7008
+ ### applePayOpenWalletButton.onSuccess(handler)
7009
+ Registers a callback function to be invoked when the OTT (One-Time Token) creation was successful.
7010
+ Both synchronous and asynchronous (async) handlers are supported.
7011
+
7012
+ **Important:** A handler is required. Do not perform thread blocking operations in callback such as `window.alert()` calls.
7013
+
7014
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7015
+ so that internal processing continues uninterrupted.
7016
+
7017
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7018
+
7019
+ | Param | Type | Description |
7020
+ | --- | --- | --- |
7021
+ | handler | [<code>OnSuccessCallback</code>](#OnSuccessCallback) | Function to be called when the OTT creation was successful. |
7022
+
7023
+ **Example**
7024
+ ```js
7025
+ button.onSuccess((event) => {
7026
+ console.log('OTT created:', event.data.token.temp_token);
7027
+ console.log('Amount:', event.data.amount);
7028
+ });
7029
+ ```
7030
+ **Example**
7031
+ ```js
7032
+ // Async handler
7033
+ button.onSuccess(async (event) => {
7034
+ await submitTokenToServer(event.data.token.temp_token);
7035
+ });
7036
+ ```
7037
+ <a name="OpenWalletButtons+onUnavailable" id="OpenWalletButtons+onUnavailable" href="#OpenWalletButtons+onUnavailable">&nbsp;</a>
7038
+
7039
+ ### applePayOpenWalletButton.onUnavailable(handler)
7040
+ Registers a callback function to be invoked when the wallet is not available in the current context.
7041
+ This can happen when the wallet service is not supported on the current device or browser.
7042
+ Both synchronous and asynchronous (async) handlers are supported.
7043
+
7044
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7045
+ so that internal processing continues uninterrupted.
7046
+
7047
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7048
+
7049
+ | Param | Type | Description |
7050
+ | --- | --- | --- |
7051
+ | handler | [<code>OnUnavailableCallback</code>](#OnUnavailableCallback) | Function to be called when the wallet is not available in the current context. |
7052
+
7053
+ **Example**
7054
+ ```js
7055
+ button.onUnavailable((event) => {
7056
+ console.log('Wallet not available:', event.data.reason);
7057
+ });
7058
+ ```
7059
+ <a name="OpenWalletButtons+onError" id="OpenWalletButtons+onError" href="#OpenWalletButtons+onError">&nbsp;</a>
7060
+
7061
+ ### applePayOpenWalletButton.onError(handler)
7062
+ Registers a callback function to be invoked when an error occurs during wallet operation.
7063
+ This includes configuration issues, validation errors, and OTT creation failures.
7064
+ Both synchronous and asynchronous (async) handlers are supported.
7065
+
7066
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7067
+ so that internal processing continues uninterrupted.
7068
+
7069
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7070
+
7071
+ | Param | Type | Description |
7072
+ | --- | --- | --- |
7073
+ | handler | [<code>OnErrorCallback</code>](#OnErrorCallback) | Function to be called when the wallet has an error. |
7074
+
7075
+ **Example**
7076
+ ```js
7077
+ button.onError((event) => {
7078
+ console.error('Wallet error:', event.data.error.message);
7079
+ console.log('Context:', event.data.context);
7080
+ });
7081
+ ```
7082
+ <a name="OpenWalletButtons+onCancel" id="OpenWalletButtons+onCancel" href="#OpenWalletButtons+onCancel">&nbsp;</a>
7083
+
7084
+ ### applePayOpenWalletButton.onCancel(handler)
7085
+ Registers a callback function to be invoked when the wallet checkout is cancelled or closed by the user.
7086
+ This event is triggered when the user dismisses the wallet payment interface without completing the transaction.
7087
+ Both synchronous and asynchronous (async) handlers are supported.
7088
+
7089
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7090
+ so that internal processing continues uninterrupted.
7091
+
7092
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7093
+
7094
+ | Param | Type | Description |
7095
+ | --- | --- | --- |
7096
+ | handler | [<code>OnCancelCallback</code>](#OnCancelCallback) | Function to be called when the wallet checkout is cancelled. |
7097
+
7098
+ **Example**
7099
+ ```js
7100
+ button.onCancel((event) => {
7101
+ console.log('Wallet checkout cancelled', event);
7102
+ });
7103
+ ```
7104
+ <a name="OpenWalletButtons+onLoaded" id="OpenWalletButtons+onLoaded" href="#OpenWalletButtons+onLoaded">&nbsp;</a>
7105
+
7106
+ ### applePayOpenWalletButton.onLoaded(handler)
7107
+ Registers a callback function to be invoked when the wallet button has been loaded and rendered in the DOM.
7108
+ Both synchronous and asynchronous (async) handlers are supported.
7109
+
7110
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7111
+ so that internal processing continues uninterrupted.
7112
+
7113
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7114
+
7115
+ | Param | Type | Description |
7116
+ | --- | --- | --- |
7117
+ | handler | <code>function</code> | Function to be called when the wallet button is loaded. |
7118
+
7119
+ **Example**
7120
+ ```js
7121
+ button.onLoaded((event) => {
7122
+ console.log('Wallet button loaded');
7123
+ });
7124
+ ```
7125
+ <a name="OpenWalletButtons+onShippingAddressChange" id="OpenWalletButtons+onShippingAddressChange" href="#OpenWalletButtons+onShippingAddressChange">&nbsp;</a>
7126
+
7127
+ ### applePayOpenWalletButton.onShippingAddressChange(handler)
7128
+ Registers a callback for when the customer selects or updates their shipping address.
7129
+ Use this method to listen for shipping address selection or input from customer when shipping is enabled.
7130
+ The event handler should return updated payment information including the new amount and
7131
+ available shipping options based on the selected address.
7132
+ Both synchronous and asynchronous (async) handlers are supported.
7133
+
7134
+ In case of an address validation error, include the `error` field in the response
7135
+ to display an appropriate error in the wallet payment sheet.
7136
+
7137
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7138
+
7139
+ | Param | Type | Description |
7140
+ | --- | --- | --- |
7141
+ | handler | [<code>OnShippingAddressChangeCallback</code>](#OnShippingAddressChangeCallback) | Function to be called when the shipping address data is updated. |
7142
+
7143
+ **Example**
7144
+ ```js
7145
+ // Async handler
7146
+ button.onShippingAddressChange(async (data) => {
7147
+ const response = await fetch('https://your-server.com/update-shipping-address', {
7148
+ method: 'POST',
7149
+ body: JSON.stringify(data),
7150
+ });
7151
+ const result = await response.json();
7152
+ return {
7153
+ amount: result.newAmount,
7154
+ shipping_options: result.availableShippingOptions,
7155
+ };
7156
+ });
7157
+ ```
7158
+ **Example**
7159
+ ```js
7160
+ // Sync handler
7161
+ button.onShippingAddressChange((data) => {
7162
+ return {
7163
+ amount: calculateShipping(data.data.address_country),
7164
+ shipping_options: getOptionsForCountry(data.data.address_country),
7165
+ };
7166
+ });
7167
+ ```
7168
+ <a name="OpenWalletButtons+onShippingOptionsChange" id="OpenWalletButtons+onShippingOptionsChange" href="#OpenWalletButtons+onShippingOptionsChange">&nbsp;</a>
7169
+
7170
+ ### applePayOpenWalletButton.onShippingOptionsChange(handler)
7171
+ Registers a callback for when the customer selects a shipping option.
7172
+ Use this method to listen for shipping option selection from customer when shipping is enabled.
7173
+ The event handler should return the updated payment amount based on the selected shipping option.
7174
+ Both synchronous and asynchronous (async) handlers are supported.
7175
+
7176
+ **Kind**: instance method of [<code>ApplePayOpenWalletButton</code>](#ApplePayOpenWalletButton)
7177
+
7178
+ | Param | Type | Description |
7179
+ | --- | --- | --- |
7180
+ | handler | [<code>OnShippingOptionsChangeCallback</code>](#OnShippingOptionsChangeCallback) | Function to be called when the shipping options data is updated. |
7181
+
7182
+ **Example**
7183
+ ```js
7184
+ // Async handler
7185
+ button.onShippingOptionsChange(async (data) => {
7186
+ const response = await fetch('https://your-server.com/update-shipping-option', {
7187
+ method: 'POST',
7188
+ body: JSON.stringify({ shipping_option_id: data.data.shipping_option_id }),
7189
+ });
7190
+ const result = await response.json();
7191
+ return {
7192
+ amount: result.newTotalAmount,
7193
+ };
7194
+ });
7195
+ ```
7196
+ **Example**
7197
+ ```js
7198
+ // Sync handler
7199
+ button.onShippingOptionsChange((data) => {
7200
+ return {
7201
+ amount: lookupShippingCost(data.data.shipping_option_id),
7202
+ };
7203
+ });
7204
+ ```
7205
+ <a name="GooglePayOpenWalletButton" id="GooglePayOpenWalletButton" href="#GooglePayOpenWalletButton">&nbsp;</a>
7206
+
7207
+ ## GooglePayOpenWalletButton ⇐ [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7208
+ Google Pay wallet button that creates One-Time Tokens (OTT) via Google Pay.
7209
+
7210
+ Provides a fully typed Google Pay integration with Google Pay-specific metadata
7211
+ and validates that the service configuration corresponds to a Google Pay service.
7212
+ On `load()`, the button fetches the service configuration and raises an error via `onError`
7213
+ if the service type does not match Google Pay.
7214
+
7215
+ **Kind**: global class
7216
+ **Extends**: [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7217
+
7218
+ * [GooglePayOpenWalletButton](#GooglePayOpenWalletButton) ⇐ [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7219
+ * [new GooglePayOpenWalletButton(selector, publicKeyOrAccessToken, serviceId, meta)](#new_GooglePayOpenWalletButton_new)
7220
+ * [.load()](#OpenWalletButtons+load)
7221
+ * [.setEnv(env, [alias])](#OpenWalletButtons+setEnv)
7222
+ * [.setMeta(meta)](#OpenWalletButtons+setMeta)
7223
+ * [.destroy()](#OpenWalletButtons+destroy)
7224
+ * [.onClick(handler)](#OpenWalletButtons+onClick)
7225
+ * [.onSuccess(handler)](#OpenWalletButtons+onSuccess)
7226
+ * [.onUnavailable(handler)](#OpenWalletButtons+onUnavailable)
7227
+ * [.onError(handler)](#OpenWalletButtons+onError)
7228
+ * [.onCancel(handler)](#OpenWalletButtons+onCancel)
7229
+ * [.onLoaded(handler)](#OpenWalletButtons+onLoaded)
7230
+ * [.onShippingAddressChange(handler)](#OpenWalletButtons+onShippingAddressChange)
7231
+ * [.onShippingOptionsChange(handler)](#OpenWalletButtons+onShippingOptionsChange)
7232
+
7233
+ <a name="new_GooglePayOpenWalletButton_new" id="new_GooglePayOpenWalletButton_new" href="#new_GooglePayOpenWalletButton_new">&nbsp;</a>
7234
+
7235
+ ### new GooglePayOpenWalletButton(selector, publicKeyOrAccessToken, serviceId, meta)
7236
+
7237
+ | Param | Type | Description |
7238
+ | --- | --- | --- |
7239
+ | selector | <code>string</code> | CSS selector of the HTML element that will contain the Google Pay button. |
7240
+ | publicKeyOrAccessToken | <code>string</code> | Public key or access token for API authentication. |
7241
+ | serviceId | <code>string</code> | The Google Pay service ID configured in PayDock dashboard. |
7242
+ | meta | [<code>GooglePayOpenWalletMeta</code>](#GooglePayOpenWalletMeta) | Google Pay-specific metadata (amount, currency, country, card_config, merchant_name, style, etc.). |
7243
+
7244
+ **Example**
7245
+ ```js
7246
+ const button = new GooglePayOpenWalletButton(
7247
+ '#wallet-container',
7248
+ publicKeyOrAccessToken,
7249
+ serviceId,
7250
+ {
7251
+ amount: 100,
7252
+ currency: 'AUD',
7253
+ country: 'AU',
7254
+ merchant_name: 'Your Store',
7255
+ },
7256
+ );
7257
+ button.setEnv('sandbox');
7258
+ button.onSuccess((data) => console.log('OTT:', data.token));
7259
+ button.onError((error) => console.error('Error:', error));
7260
+ button.load();
7261
+ ```
7262
+ <a name="OpenWalletButtons+load" id="OpenWalletButtons+load" href="#OpenWalletButtons+load">&nbsp;</a>
7263
+
7264
+ ### googlePayOpenWalletButton.load()
7265
+ Loads and initializes the wallet button based on the service configuration.
7266
+ This method fetches the wallet service configuration, validates that the service
7267
+ type matches the expected wallet, and creates the appropriate wallet service instance.
7268
+ Bear in mind that you must call this method after setting up all event handlers.
7269
+
7270
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7271
+ **Example**
7272
+ ```js
7273
+ button.onClick((data) => { ... });
7274
+ button.onSuccess((data) => { ... });
7275
+ button.onError((error) => { ... });
7276
+ button.load();
7277
+ ```
7278
+ <a name="OpenWalletButtons+setEnv" id="OpenWalletButtons+setEnv" href="#OpenWalletButtons+setEnv">&nbsp;</a>
7279
+
7280
+ ### googlePayOpenWalletButton.setEnv(env, [alias])
7281
+ Current method can change environment. By default environment = sandbox.
7282
+ Also we can change domain alias for this environment. By default domain_alias = paydock.com
7283
+ Bear in mind that you must set an environment before calling `button.load()`.
7284
+
7285
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7286
+
7287
+ | Param | Type | Description |
7288
+ | --- | --- | --- |
7289
+ | env | <code>string</code> | The target environment: `'sandbox'` or `'production'`. |
7290
+ | [alias] | <code>string</code> | Own domain alias. |
7291
+
7292
+ **Example**
7293
+ ```js
7294
+ button.setEnv('production', 'paydock.com');
7295
+ ```
7296
+ <a name="OpenWalletButtons+setMeta" id="OpenWalletButtons+setMeta" href="#OpenWalletButtons+setMeta">&nbsp;</a>
7297
+
7298
+ ### googlePayOpenWalletButton.setMeta(meta)
7299
+ Updates the wallet metadata after initialization.
7300
+ Use this when order information changes (e.g. amount, currency) after the button has been rendered.
7301
+ Bear in mind that this must be called before the next payment attempt takes effect.
7302
+
7303
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7304
+
7305
+ | Param | Type | Description |
7306
+ | --- | --- | --- |
7307
+ | meta | [<code>ApplePayOpenWalletMeta</code>](#ApplePayOpenWalletMeta) \| [<code>GooglePayOpenWalletMeta</code>](#GooglePayOpenWalletMeta) | The updated metadata object. The concrete type depends on the button class. |
7308
+
7309
+ **Example**
7310
+ ```js
7311
+ button.setMeta({ ...meta, amount: 29.99 });
7312
+ ```
7313
+ <a name="OpenWalletButtons+destroy" id="OpenWalletButtons+destroy" href="#OpenWalletButtons+destroy">&nbsp;</a>
7314
+
7315
+ ### googlePayOpenWalletButton.destroy()
7316
+ Removes the wallet button from the DOM and cleans up resources.
7317
+ Call this method when the wallet button is no longer needed (e.g. navigating away from the payment page).
7318
+
7319
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7320
+ **Example**
7321
+ ```js
7322
+ button.destroy();
7323
+ ```
7324
+ <a name="OpenWalletButtons+onClick" id="OpenWalletButtons+onClick" href="#OpenWalletButtons+onClick">&nbsp;</a>
7325
+
7326
+ ### googlePayOpenWalletButton.onClick(handler)
7327
+ Registers a callback function to be invoked when the wallet button gets clicked.
7328
+ The handler controls the wallet payment flow via its return value:
7329
+
7330
+ - Return `void` (or nothing) to continue the payment flow normally.
7331
+ - Return `false` to abort the payment flow.
7332
+ - Return a `Promise<void>` to defer the wallet sheet until the promise resolves.
7333
+ - Return a `Promise<boolean>` — if it resolves to `false`, the flow is aborted.
7334
+ - Throwing an error (sync or async) also aborts the flow.
7335
+
7336
+ Both synchronous and asynchronous (async) handlers are supported.
7337
+
7338
+ **Note:** this callback may be called multiple times as the customer closes the payment
7339
+ checkout and re-clicks the button.
7340
+
7341
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7342
+
7343
+ | Param | Type | Description |
7344
+ | --- | --- | --- |
7345
+ | handler | [<code>OnClickCallback</code>](#OnClickCallback) | Function to be called when the wallet button is clicked. |
7346
+
7347
+ **Example**
7348
+ ```js
7349
+ // Synchronous usage — continue normally
7350
+ button.onClick((event) => {
7351
+ performValidationLogic();
7352
+ });
7353
+ ```
7354
+ **Example**
7355
+ ```js
7356
+ // Synchronous abort — return false to cancel the payment
7357
+ button.onClick((event) => {
7358
+ if (!isOrderValid()) return false;
7359
+ });
7360
+ ```
7361
+ **Example**
7362
+ ```js
7363
+ // Asynchronous usage — defer wallet sheet until the promise resolves
7364
+ button.onClick(async (event) => {
7365
+ await fetch('/validate-order').then(res => res.json());
7366
+ });
7367
+ ```
7368
+ <a name="OpenWalletButtons+onSuccess" id="OpenWalletButtons+onSuccess" href="#OpenWalletButtons+onSuccess">&nbsp;</a>
7369
+
7370
+ ### googlePayOpenWalletButton.onSuccess(handler)
7371
+ Registers a callback function to be invoked when the OTT (One-Time Token) creation was successful.
7372
+ Both synchronous and asynchronous (async) handlers are supported.
7373
+
7374
+ **Important:** A handler is required. Do not perform thread blocking operations in callback such as `window.alert()` calls.
7375
+
7376
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7377
+ so that internal processing continues uninterrupted.
7378
+
7379
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7380
+
7381
+ | Param | Type | Description |
7382
+ | --- | --- | --- |
7383
+ | handler | [<code>OnSuccessCallback</code>](#OnSuccessCallback) | Function to be called when the OTT creation was successful. |
7384
+
7385
+ **Example**
7386
+ ```js
7387
+ button.onSuccess((event) => {
7388
+ console.log('OTT created:', event.data.token.temp_token);
7389
+ console.log('Amount:', event.data.amount);
7390
+ });
7391
+ ```
7392
+ **Example**
7393
+ ```js
7394
+ // Async handler
7395
+ button.onSuccess(async (event) => {
7396
+ await submitTokenToServer(event.data.token.temp_token);
7397
+ });
7398
+ ```
7399
+ <a name="OpenWalletButtons+onUnavailable" id="OpenWalletButtons+onUnavailable" href="#OpenWalletButtons+onUnavailable">&nbsp;</a>
7400
+
7401
+ ### googlePayOpenWalletButton.onUnavailable(handler)
7402
+ Registers a callback function to be invoked when the wallet is not available in the current context.
7403
+ This can happen when the wallet service is not supported on the current device or browser.
7404
+ Both synchronous and asynchronous (async) handlers are supported.
7405
+
7406
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7407
+ so that internal processing continues uninterrupted.
7408
+
7409
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7410
+
7411
+ | Param | Type | Description |
7412
+ | --- | --- | --- |
7413
+ | handler | [<code>OnUnavailableCallback</code>](#OnUnavailableCallback) | Function to be called when the wallet is not available in the current context. |
7414
+
7415
+ **Example**
7416
+ ```js
7417
+ button.onUnavailable((event) => {
7418
+ console.log('Wallet not available:', event.data.reason);
7419
+ });
7420
+ ```
7421
+ <a name="OpenWalletButtons+onError" id="OpenWalletButtons+onError" href="#OpenWalletButtons+onError">&nbsp;</a>
7422
+
7423
+ ### googlePayOpenWalletButton.onError(handler)
7424
+ Registers a callback function to be invoked when an error occurs during wallet operation.
7425
+ This includes configuration issues, validation errors, and OTT creation failures.
7426
+ Both synchronous and asynchronous (async) handlers are supported.
7427
+
7428
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7429
+ so that internal processing continues uninterrupted.
7430
+
7431
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7432
+
7433
+ | Param | Type | Description |
7434
+ | --- | --- | --- |
7435
+ | handler | [<code>OnErrorCallback</code>](#OnErrorCallback) | Function to be called when the wallet has an error. |
7436
+
7437
+ **Example**
7438
+ ```js
7439
+ button.onError((event) => {
7440
+ console.error('Wallet error:', event.data.error.message);
7441
+ console.log('Context:', event.data.context);
7442
+ });
7443
+ ```
7444
+ <a name="OpenWalletButtons+onCancel" id="OpenWalletButtons+onCancel" href="#OpenWalletButtons+onCancel">&nbsp;</a>
7445
+
7446
+ ### googlePayOpenWalletButton.onCancel(handler)
7447
+ Registers a callback function to be invoked when the wallet checkout is cancelled or closed by the user.
7448
+ This event is triggered when the user dismisses the wallet payment interface without completing the transaction.
7449
+ Both synchronous and asynchronous (async) handlers are supported.
7450
+
7451
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7452
+ so that internal processing continues uninterrupted.
7453
+
7454
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7455
+
7456
+ | Param | Type | Description |
7457
+ | --- | --- | --- |
7458
+ | handler | [<code>OnCancelCallback</code>](#OnCancelCallback) | Function to be called when the wallet checkout is cancelled. |
7459
+
7460
+ **Example**
7461
+ ```js
7462
+ button.onCancel((event) => {
7463
+ console.log('Wallet checkout cancelled', event);
7464
+ });
7465
+ ```
7466
+ <a name="OpenWalletButtons+onLoaded" id="OpenWalletButtons+onLoaded" href="#OpenWalletButtons+onLoaded">&nbsp;</a>
7467
+
7468
+ ### googlePayOpenWalletButton.onLoaded(handler)
7469
+ Registers a callback function to be invoked when the wallet button has been loaded and rendered in the DOM.
7470
+ Both synchronous and asynchronous (async) handlers are supported.
7471
+
7472
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7473
+ so that internal processing continues uninterrupted.
7474
+
7475
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7476
+
7477
+ | Param | Type | Description |
7478
+ | --- | --- | --- |
7479
+ | handler | <code>function</code> | Function to be called when the wallet button is loaded. |
7480
+
7481
+ **Example**
7482
+ ```js
7483
+ button.onLoaded((event) => {
7484
+ console.log('Wallet button loaded');
7485
+ });
7486
+ ```
7487
+ <a name="OpenWalletButtons+onShippingAddressChange" id="OpenWalletButtons+onShippingAddressChange" href="#OpenWalletButtons+onShippingAddressChange">&nbsp;</a>
7488
+
7489
+ ### googlePayOpenWalletButton.onShippingAddressChange(handler)
7490
+ Registers a callback for when the customer selects or updates their shipping address.
7491
+ Use this method to listen for shipping address selection or input from customer when shipping is enabled.
7492
+ The event handler should return updated payment information including the new amount and
7493
+ available shipping options based on the selected address.
7494
+ Both synchronous and asynchronous (async) handlers are supported.
7495
+
7496
+ In case of an address validation error, include the `error` field in the response
7497
+ to display an appropriate error in the wallet payment sheet.
7498
+
7499
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7500
+
7501
+ | Param | Type | Description |
7502
+ | --- | --- | --- |
7503
+ | handler | [<code>OnShippingAddressChangeCallback</code>](#OnShippingAddressChangeCallback) | Function to be called when the shipping address data is updated. |
7504
+
7505
+ **Example**
7506
+ ```js
7507
+ // Async handler
7508
+ button.onShippingAddressChange(async (data) => {
7509
+ const response = await fetch('https://your-server.com/update-shipping-address', {
7510
+ method: 'POST',
7511
+ body: JSON.stringify(data),
7512
+ });
7513
+ const result = await response.json();
7514
+ return {
7515
+ amount: result.newAmount,
7516
+ shipping_options: result.availableShippingOptions,
7517
+ };
7518
+ });
7519
+ ```
7520
+ **Example**
7521
+ ```js
7522
+ // Sync handler
7523
+ button.onShippingAddressChange((data) => {
7524
+ return {
7525
+ amount: calculateShipping(data.data.address_country),
7526
+ shipping_options: getOptionsForCountry(data.data.address_country),
7527
+ };
7528
+ });
7529
+ ```
7530
+ <a name="OpenWalletButtons+onShippingOptionsChange" id="OpenWalletButtons+onShippingOptionsChange" href="#OpenWalletButtons+onShippingOptionsChange">&nbsp;</a>
7531
+
7532
+ ### googlePayOpenWalletButton.onShippingOptionsChange(handler)
7533
+ Registers a callback for when the customer selects a shipping option.
7534
+ Use this method to listen for shipping option selection from customer when shipping is enabled.
7535
+ The event handler should return the updated payment amount based on the selected shipping option.
7536
+ Both synchronous and asynchronous (async) handlers are supported.
7537
+
7538
+ **Kind**: instance method of [<code>GooglePayOpenWalletButton</code>](#GooglePayOpenWalletButton)
7539
+
7540
+ | Param | Type | Description |
7541
+ | --- | --- | --- |
7542
+ | handler | [<code>OnShippingOptionsChangeCallback</code>](#OnShippingOptionsChangeCallback) | Function to be called when the shipping options data is updated. |
7543
+
7544
+ **Example**
7545
+ ```js
7546
+ // Async handler
7547
+ button.onShippingOptionsChange(async (data) => {
7548
+ const response = await fetch('https://your-server.com/update-shipping-option', {
7549
+ method: 'POST',
7550
+ body: JSON.stringify({ shipping_option_id: data.data.shipping_option_id }),
7551
+ });
7552
+ const result = await response.json();
7553
+ return {
7554
+ amount: result.newTotalAmount,
7555
+ };
7556
+ });
7557
+ ```
7558
+ **Example**
7559
+ ```js
7560
+ // Sync handler
7561
+ button.onShippingOptionsChange((data) => {
7562
+ return {
7563
+ amount: lookupShippingCost(data.data.shipping_option_id),
7564
+ };
7565
+ });
7566
+ ```
7567
+ <a name="OpenWalletButtons" id="OpenWalletButtons" href="#OpenWalletButtons">&nbsp;</a>
7568
+
7569
+ ## *OpenWalletButtons*
7570
+ Abstract base class for Open Wallet buttons. **Do not instantiate directly.**
7571
+ Use [ApplePayOpenWalletButton](#ApplePayOpenWalletButton) or [GooglePayOpenWalletButton](#GooglePayOpenWalletButton) instead.
7572
+
7573
+ Use one of the concrete implementations instead:
7574
+ - [ApplePayOpenWalletButton](#ApplePayOpenWalletButton) for Apple Pay integration
7575
+ - [GooglePayOpenWalletButton](#GooglePayOpenWalletButton) for Google Pay integration
7576
+
7577
+ These subclasses inherit all event handlers and lifecycle methods documented below.
7578
+
7579
+ **Kind**: global abstract class
7580
+
7581
+ * *[OpenWalletButtons](#OpenWalletButtons)*
7582
+ * *[.load()](#OpenWalletButtons+load)*
7583
+ * *[.setEnv(env, [alias])](#OpenWalletButtons+setEnv)*
7584
+ * *[.setMeta(meta)](#OpenWalletButtons+setMeta)*
7585
+ * *[.destroy()](#OpenWalletButtons+destroy)*
7586
+ * *[.onClick(handler)](#OpenWalletButtons+onClick)*
7587
+ * *[.onSuccess(handler)](#OpenWalletButtons+onSuccess)*
7588
+ * *[.onUnavailable(handler)](#OpenWalletButtons+onUnavailable)*
7589
+ * *[.onError(handler)](#OpenWalletButtons+onError)*
7590
+ * *[.onCancel(handler)](#OpenWalletButtons+onCancel)*
7591
+ * *[.onLoaded(handler)](#OpenWalletButtons+onLoaded)*
7592
+ * *[.onShippingAddressChange(handler)](#OpenWalletButtons+onShippingAddressChange)*
7593
+ * *[.onShippingOptionsChange(handler)](#OpenWalletButtons+onShippingOptionsChange)*
7594
+
7595
+ <a name="OpenWalletButtons+load" id="OpenWalletButtons+load" href="#OpenWalletButtons+load">&nbsp;</a>
7596
+
7597
+ ### *openWalletButtons.load()*
7598
+ Loads and initializes the wallet button based on the service configuration.
7599
+ This method fetches the wallet service configuration, validates that the service
7600
+ type matches the expected wallet, and creates the appropriate wallet service instance.
7601
+ Bear in mind that you must call this method after setting up all event handlers.
7602
+
7603
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7604
+ **Example**
7605
+ ```js
7606
+ button.onClick((data) => { ... });
7607
+ button.onSuccess((data) => { ... });
7608
+ button.onError((error) => { ... });
7609
+ button.load();
7610
+ ```
7611
+ <a name="OpenWalletButtons+setEnv" id="OpenWalletButtons+setEnv" href="#OpenWalletButtons+setEnv">&nbsp;</a>
7612
+
7613
+ ### *openWalletButtons.setEnv(env, [alias])*
7614
+ Current method can change environment. By default environment = sandbox.
7615
+ Also we can change domain alias for this environment. By default domain_alias = paydock.com
7616
+ Bear in mind that you must set an environment before calling `button.load()`.
7617
+
7618
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7619
+
7620
+ | Param | Type | Description |
7621
+ | --- | --- | --- |
7622
+ | env | <code>string</code> | The target environment: `'sandbox'` or `'production'`. |
7623
+ | [alias] | <code>string</code> | Own domain alias. |
7624
+
7625
+ **Example**
7626
+ ```js
7627
+ button.setEnv('production', 'paydock.com');
7628
+ ```
7629
+ <a name="OpenWalletButtons+setMeta" id="OpenWalletButtons+setMeta" href="#OpenWalletButtons+setMeta">&nbsp;</a>
7630
+
7631
+ ### *openWalletButtons.setMeta(meta)*
7632
+ Updates the wallet metadata after initialization.
7633
+ Use this when order information changes (e.g. amount, currency) after the button has been rendered.
7634
+ Bear in mind that this must be called before the next payment attempt takes effect.
7635
+
7636
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7637
+
7638
+ | Param | Type | Description |
7639
+ | --- | --- | --- |
7640
+ | meta | [<code>ApplePayOpenWalletMeta</code>](#ApplePayOpenWalletMeta) \| [<code>GooglePayOpenWalletMeta</code>](#GooglePayOpenWalletMeta) | The updated metadata object. The concrete type depends on the button class. |
7641
+
7642
+ **Example**
7643
+ ```js
7644
+ button.setMeta({ ...meta, amount: 29.99 });
7645
+ ```
7646
+ <a name="OpenWalletButtons+destroy" id="OpenWalletButtons+destroy" href="#OpenWalletButtons+destroy">&nbsp;</a>
7647
+
7648
+ ### *openWalletButtons.destroy()*
7649
+ Removes the wallet button from the DOM and cleans up resources.
7650
+ Call this method when the wallet button is no longer needed (e.g. navigating away from the payment page).
7651
+
7652
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7653
+ **Example**
7654
+ ```js
7655
+ button.destroy();
7656
+ ```
7657
+ <a name="OpenWalletButtons+onClick" id="OpenWalletButtons+onClick" href="#OpenWalletButtons+onClick">&nbsp;</a>
7658
+
7659
+ ### *openWalletButtons.onClick(handler)*
7660
+ Registers a callback function to be invoked when the wallet button gets clicked.
7661
+ The handler controls the wallet payment flow via its return value:
7662
+
7663
+ - Return `void` (or nothing) to continue the payment flow normally.
7664
+ - Return `false` to abort the payment flow.
7665
+ - Return a `Promise<void>` to defer the wallet sheet until the promise resolves.
7666
+ - Return a `Promise<boolean>` — if it resolves to `false`, the flow is aborted.
7667
+ - Throwing an error (sync or async) also aborts the flow.
7668
+
7669
+ Both synchronous and asynchronous (async) handlers are supported.
7670
+
7671
+ **Note:** this callback may be called multiple times as the customer closes the payment
7672
+ checkout and re-clicks the button.
7673
+
7674
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7675
+
7676
+ | Param | Type | Description |
7677
+ | --- | --- | --- |
7678
+ | handler | [<code>OnClickCallback</code>](#OnClickCallback) | Function to be called when the wallet button is clicked. |
7679
+
7680
+ **Example**
7681
+ ```js
7682
+ // Synchronous usage — continue normally
7683
+ button.onClick((event) => {
7684
+ performValidationLogic();
7685
+ });
7686
+ ```
7687
+ **Example**
7688
+ ```js
7689
+ // Synchronous abort — return false to cancel the payment
7690
+ button.onClick((event) => {
7691
+ if (!isOrderValid()) return false;
7692
+ });
7693
+ ```
7694
+ **Example**
7695
+ ```js
7696
+ // Asynchronous usage — defer wallet sheet until the promise resolves
7697
+ button.onClick(async (event) => {
7698
+ await fetch('/validate-order').then(res => res.json());
7699
+ });
7700
+ ```
7701
+ <a name="OpenWalletButtons+onSuccess" id="OpenWalletButtons+onSuccess" href="#OpenWalletButtons+onSuccess">&nbsp;</a>
7702
+
7703
+ ### *openWalletButtons.onSuccess(handler)*
7704
+ Registers a callback function to be invoked when the OTT (One-Time Token) creation was successful.
7705
+ Both synchronous and asynchronous (async) handlers are supported.
7706
+
7707
+ **Important:** A handler is required. Do not perform thread blocking operations in callback such as `window.alert()` calls.
7708
+
7709
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7710
+ so that internal processing continues uninterrupted.
7711
+
7712
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7713
+
7714
+ | Param | Type | Description |
7715
+ | --- | --- | --- |
7716
+ | handler | [<code>OnSuccessCallback</code>](#OnSuccessCallback) | Function to be called when the OTT creation was successful. |
7717
+
7718
+ **Example**
7719
+ ```js
7720
+ button.onSuccess((event) => {
7721
+ console.log('OTT created:', event.data.token.temp_token);
7722
+ console.log('Amount:', event.data.amount);
7723
+ });
7724
+ ```
7725
+ **Example**
7726
+ ```js
7727
+ // Async handler
7728
+ button.onSuccess(async (event) => {
7729
+ await submitTokenToServer(event.data.token.temp_token);
7730
+ });
7731
+ ```
7732
+ <a name="OpenWalletButtons+onUnavailable" id="OpenWalletButtons+onUnavailable" href="#OpenWalletButtons+onUnavailable">&nbsp;</a>
7733
+
7734
+ ### *openWalletButtons.onUnavailable(handler)*
7735
+ Registers a callback function to be invoked when the wallet is not available in the current context.
7736
+ This can happen when the wallet service is not supported on the current device or browser.
7737
+ Both synchronous and asynchronous (async) handlers are supported.
7738
+
7739
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7740
+ so that internal processing continues uninterrupted.
7741
+
7742
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7743
+
7744
+ | Param | Type | Description |
7745
+ | --- | --- | --- |
7746
+ | handler | [<code>OnUnavailableCallback</code>](#OnUnavailableCallback) | Function to be called when the wallet is not available in the current context. |
7747
+
7748
+ **Example**
7749
+ ```js
7750
+ button.onUnavailable((event) => {
7751
+ console.log('Wallet not available:', event.data.reason);
7752
+ });
7753
+ ```
7754
+ <a name="OpenWalletButtons+onError" id="OpenWalletButtons+onError" href="#OpenWalletButtons+onError">&nbsp;</a>
7755
+
7756
+ ### *openWalletButtons.onError(handler)*
7757
+ Registers a callback function to be invoked when an error occurs during wallet operation.
7758
+ This includes configuration issues, validation errors, and OTT creation failures.
7759
+ Both synchronous and asynchronous (async) handlers are supported.
7760
+
7761
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7762
+ so that internal processing continues uninterrupted.
7763
+
7764
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7765
+
7766
+ | Param | Type | Description |
7767
+ | --- | --- | --- |
7768
+ | handler | [<code>OnErrorCallback</code>](#OnErrorCallback) | Function to be called when the wallet has an error. |
7769
+
7770
+ **Example**
7771
+ ```js
7772
+ button.onError((event) => {
7773
+ console.error('Wallet error:', event.data.error.message);
7774
+ console.log('Context:', event.data.context);
7775
+ });
7776
+ ```
7777
+ <a name="OpenWalletButtons+onCancel" id="OpenWalletButtons+onCancel" href="#OpenWalletButtons+onCancel">&nbsp;</a>
7778
+
7779
+ ### *openWalletButtons.onCancel(handler)*
7780
+ Registers a callback function to be invoked when the wallet checkout is cancelled or closed by the user.
7781
+ This event is triggered when the user dismisses the wallet payment interface without completing the transaction.
7782
+ Both synchronous and asynchronous (async) handlers are supported.
7783
+
7784
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7785
+ so that internal processing continues uninterrupted.
7786
+
7787
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7788
+
7789
+ | Param | Type | Description |
7790
+ | --- | --- | --- |
7791
+ | handler | [<code>OnCancelCallback</code>](#OnCancelCallback) | Function to be called when the wallet checkout is cancelled. |
7792
+
7793
+ **Example**
7794
+ ```js
7795
+ button.onCancel((event) => {
7796
+ console.log('Wallet checkout cancelled', event);
7797
+ });
7798
+ ```
7799
+ <a name="OpenWalletButtons+onLoaded" id="OpenWalletButtons+onLoaded" href="#OpenWalletButtons+onLoaded">&nbsp;</a>
7800
+
7801
+ ### *openWalletButtons.onLoaded(handler)*
7802
+ Registers a callback function to be invoked when the wallet button has been loaded and rendered in the DOM.
7803
+ Both synchronous and asynchronous (async) handlers are supported.
7804
+
7805
+ **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
7806
+ so that internal processing continues uninterrupted.
7807
+
7808
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7809
+
7810
+ | Param | Type | Description |
7811
+ | --- | --- | --- |
7812
+ | handler | <code>function</code> | Function to be called when the wallet button is loaded. |
7813
+
7814
+ **Example**
7815
+ ```js
7816
+ button.onLoaded((event) => {
7817
+ console.log('Wallet button loaded');
7818
+ });
7819
+ ```
7820
+ <a name="OpenWalletButtons+onShippingAddressChange" id="OpenWalletButtons+onShippingAddressChange" href="#OpenWalletButtons+onShippingAddressChange">&nbsp;</a>
7821
+
7822
+ ### *openWalletButtons.onShippingAddressChange(handler)*
7823
+ Registers a callback for when the customer selects or updates their shipping address.
7824
+ Use this method to listen for shipping address selection or input from customer when shipping is enabled.
7825
+ The event handler should return updated payment information including the new amount and
7826
+ available shipping options based on the selected address.
7827
+ Both synchronous and asynchronous (async) handlers are supported.
7828
+
7829
+ In case of an address validation error, include the `error` field in the response
7830
+ to display an appropriate error in the wallet payment sheet.
7831
+
7832
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7833
+
7834
+ | Param | Type | Description |
7835
+ | --- | --- | --- |
7836
+ | handler | [<code>OnShippingAddressChangeCallback</code>](#OnShippingAddressChangeCallback) | Function to be called when the shipping address data is updated. |
7837
+
7838
+ **Example**
7839
+ ```js
7840
+ // Async handler
7841
+ button.onShippingAddressChange(async (data) => {
7842
+ const response = await fetch('https://your-server.com/update-shipping-address', {
7843
+ method: 'POST',
7844
+ body: JSON.stringify(data),
7845
+ });
7846
+ const result = await response.json();
7847
+ return {
7848
+ amount: result.newAmount,
7849
+ shipping_options: result.availableShippingOptions,
7850
+ };
7851
+ });
7852
+ ```
7853
+ **Example**
7854
+ ```js
7855
+ // Sync handler
7856
+ button.onShippingAddressChange((data) => {
7857
+ return {
7858
+ amount: calculateShipping(data.data.address_country),
7859
+ shipping_options: getOptionsForCountry(data.data.address_country),
7860
+ };
7861
+ });
7862
+ ```
7863
+ <a name="OpenWalletButtons+onShippingOptionsChange" id="OpenWalletButtons+onShippingOptionsChange" href="#OpenWalletButtons+onShippingOptionsChange">&nbsp;</a>
7864
+
7865
+ ### *openWalletButtons.onShippingOptionsChange(handler)*
7866
+ Registers a callback for when the customer selects a shipping option.
7867
+ Use this method to listen for shipping option selection from customer when shipping is enabled.
7868
+ The event handler should return the updated payment amount based on the selected shipping option.
7869
+ Both synchronous and asynchronous (async) handlers are supported.
7870
+
7871
+ **Kind**: instance method of [<code>OpenWalletButtons</code>](#OpenWalletButtons)
7872
+
7873
+ | Param | Type | Description |
7874
+ | --- | --- | --- |
7875
+ | handler | [<code>OnShippingOptionsChangeCallback</code>](#OnShippingOptionsChangeCallback) | Function to be called when the shipping options data is updated. |
7876
+
7877
+ **Example**
7878
+ ```js
7879
+ // Async handler
7880
+ button.onShippingOptionsChange(async (data) => {
7881
+ const response = await fetch('https://your-server.com/update-shipping-option', {
7882
+ method: 'POST',
7883
+ body: JSON.stringify({ shipping_option_id: data.data.shipping_option_id }),
7884
+ });
7885
+ const result = await response.json();
7886
+ return {
7887
+ amount: result.newTotalAmount,
7888
+ };
7889
+ });
7890
+ ```
7891
+ **Example**
7892
+ ```js
7893
+ // Sync handler
7894
+ button.onShippingOptionsChange((data) => {
7895
+ return {
7896
+ amount: lookupShippingCost(data.data.shipping_option_id),
7897
+ };
7898
+ });
7899
+ ```
7900
+ <a name="EVENT" id="EVENT" href="#EVENT">&nbsp;</a>
7901
+
7902
+ ## EVENT : <code>object</code>
7903
+ List of available event names in the Open Wallet button lifecycle.
7904
+
7905
+ **Kind**: global constant
7906
+
7907
+ | Param | Type | Default | Description |
7908
+ | --- | --- | --- | --- |
7909
+ | ON_CLICK | <code>string</code> | <code>&quot;onClick&quot;</code> | Emitted when the wallet button is clicked. |
7910
+ | SUCCESS | <code>string</code> | <code>&quot;success&quot;</code> | Emitted when OTT creation succeeds. |
7911
+ | UNAVAILABLE | <code>string</code> | <code>&quot;unavailable&quot;</code> | Emitted when the wallet is not available. |
7912
+ | ERROR | <code>string</code> | <code>&quot;error&quot;</code> | Emitted when an error occurs. |
7913
+ | LOADED | <code>string</code> | <code>&quot;loaded&quot;</code> | Emitted when the button is rendered. |
7914
+ | CHECKOUT_CLOSE | <code>string</code> | <code>&quot;checkoutClose&quot;</code> | Emitted when the wallet checkout is cancelled. |
7915
+ | ON_SHIPPING_ADDRESS_CHANGE | <code>string</code> | <code>&quot;onShippingAddressChange&quot;</code> | Emitted when shipping address changes. |
7916
+ | ON_SHIPPING_OPTIONS_CHANGE | <code>string</code> | <code>&quot;onShippingOptionsChange&quot;</code> | Emitted when shipping option changes. |
7917
+
7918
+ <a name="WALLET_TYPES" id="WALLET_TYPES" href="#WALLET_TYPES">&nbsp;</a>
7919
+
7920
+ ## WALLET\_TYPES : <code>object</code>
7921
+ Enum of available wallet types.
7922
+
7923
+ **Kind**: global constant
7924
+
7925
+ | Param | Type | Default | Description |
7926
+ | --- | --- | --- | --- |
7927
+ | APPLE_PAY | <code>string</code> | <code>&quot;apple&quot;</code> | Apple Pay wallet. |
7928
+ | GOOGLE_PAY | <code>string</code> | <code>&quot;google&quot;</code> | Google Pay wallet. |
7929
+
7930
+ <a name="TOKEN_TYPE" id="TOKEN_TYPE" href="#TOKEN_TYPE">&nbsp;</a>
7931
+
7932
+ ## TOKEN\_TYPE : <code>object</code>
7933
+ Token types returned in the OTT (One-Time Token) creation response.
7934
+
7935
+ **Kind**: global constant
7936
+
7937
+ | Param | Type | Default | Description |
7938
+ | --- | --- | --- | --- |
7939
+ | CARD | <code>string</code> | <code>&quot;card&quot;</code> | FPAN (Funding Primary Account Number). Available for Google Pay only. |
7940
+ | CARD_SCHEME_TOKEN | <code>string</code> | <code>&quot;card_scheme_token&quot;</code> | DPAN (Device Primary Account Number). Available for both Apple Pay and Google Pay. |
7941
+
7942
+ <a name="ERROR_OPERATION" id="ERROR_OPERATION" href="#ERROR_OPERATION">&nbsp;</a>
7943
+
7944
+ ## ERROR\_OPERATION : <code>object</code>
7945
+ Operations that can fail during the wallet lifecycle.
7946
+ Used in the `context.operation` field of [OnErrorEventData](#OnErrorEventData).
7947
+
7948
+ **Kind**: global constant
7949
+
7950
+ | Param | Type | Default | Description |
7951
+ | --- | --- | --- | --- |
7952
+ | WALLET_OPERATION | <code>string</code> | <code>&quot;wallet_operation&quot;</code> | General wallet lifecycle operation (default). |
7953
+ | CONFIGURATION | <code>string</code> | <code>&quot;configuration&quot;</code> | Loading or validating the wallet service configuration (e.g. network fetch failure, card config validation). |
7954
+ | HANDLER_REGISTRATION | <code>string</code> | <code>&quot;handler_registration&quot;</code> | A required event handler was not registered before calling load(). |
7955
+ | SHIPPING_UPDATE | <code>string</code> | <code>&quot;shipping_update&quot;</code> | Processing a shipping address or shipping option update failed. |
7956
+
7957
+ <a name="OnClickCallback" id="OnClickCallback" href="#OnClickCallback">&nbsp;</a>
7958
+
7959
+ ## OnClickCallback ⇒ <code>boolean</code> \| <code>void</code> \| <code>Promise.&lt;(boolean\|void)&gt;</code>
7960
+ Callback for onClick method.
7961
+
7962
+ **Kind**: global typedef
7963
+ **Returns**: <code>boolean</code> \| <code>void</code> \| <code>Promise.&lt;(boolean\|void)&gt;</code> - Return `false` to abort, or a Promise to defer.
7964
+
7965
+ | Param | Type | Description |
7966
+ | --- | --- | --- |
7967
+ | data | [<code>OnClickEventData</code>](#OnClickEventData) | The click event data. |
7968
+
7969
+ <a name="OnSuccessCallback" id="OnSuccessCallback" href="#OnSuccessCallback">&nbsp;</a>
7970
+
7971
+ ## OnSuccessCallback : <code>function</code>
7972
+ Callback for onSuccess method.
7973
+
7974
+ **Kind**: global typedef
7975
+
7976
+ | Param | Type | Description |
7977
+ | --- | --- | --- |
7978
+ | data | [<code>OnCreateOTTSuccessfulEventData</code>](#OnCreateOTTSuccessfulEventData) | The OTT creation result including the token, amount, and address data. |
7979
+
7980
+ <a name="OnUnavailableCallback" id="OnUnavailableCallback" href="#OnUnavailableCallback">&nbsp;</a>
7981
+
7982
+ ## OnUnavailableCallback : <code>function</code>
7983
+ Callback for onUnavailable method.
7984
+
7985
+ **Kind**: global typedef
7986
+
7987
+ | Param | Type | Description |
7988
+ | --- | --- | --- |
7989
+ | data | [<code>OnUnavailableEventData</code>](#OnUnavailableEventData) | Data describing why the wallet is unavailable. |
7990
+
7991
+ <a name="OnErrorCallback" id="OnErrorCallback" href="#OnErrorCallback">&nbsp;</a>
7992
+
7993
+ ## OnErrorCallback : <code>function</code>
7994
+ Callback for onError method.
7995
+
7996
+ **Kind**: global typedef
7997
+
7998
+ | Param | Type | Description |
7999
+ | --- | --- | --- |
8000
+ | data | [<code>OnErrorEventData</code>](#OnErrorEventData) | The error event data including the Error object and context. |
8001
+
8002
+ <a name="OnCancelCallback" id="OnCancelCallback" href="#OnCancelCallback">&nbsp;</a>
8003
+
8004
+ ## OnCancelCallback : <code>function</code>
8005
+ Callback for onCancel method.
8006
+
8007
+ **Kind**: global typedef
8008
+
8009
+ | Param | Type | Description |
8010
+ | --- | --- | --- |
8011
+ | data | [<code>OnCancelEventData</code>](#OnCancelEventData) | Data associated with the cancellation event. |
8012
+
8013
+ <a name="OnShippingAddressChangeCallback" id="OnShippingAddressChangeCallback" href="#OnShippingAddressChangeCallback">&nbsp;</a>
8014
+
8015
+ ## OnShippingAddressChangeCallback ⇒ [<code>OnShippingAddressChangeEventResponse</code>](#OnShippingAddressChangeEventResponse) \| [<code>Promise.&lt;OnShippingAddressChangeEventResponse&gt;</code>](#OnShippingAddressChangeEventResponse)
8016
+ Callback for onShippingAddressChange method.
8017
+
8018
+ **Kind**: global typedef
8019
+ **Returns**: [<code>OnShippingAddressChangeEventResponse</code>](#OnShippingAddressChangeEventResponse) \| [<code>Promise.&lt;OnShippingAddressChangeEventResponse&gt;</code>](#OnShippingAddressChangeEventResponse) - Address update result containing updated amount, shipping options, and optional error.
8020
+
8021
+ | Param | Type | Description |
8022
+ | --- | --- | --- |
8023
+ | data | [<code>OnShippingAddressChangeEventData</code>](#OnShippingAddressChangeEventData) | The shipping address data from the wallet. |
8024
+
8025
+ <a name="OnShippingOptionsChangeCallback" id="OnShippingOptionsChangeCallback" href="#OnShippingOptionsChangeCallback">&nbsp;</a>
8026
+
8027
+ ## OnShippingOptionsChangeCallback ⇒ [<code>OnShippingOptionChangeEventResponse</code>](#OnShippingOptionChangeEventResponse) \| [<code>Promise.&lt;OnShippingOptionChangeEventResponse&gt;</code>](#OnShippingOptionChangeEventResponse)
8028
+ Callback for onShippingOptionsChange method.
8029
+
8030
+ **Kind**: global typedef
8031
+ **Returns**: [<code>OnShippingOptionChangeEventResponse</code>](#OnShippingOptionChangeEventResponse) \| [<code>Promise.&lt;OnShippingOptionChangeEventResponse&gt;</code>](#OnShippingOptionChangeEventResponse) - Shipping options update result containing the updated amount.
8032
+
8033
+ | Param | Type | Description |
8034
+ | --- | --- | --- |
8035
+ | data | [<code>OnShippingOptionChangeEventData</code>](#OnShippingOptionChangeEventData) | The selected shipping option data. |
8036
+
8037
+
5465
8038
  # Click To Pay
5466
8039
 
5467
8040
  ## Overview