@paydock/client-sdk 1.139.0-beta → 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/bundles/index.mjs CHANGED
@@ -1192,7 +1192,7 @@ SDK.headerKeys = Object.freeze({
1192
1192
  version: 'x-sdk-version',
1193
1193
  type: 'x-sdk-type'
1194
1194
  });
1195
- SDK._version = 'v1.139.0-beta';
1195
+ SDK._version = 'v1.140.0-beta';
1196
1196
 
1197
1197
  function isFunction(value) {
1198
1198
  return typeof value === 'function';
@@ -18785,21 +18785,674 @@ var PaypalCheckoutButton = /*#__PURE__*/function (_CheckoutButton) {
18785
18785
  return _createClass(PaypalCheckoutButton);
18786
18786
  }(CheckoutButton);
18787
18787
 
18788
+ /**
18789
+ * Operations that can fail during the wallet lifecycle.
18790
+ * Used in {@link OnErrorPayload.context.operation} to identify what failed.
18791
+ */
18792
+ var ERROR_OPERATION;
18793
+ (function (ERROR_OPERATION) {
18794
+ /** General wallet lifecycle operation. */
18795
+ ERROR_OPERATION["WALLET_OPERATION"] = "wallet_operation";
18796
+ /** Loading or validating the wallet service configuration. */
18797
+ ERROR_OPERATION["CONFIGURATION"] = "configuration";
18798
+ /** A required event handler was not registered before calling load(). */
18799
+ ERROR_OPERATION["HANDLER_REGISTRATION"] = "handler_registration";
18800
+ /** Processing a shipping address or shipping option update. */
18801
+ ERROR_OPERATION["SHIPPING_UPDATE"] = "shipping_update";
18802
+ })(ERROR_OPERATION || (ERROR_OPERATION = {}));
18803
+
18804
+ /**
18805
+ * Events emitted during the OpenWallet payment lifecycle.
18806
+ */
18788
18807
  var EVENT$2;
18789
18808
  (function (EVENT) {
18790
- EVENT["ON_UPDATE"] = "onUpdate";
18809
+ /** Emitted when the wallet button is clicked by the user. */
18791
18810
  EVENT["ON_CLICK"] = "onClick";
18792
- EVENT["ON_CHECKOUT_CLOSE"] = "onCheckoutClose";
18811
+ /** Emitted when the OTT (One-Time Token) creation succeeds. */
18793
18812
  EVENT["SUCCESS"] = "success";
18813
+ /** Emitted when the wallet is not available on the current device/browser. */
18794
18814
  EVENT["UNAVAILABLE"] = "unavailable";
18815
+ /** Emitted when an error occurs during wallet operation. */
18795
18816
  EVENT["ERROR"] = "error";
18796
- EVENT["UPDATE"] = "update";
18817
+ /** Emitted when the wallet button has been loaded and rendered in the DOM. */
18797
18818
  EVENT["LOADED"] = "loaded";
18819
+ /** Emitted when the wallet checkout is closed/cancelled by the user (internal). */
18798
18820
  EVENT["CHECKOUT_CLOSE"] = "checkoutClose";
18821
+ /** Emitted when the customer selects or updates their shipping address. */
18799
18822
  EVENT["ON_SHIPPING_ADDRESS_CHANGE"] = "onShippingAddressChange";
18823
+ /** Emitted when the customer selects a shipping option. */
18800
18824
  EVENT["ON_SHIPPING_OPTIONS_CHANGE"] = "onShippingOptionsChange";
18801
18825
  })(EVENT$2 || (EVENT$2 = {}));
18802
18826
 
18827
+ /**
18828
+ * @classdesc Abstract base class for Open Wallet buttons. **Do not instantiate directly.**
18829
+ * Use {@link ApplePayOpenWalletButton} or {@link GooglePayOpenWalletButton} instead.
18830
+ *
18831
+ * Use one of the concrete implementations instead:
18832
+ * - {@link ApplePayOpenWalletButton} for Apple Pay integration
18833
+ * - {@link GooglePayOpenWalletButton} for Google Pay integration
18834
+ *
18835
+ * These subclasses inherit all event handlers and lifecycle methods documented below.
18836
+ *
18837
+ * @class OpenWalletButtons
18838
+ * @abstract
18839
+ * @hideconstructor
18840
+ */
18841
+ var OpenWalletButtons = /*#__PURE__*/function () {
18842
+ /** @private */
18843
+ function OpenWalletButtons(selector, publicKeyOrAccessToken, serviceId, meta) {
18844
+ _classCallCheck(this, OpenWalletButtons);
18845
+ this.env = DEFAULT_ENV;
18846
+ this.onShippingOptionsChangeHandlerRegistered = false;
18847
+ this.eventEmitter = new EventEmitter();
18848
+ this.container = new Container(selector);
18849
+ this.api = new ApiInternal(publicKeyOrAccessToken, this.getApiAuthType(publicKeyOrAccessToken));
18850
+ this.serviceId = serviceId;
18851
+ this.meta = meta;
18852
+ this.validateBaseMeta();
18853
+ this.validateWalletMeta();
18854
+ }
18855
+ return _createClass(OpenWalletButtons, [{
18856
+ key: "getApiAuthType",
18857
+ value: function getApiAuthType(publicKeyOrAccessToken) {
18858
+ if (AccessToken.validateJWT(publicKeyOrAccessToken)) {
18859
+ return API_AUTH_TYPE.TOKEN;
18860
+ }
18861
+ return API_AUTH_TYPE.PUBLIC_KEY;
18862
+ }
18863
+ /**
18864
+ * Validates the base metadata fields common to all wallet types:
18865
+ * `meta` must exist, `amount` must be a number, `currency` and `country` must be strings.
18866
+ *
18867
+ * @private
18868
+ * @throws {Error} If any base required field is missing or has an invalid type.
18869
+ */
18870
+ }, {
18871
+ key: "validateBaseMeta",
18872
+ value: function validateBaseMeta() {
18873
+ if (!this.meta) {
18874
+ throw new Error('Meta is required');
18875
+ }
18876
+ if (typeof this.meta.amount !== 'number') {
18877
+ throw new Error('meta.amount needs to be numeric');
18878
+ }
18879
+ if (typeof this.meta.currency !== 'string') {
18880
+ throw new Error('meta.currency needs to be a string');
18881
+ }
18882
+ if (typeof this.meta.country !== 'string') {
18883
+ throw new Error('meta.country needs to be a string');
18884
+ }
18885
+ }
18886
+ }, {
18887
+ key: "getOpenWalletServiceConfig",
18888
+ value: function getOpenWalletServiceConfig() {
18889
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
18890
+ var storageKey, cachedData, _JSON$parse, data, timestamp, oneDay, serviceConfigResponse, encodedData;
18891
+ return _regenerator().w(function (_context) {
18892
+ while (1) switch (_context.p = _context.n) {
18893
+ case 0:
18894
+ storageKey = "serviceConfig-".concat(this.serviceId);
18895
+ _context.p = 1;
18896
+ cachedData = localStorage.getItem(storageKey);
18897
+ if (!cachedData) {
18898
+ _context.n = 5;
18899
+ break;
18900
+ }
18901
+ _context.p = 2;
18902
+ _JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
18903
+ oneDay = 86400000;
18904
+ if (!(Date.now() - timestamp < oneDay)) {
18905
+ _context.n = 3;
18906
+ break;
18907
+ }
18908
+ return _context.a(2, JSON.parse(data));
18909
+ case 3:
18910
+ _context.n = 5;
18911
+ break;
18912
+ case 4:
18913
+ _context.p = 4;
18914
+ _context.v;
18915
+ localStorage.removeItem(storageKey);
18916
+ case 5:
18917
+ _context.n = 7;
18918
+ break;
18919
+ case 6:
18920
+ _context.p = 6;
18921
+ _context.v;
18922
+ case 7:
18923
+ _context.n = 8;
18924
+ return this.api.service().getConfig(this.serviceId);
18925
+ case 8:
18926
+ serviceConfigResponse = _context.v;
18927
+ try {
18928
+ encodedData = btoa(JSON.stringify({
18929
+ data: JSON.stringify(serviceConfigResponse),
18930
+ timestamp: Date.now()
18931
+ }));
18932
+ localStorage.setItem(storageKey, encodedData);
18933
+ } catch (_error) {
18934
+ // localStorage may be unavailable; proceed without caching
18935
+ }
18936
+ return _context.a(2, serviceConfigResponse);
18937
+ }
18938
+ }, _callee, this, [[2, 4], [1, 6]]);
18939
+ }));
18940
+ }
18941
+ }, {
18942
+ key: "handleOnError",
18943
+ value: function handleOnError(error) {
18944
+ var operation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ERROR_OPERATION.WALLET_OPERATION;
18945
+ if (error) {
18946
+ console.error('Wallet operation error:', error);
18947
+ }
18948
+ var errorData = {
18949
+ event: EVENT$2.ERROR,
18950
+ data: {
18951
+ error: error,
18952
+ context: {
18953
+ operation: operation
18954
+ }
18955
+ }
18956
+ };
18957
+ this.eventEmitter.emit(EVENT$2.ERROR, errorData);
18958
+ }
18959
+ /**
18960
+ * Loads and initializes the wallet button based on the service configuration.
18961
+ * This method fetches the wallet service configuration, validates that the service
18962
+ * type matches the expected wallet, and creates the appropriate wallet service instance.
18963
+ * Bear in mind that you must call this method after setting up all event handlers.
18964
+ *
18965
+ * @example
18966
+ * button.onClick((data) => { ... });
18967
+ * button.onSuccess((data) => { ... });
18968
+ * button.onError((error) => { ... });
18969
+ * button.load();
18970
+ */
18971
+ }, {
18972
+ key: "load",
18973
+ value: function load() {
18974
+ var _this = this;
18975
+ this.getOpenWalletServiceConfig().then(function (serviceConfig) {
18976
+ _this.validateServiceType(serviceConfig);
18977
+ _this.walletService = _this.createWalletService(serviceConfig);
18978
+ _this.walletService.load();
18979
+ })["catch"](function (error) {
18980
+ _this.handleOnError(error instanceof Error ? error : new Error(String(error)), ERROR_OPERATION.CONFIGURATION);
18981
+ });
18982
+ }
18983
+ /**
18984
+ * Current method can change environment. By default environment = sandbox.
18985
+ * Also we can change domain alias for this environment. By default domain_alias = paydock.com
18986
+ * Bear in mind that you must set an environment before calling `button.load()`.
18987
+ *
18988
+ * @example
18989
+ * button.setEnv('production', 'paydock.com');
18990
+ *
18991
+ * @param {string} env - The target environment: `'sandbox'` or `'production'`.
18992
+ * @param {string} [alias] - Own domain alias.
18993
+ */
18994
+ }, {
18995
+ key: "setEnv",
18996
+ value: function setEnv(env, alias) {
18997
+ this.env = env;
18998
+ this.api.setEnv(env, alias);
18999
+ }
19000
+ /**
19001
+ * Updates the wallet metadata after initialization.
19002
+ * Use this when order information changes (e.g. amount, currency) after the button has been rendered.
19003
+ * Bear in mind that this must be called before the next payment attempt takes effect.
19004
+ *
19005
+ * @example
19006
+ * button.setMeta({ ...meta, amount: 29.99 });
19007
+ *
19008
+ * @param {ApplePayOpenWalletMeta | GooglePayOpenWalletMeta} meta - The updated metadata object. The concrete type depends on the button class.
19009
+ */
19010
+ }, {
19011
+ key: "setMeta",
19012
+ value: function setMeta(meta) {
19013
+ this.meta = meta;
19014
+ if (this.walletService) {
19015
+ this.walletService.setMeta(meta);
19016
+ }
19017
+ }
19018
+ /**
19019
+ * Removes the wallet button from the DOM and cleans up resources.
19020
+ * Call this method when the wallet button is no longer needed (e.g. navigating away from the payment page).
19021
+ *
19022
+ * @example
19023
+ * button.destroy();
19024
+ */
19025
+ }, {
19026
+ key: "destroy",
19027
+ value: function destroy() {
19028
+ if (this.walletService) {
19029
+ this.walletService.destroy();
19030
+ this.walletService = undefined;
19031
+ }
19032
+ }
19033
+ /**
19034
+ * Callback for onClick method.
19035
+ *
19036
+ * @callback OnClickCallback
19037
+ * @param {OnClickEventData} data - The click event data.
19038
+ * @returns {boolean | void | Promise<boolean | void>} Return `false` to abort, or a Promise to defer.
19039
+ */
19040
+ /**
19041
+ * Registers a callback function to be invoked when the wallet button gets clicked.
19042
+ * The handler controls the wallet payment flow via its return value:
19043
+ *
19044
+ * - Return `void` (or nothing) to continue the payment flow normally.
19045
+ * - Return `false` to abort the payment flow.
19046
+ * - Return a `Promise<void>` to defer the wallet sheet until the promise resolves.
19047
+ * - Return a `Promise<boolean>` — if it resolves to `false`, the flow is aborted.
19048
+ * - Throwing an error (sync or async) also aborts the flow.
19049
+ *
19050
+ * Both synchronous and asynchronous (async) handlers are supported.
19051
+ *
19052
+ * **Note:** this callback may be called multiple times as the customer closes the payment
19053
+ * checkout and re-clicks the button.
19054
+ *
19055
+ * @example
19056
+ * // Synchronous usage — continue normally
19057
+ * button.onClick((event) => {
19058
+ * performValidationLogic();
19059
+ * });
19060
+ *
19061
+ * @example
19062
+ * // Synchronous abort — return false to cancel the payment
19063
+ * button.onClick((event) => {
19064
+ * if (!isOrderValid()) return false;
19065
+ * });
19066
+ *
19067
+ * @example
19068
+ * // Asynchronous usage — defer wallet sheet until the promise resolves
19069
+ * button.onClick(async (event) => {
19070
+ * await fetch('/validate-order').then(res => res.json());
19071
+ * });
19072
+ *
19073
+ * @param {OnClickCallback} handler - Function to be called when the wallet button is clicked.
19074
+ */
19075
+ }, {
19076
+ key: "onClick",
19077
+ value: function onClick(handler) {
19078
+ if (typeof handler === 'function') {
19079
+ this.eventEmitter.subscribe(EVENT$2.ON_CLICK, handler);
19080
+ return;
19081
+ }
19082
+ this.handleOnError(new Error('onClick event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19083
+ }
19084
+ /**
19085
+ * Callback for onSuccess method.
19086
+ *
19087
+ * @callback OnSuccessCallback
19088
+ * @param {OnCreateOTTSuccessfulEventData} data - The OTT creation result including the token, amount, and address data.
19089
+ */
19090
+ /**
19091
+ * Registers a callback function to be invoked when the OTT (One-Time Token) creation was successful.
19092
+ * Both synchronous and asynchronous (async) handlers are supported.
19093
+ *
19094
+ * **Important:** A handler is required. Do not perform thread blocking operations in callback such as `window.alert()` calls.
19095
+ *
19096
+ * **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
19097
+ * so that internal processing continues uninterrupted.
19098
+ *
19099
+ * @example
19100
+ * button.onSuccess((event) => {
19101
+ * console.log('OTT created:', event.data.token.temp_token);
19102
+ * console.log('Amount:', event.data.amount);
19103
+ * });
19104
+ *
19105
+ * @example
19106
+ * // Async handler
19107
+ * button.onSuccess(async (event) => {
19108
+ * await submitTokenToServer(event.data.token.temp_token);
19109
+ * });
19110
+ *
19111
+ * @param {OnSuccessCallback} handler - Function to be called when the OTT creation was successful.
19112
+ */
19113
+ }, {
19114
+ key: "onSuccess",
19115
+ value: function onSuccess(handler) {
19116
+ var _this2 = this;
19117
+ if (typeof handler === 'function') {
19118
+ this.eventEmitter.subscribe(EVENT$2.SUCCESS, function (data) {
19119
+ return __awaiter(_this2, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
19120
+ var _t3;
19121
+ return _regenerator().w(function (_context2) {
19122
+ while (1) switch (_context2.p = _context2.n) {
19123
+ case 0:
19124
+ _context2.p = 0;
19125
+ _context2.n = 1;
19126
+ return handler(data);
19127
+ case 1:
19128
+ _context2.n = 3;
19129
+ break;
19130
+ case 2:
19131
+ _context2.p = 2;
19132
+ _t3 = _context2.v;
19133
+ console.warn('Merchant onSuccess handler threw (swallowed):', _t3);
19134
+ case 3:
19135
+ return _context2.a(2);
19136
+ }
19137
+ }, _callee2, null, [[0, 2]]);
19138
+ }));
19139
+ });
19140
+ return;
19141
+ }
19142
+ this.handleOnError(new Error('onSuccess event handler is required to receive the OTT token string.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19143
+ }
19144
+ /**
19145
+ * Callback for onUnavailable method.
19146
+ *
19147
+ * @callback OnUnavailableCallback
19148
+ * @param {OnUnavailableEventData} data - Data describing why the wallet is unavailable.
19149
+ */
19150
+ /**
19151
+ * Registers a callback function to be invoked when the wallet is not available in the current context.
19152
+ * This can happen when the wallet service is not supported on the current device or browser.
19153
+ * Both synchronous and asynchronous (async) handlers are supported.
19154
+ *
19155
+ * **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
19156
+ * so that internal processing continues uninterrupted.
19157
+ *
19158
+ * @example
19159
+ * button.onUnavailable((event) => {
19160
+ * console.log('Wallet not available:', event.data.reason);
19161
+ * });
19162
+ *
19163
+ * @param {OnUnavailableCallback} handler - Function to be called when the wallet is not available in the current context.
19164
+ */
19165
+ }, {
19166
+ key: "onUnavailable",
19167
+ value: function onUnavailable(handler) {
19168
+ var _this3 = this;
19169
+ if (typeof handler === 'function') {
19170
+ this.eventEmitter.subscribe(EVENT$2.UNAVAILABLE, function (data) {
19171
+ return __awaiter(_this3, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
19172
+ var _t4;
19173
+ return _regenerator().w(function (_context3) {
19174
+ while (1) switch (_context3.p = _context3.n) {
19175
+ case 0:
19176
+ _context3.p = 0;
19177
+ _context3.n = 1;
19178
+ return handler(data);
19179
+ case 1:
19180
+ _context3.n = 3;
19181
+ break;
19182
+ case 2:
19183
+ _context3.p = 2;
19184
+ _t4 = _context3.v;
19185
+ console.warn('Merchant onUnavailable handler threw (swallowed):', _t4);
19186
+ case 3:
19187
+ return _context3.a(2);
19188
+ }
19189
+ }, _callee3, null, [[0, 2]]);
19190
+ }));
19191
+ });
19192
+ return;
19193
+ }
19194
+ this.handleOnError(new Error('onUnavailable event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19195
+ }
19196
+ /**
19197
+ * Callback for onError method.
19198
+ *
19199
+ * @callback OnErrorCallback
19200
+ * @param {OnErrorEventData} data - The error event data including the Error object and context.
19201
+ */
19202
+ /**
19203
+ * Registers a callback function to be invoked when an error occurs during wallet operation.
19204
+ * This includes configuration issues, validation errors, and OTT creation failures.
19205
+ * Both synchronous and asynchronous (async) handlers are supported.
19206
+ *
19207
+ * **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
19208
+ * so that internal processing continues uninterrupted.
19209
+ *
19210
+ * @example
19211
+ * button.onError((event) => {
19212
+ * console.error('Wallet error:', event.data.error.message);
19213
+ * console.log('Context:', event.data.context);
19214
+ * });
19215
+ *
19216
+ * @param {OnErrorCallback} handler - Function to be called when the wallet has an error.
19217
+ */
19218
+ }, {
19219
+ key: "onError",
19220
+ value: function onError(handler) {
19221
+ var _this4 = this;
19222
+ if (typeof handler === 'function') {
19223
+ this.eventEmitter.subscribe(EVENT$2.ERROR, function (data) {
19224
+ return __awaiter(_this4, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
19225
+ var _t5;
19226
+ return _regenerator().w(function (_context4) {
19227
+ while (1) switch (_context4.p = _context4.n) {
19228
+ case 0:
19229
+ _context4.p = 0;
19230
+ _context4.n = 1;
19231
+ return handler(data);
19232
+ case 1:
19233
+ _context4.n = 3;
19234
+ break;
19235
+ case 2:
19236
+ _context4.p = 2;
19237
+ _t5 = _context4.v;
19238
+ console.warn('Merchant onError handler threw (swallowed):', _t5);
19239
+ case 3:
19240
+ return _context4.a(2);
19241
+ }
19242
+ }, _callee4, null, [[0, 2]]);
19243
+ }));
19244
+ });
19245
+ return;
19246
+ }
19247
+ this.handleOnError(new Error('onError event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19248
+ }
19249
+ /**
19250
+ * Callback for onCancel method.
19251
+ *
19252
+ * @callback OnCancelCallback
19253
+ * @param {OnCancelEventData} data - Data associated with the cancellation event.
19254
+ */
19255
+ /**
19256
+ * Registers a callback function to be invoked when the wallet checkout is cancelled or closed by the user.
19257
+ * This event is triggered when the user dismisses the wallet payment interface without completing the transaction.
19258
+ * Both synchronous and asynchronous (async) handlers are supported.
19259
+ *
19260
+ * **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
19261
+ * so that internal processing continues uninterrupted.
19262
+ *
19263
+ * @example
19264
+ * button.onCancel((event) => {
19265
+ * console.log('Wallet checkout cancelled', event);
19266
+ * });
19267
+ *
19268
+ * @param {OnCancelCallback} handler - Function to be called when the wallet checkout is cancelled.
19269
+ */
19270
+ }, {
19271
+ key: "onCancel",
19272
+ value: function onCancel(handler) {
19273
+ var _this5 = this;
19274
+ if (typeof handler === 'function') {
19275
+ this.eventEmitter.subscribe(EVENT$2.CHECKOUT_CLOSE, function (data) {
19276
+ return __awaiter(_this5, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
19277
+ var _t6;
19278
+ return _regenerator().w(function (_context5) {
19279
+ while (1) switch (_context5.p = _context5.n) {
19280
+ case 0:
19281
+ _context5.p = 0;
19282
+ _context5.n = 1;
19283
+ return handler(data);
19284
+ case 1:
19285
+ _context5.n = 3;
19286
+ break;
19287
+ case 2:
19288
+ _context5.p = 2;
19289
+ _t6 = _context5.v;
19290
+ console.warn('Merchant onCancel handler threw (swallowed):', _t6);
19291
+ case 3:
19292
+ return _context5.a(2);
19293
+ }
19294
+ }, _callee5, null, [[0, 2]]);
19295
+ }));
19296
+ });
19297
+ return;
19298
+ }
19299
+ this.handleOnError(new Error('onCancel event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19300
+ }
19301
+ /**
19302
+ * Registers a callback function to be invoked when the wallet button has been loaded and rendered in the DOM.
19303
+ * Both synchronous and asynchronous (async) handlers are supported.
19304
+ *
19305
+ * **Error handling:** If the handler throws (sync or async), the error is logged and swallowed
19306
+ * so that internal processing continues uninterrupted.
19307
+ *
19308
+ * @example
19309
+ * button.onLoaded((event) => {
19310
+ * console.log('Wallet button loaded');
19311
+ * });
19312
+ *
19313
+ * @param {Function} handler - Function to be called when the wallet button is loaded.
19314
+ */
19315
+ }, {
19316
+ key: "onLoaded",
19317
+ value: function onLoaded(handler) {
19318
+ var _this6 = this;
19319
+ if (typeof handler === 'function') {
19320
+ this.eventEmitter.subscribe(EVENT$2.LOADED, function (data) {
19321
+ return __awaiter(_this6, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee6() {
19322
+ var _t7;
19323
+ return _regenerator().w(function (_context6) {
19324
+ while (1) switch (_context6.p = _context6.n) {
19325
+ case 0:
19326
+ _context6.p = 0;
19327
+ _context6.n = 1;
19328
+ return handler(data);
19329
+ case 1:
19330
+ _context6.n = 3;
19331
+ break;
19332
+ case 2:
19333
+ _context6.p = 2;
19334
+ _t7 = _context6.v;
19335
+ console.warn('Merchant onLoaded handler threw (swallowed):', _t7);
19336
+ case 3:
19337
+ return _context6.a(2);
19338
+ }
19339
+ }, _callee6, null, [[0, 2]]);
19340
+ }));
19341
+ });
19342
+ return;
19343
+ }
19344
+ this.handleOnError(new Error('onLoaded event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19345
+ }
19346
+ /**
19347
+ * Callback for onShippingAddressChange method.
19348
+ *
19349
+ * @callback OnShippingAddressChangeCallback
19350
+ * @param {OnShippingAddressChangeEventData} data - The shipping address data from the wallet.
19351
+ * @returns {OnShippingAddressChangeEventResponse | Promise<OnShippingAddressChangeEventResponse>} Address update result containing updated amount, shipping options, and optional error.
19352
+ */
19353
+ /**
19354
+ * Registers a callback for when the customer selects or updates their shipping address.
19355
+ * Use this method to listen for shipping address selection or input from customer when shipping is enabled.
19356
+ * The event handler should return updated payment information including the new amount and
19357
+ * available shipping options based on the selected address.
19358
+ * Both synchronous and asynchronous (async) handlers are supported.
19359
+ *
19360
+ * In case of an address validation error, include the `error` field in the response
19361
+ * to display an appropriate error in the wallet payment sheet.
19362
+ *
19363
+ * @example
19364
+ * // Async handler
19365
+ * button.onShippingAddressChange(async (data) => {
19366
+ * const response = await fetch('https://your-server.com/update-shipping-address', {
19367
+ * method: 'POST',
19368
+ * body: JSON.stringify(data),
19369
+ * });
19370
+ * const result = await response.json();
19371
+ * return {
19372
+ * amount: result.newAmount,
19373
+ * shipping_options: result.availableShippingOptions,
19374
+ * };
19375
+ * });
19376
+ *
19377
+ * @example
19378
+ * // Sync handler
19379
+ * button.onShippingAddressChange((data) => {
19380
+ * return {
19381
+ * amount: calculateShipping(data.data.address_country),
19382
+ * shipping_options: getOptionsForCountry(data.data.address_country),
19383
+ * };
19384
+ * });
19385
+ *
19386
+ * @param {OnShippingAddressChangeCallback} handler - Function to be called when the shipping address data is updated.
19387
+ */
19388
+ }, {
19389
+ key: "onShippingAddressChange",
19390
+ value: function onShippingAddressChange(handler) {
19391
+ if (typeof handler === 'function') {
19392
+ return this.eventEmitter.subscribe(EVENT$2.ON_SHIPPING_ADDRESS_CHANGE, handler);
19393
+ }
19394
+ this.handleOnError(new Error('onShippingAddressChange event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19395
+ }
19396
+ /**
19397
+ * Callback for onShippingOptionsChange method.
19398
+ *
19399
+ * @callback OnShippingOptionsChangeCallback
19400
+ * @param {OnShippingOptionChangeEventData} data - The selected shipping option data.
19401
+ * @returns {OnShippingOptionChangeEventResponse | Promise<OnShippingOptionChangeEventResponse>} Shipping options update result containing the updated amount.
19402
+ */
19403
+ /**
19404
+ * Registers a callback for when the customer selects a shipping option.
19405
+ * Use this method to listen for shipping option selection from customer when shipping is enabled.
19406
+ * The event handler should return the updated payment amount based on the selected shipping option.
19407
+ * Both synchronous and asynchronous (async) handlers are supported.
19408
+ *
19409
+ * @example
19410
+ * // Async handler
19411
+ * button.onShippingOptionsChange(async (data) => {
19412
+ * const response = await fetch('https://your-server.com/update-shipping-option', {
19413
+ * method: 'POST',
19414
+ * body: JSON.stringify({ shipping_option_id: data.data.shipping_option_id }),
19415
+ * });
19416
+ * const result = await response.json();
19417
+ * return {
19418
+ * amount: result.newTotalAmount,
19419
+ * };
19420
+ * });
19421
+ *
19422
+ * @example
19423
+ * // Sync handler
19424
+ * button.onShippingOptionsChange((data) => {
19425
+ * return {
19426
+ * amount: lookupShippingCost(data.data.shipping_option_id),
19427
+ * };
19428
+ * });
19429
+ *
19430
+ * @param {OnShippingOptionsChangeCallback} handler - Function to be called when the shipping options data is updated.
19431
+ */
19432
+ }, {
19433
+ key: "onShippingOptionsChange",
19434
+ value: function onShippingOptionsChange(handler) {
19435
+ if (typeof handler === 'function') {
19436
+ this.onShippingOptionsChangeHandlerRegistered = true;
19437
+ return this.eventEmitter.subscribe(EVENT$2.ON_SHIPPING_OPTIONS_CHANGE, handler);
19438
+ }
19439
+ this.handleOnError(new Error('onShippingOptionsChange event handler is required.'), ERROR_OPERATION.HANDLER_REGISTRATION);
19440
+ }
19441
+ /**
19442
+ * Whether a shipping options change handler has been registered.
19443
+ * Used internally by wallet services to validate shipping configuration.
19444
+ *
19445
+ * @private
19446
+ * @returns {boolean} `true` if an `onShippingOptionsChange` handler has been registered.
19447
+ */
19448
+ }, {
19449
+ key: "isShippingOptionsChangeHandlerRegistered",
19450
+ get: function get() {
19451
+ return this.onShippingOptionsChangeHandlerRegistered;
19452
+ }
19453
+ }]);
19454
+ }();
19455
+
18803
19456
  var PAYLOAD_FORMAT;
18804
19457
  (function (PAYLOAD_FORMAT) {
18805
19458
  PAYLOAD_FORMAT["ENCRYPTED_STRING"] = "encrypted_string";
@@ -18811,7 +19464,48 @@ var SERVICE_GROUP;
18811
19464
  SERVICE_GROUP["WALLET"] = "wallet";
18812
19465
  })(SERVICE_GROUP || (SERVICE_GROUP = {}));
18813
19466
 
19467
+ /**
19468
+ * Recursively removes properties with `undefined` or `null` values from an object.
19469
+ * Returns `undefined` if the resulting object has no remaining properties.
19470
+ */
19471
+ function stripEmpty(obj) {
19472
+ if (!obj || _typeof$1(obj) !== 'object') return undefined;
19473
+ var result = {};
19474
+ for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
19475
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
19476
+ key = _Object$entries$_i[0],
19477
+ value = _Object$entries$_i[1];
19478
+ if (value != null) {
19479
+ if (_typeof$1(value) === 'object' && !Array.isArray(value)) {
19480
+ var nested = stripEmpty(value);
19481
+ if (nested !== undefined) {
19482
+ result[key] = nested;
19483
+ }
19484
+ } else {
19485
+ result[key] = value;
19486
+ }
19487
+ }
19488
+ }
19489
+ return Object.keys(result).length > 0 ? result : undefined;
19490
+ }
19491
+ /**
19492
+ * Abstract base class for wallet-specific OpenWallet service implementations.
19493
+ *
19494
+ * Provides shared functionality for OTT creation, shipping event handling,
19495
+ * error/unavailable emission, and DOM cleanup. Concrete implementations
19496
+ * (e.g. Apple Pay, Google Pay) extend this class and implement {@link load} and {@link setMeta}.
19497
+ *
19498
+ * @implements {IOpenWalletProvider}
19499
+ */
18814
19500
  var OpenWalletService = /*#__PURE__*/function () {
19501
+ /**
19502
+ * @param api - API client for backend communication.
19503
+ * @param eventEmitter - Shared event emitter for wallet lifecycle events.
19504
+ * @param walletType - The wallet type identifier (e.g. `'apple'`, `'google'`).
19505
+ * @param serviceId - The service ID for the wallet configuration.
19506
+ * @param container - The DOM container that holds the wallet button.
19507
+ * @param serviceType - The service type from the API configuration.
19508
+ */
18815
19509
  function OpenWalletService(api, eventEmitter, walletType, serviceId, container, serviceType) {
18816
19510
  _classCallCheck(this, OpenWalletService);
18817
19511
  this.api = api;
@@ -18820,8 +19514,16 @@ var OpenWalletService = /*#__PURE__*/function () {
18820
19514
  this.serviceId = serviceId;
18821
19515
  this.container = container;
18822
19516
  this.serviceType = serviceType;
19517
+ /** The service group identifier used in OTT creation requests. */
18823
19518
  this.serviceGroup = SERVICE_GROUP.WALLET;
18824
19519
  }
19520
+ /**
19521
+ * Creates a One-Time Token (OTT) by sending the payment data to the API.
19522
+ * Emits {@link EVENT.SUCCESS} on success or {@link EVENT.ERROR} on failure.
19523
+ *
19524
+ * @param data - The payment data including amount, shipping, billing, card info, and ref token.
19525
+ * @returns A promise resolving to the OTT response.
19526
+ */
18825
19527
  return _createClass(OpenWalletService, [{
18826
19528
  key: "createOTT",
18827
19529
  value: function createOTT(data) {
@@ -18844,11 +19546,18 @@ var OpenWalletService = /*#__PURE__*/function () {
18844
19546
  payload_format: PAYLOAD_FORMAT.ENCRYPTED_STRING
18845
19547
  };
18846
19548
  return this.api.paymentSource().createOTT(requestData).then(function (response) {
19549
+ var cleanShipping = stripEmpty(shipping);
19550
+ var cleanBilling = stripEmpty(billing);
18847
19551
  _this.eventEmitter.emit(EVENT$2.SUCCESS, {
18848
- token: response,
18849
- amount: amount,
18850
- shipping: shipping,
18851
- billing: billing
19552
+ event: EVENT$2.SUCCESS,
19553
+ data: _extends(_extends({
19554
+ token: response,
19555
+ amount: amount
19556
+ }, cleanShipping && {
19557
+ shipping: cleanShipping
19558
+ }), cleanBilling && {
19559
+ billing: cleanBilling
19560
+ })
18852
19561
  });
18853
19562
  return response;
18854
19563
  })["catch"](function (err) {
@@ -18863,6 +19572,14 @@ var OpenWalletService = /*#__PURE__*/function () {
18863
19572
  throw err;
18864
19573
  });
18865
19574
  }
19575
+ /**
19576
+ * Delegates a shipping change event to the merchant's registered handler
19577
+ * and returns the merchant's response.
19578
+ *
19579
+ * @param eventData - The shipping address or option change event data.
19580
+ * @returns A promise resolving to the merchant's shipping update response.
19581
+ * @throws {Error} If no handler is registered or the handler returns no result.
19582
+ */
18866
19583
  }, {
18867
19584
  key: "handleMerchantOnShippingChangedEvent",
18868
19585
  value: function handleMerchantOnShippingChangedEvent(eventData) {
@@ -18874,7 +19591,7 @@ var OpenWalletService = /*#__PURE__*/function () {
18874
19591
  return _context.a(2, this.eventEmitter.emitWithResult(eventData.event, eventData).then(function (result) {
18875
19592
  if (!result || result.length === 0) {
18876
19593
  var error = new Error('No result from shippingUpdate event');
18877
- _this2.handleOnError(error);
19594
+ _this2.handleOnError(error, ERROR_OPERATION.SHIPPING_UPDATE);
18878
19595
  throw error;
18879
19596
  }
18880
19597
  return result[0];
@@ -18883,40 +19600,60 @@ var OpenWalletService = /*#__PURE__*/function () {
18883
19600
  }, _callee, this);
18884
19601
  }));
18885
19602
  }
19603
+ /**
19604
+ * Emits the {@link EVENT.UNAVAILABLE} event when the wallet is not available.
19605
+ *
19606
+ * @param reason - A human-readable description of why the wallet is unavailable.
19607
+ */
18886
19608
  }, {
18887
19609
  key: "handleOnUnavailable",
18888
19610
  value: function handleOnUnavailable() {
18889
19611
  var reason = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Wallet not available';
18890
19612
  var unavailableData = {
18891
- wallet_type: this.walletType,
18892
- reason: reason,
18893
- details: {
18894
- service_id: this.serviceId
19613
+ event: EVENT$2.UNAVAILABLE,
19614
+ data: {
19615
+ reason: reason,
19616
+ details: {
19617
+ service_id: this.serviceId
19618
+ }
18895
19619
  }
18896
19620
  };
18897
19621
  this.eventEmitter.emit(EVENT$2.UNAVAILABLE, unavailableData);
18898
19622
  }
19623
+ /**
19624
+ * Emits the {@link EVENT.ERROR} event and logs the error to the console.
19625
+ *
19626
+ * @param error - The error that occurred.
19627
+ * @param operation - The operation that failed. Defaults to {@link ERROR_OPERATION.WALLET_OPERATION}.
19628
+ */
18899
19629
  }, {
18900
19630
  key: "handleOnError",
18901
19631
  value: function handleOnError(error) {
18902
- var errorData = {
18903
- error: error,
18904
- context: {
18905
- operation: 'wallet_operation',
18906
- wallet_type: this.walletType
18907
- }
18908
- };
19632
+ var operation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ERROR_OPERATION.WALLET_OPERATION;
18909
19633
  if (error) {
18910
19634
  console.error('Wallet operation error:', error);
18911
19635
  }
19636
+ var errorData = {
19637
+ event: EVENT$2.ERROR,
19638
+ data: {
19639
+ error: error,
19640
+ context: {
19641
+ operation: operation
19642
+ }
19643
+ }
19644
+ };
18912
19645
  this.eventEmitter.emit(EVENT$2.ERROR, errorData);
18913
19646
  }
19647
+ /**
19648
+ * Removes the wallet button element from the DOM.
19649
+ * Call this to clean up resources when the button is no longer needed.
19650
+ */
18914
19651
  }, {
18915
19652
  key: "destroy",
18916
19653
  value: function destroy() {
18917
19654
  var element = this.container.getElement();
18918
- if (element === null || element === void 0 ? void 0 : element.parentNode) {
18919
- element.parentNode.removeChild(element);
19655
+ if (element) {
19656
+ element.innerHTML = '';
18920
19657
  }
18921
19658
  }
18922
19659
  }]);
@@ -18929,7 +19666,24 @@ var WALLET_TYPES;
18929
19666
  })(WALLET_TYPES || (WALLET_TYPES = {}));
18930
19667
 
18931
19668
  var DEFAULT_APPLE_PAY_CAPABILITIES$1 = ['paymentCredentialsAvailable'];
19669
+ /**
19670
+ * Apple Pay implementation of the OpenWallet service.
19671
+ *
19672
+ * Handles loading the Apple Pay SDK, checking device/browser availability,
19673
+ * rendering the Apple Pay button, and managing the full Apple Pay payment session
19674
+ * lifecycle including merchant validation, payment authorization, and shipping updates.
19675
+ *
19676
+ * @extends OpenWalletService
19677
+ */
18932
19678
  var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19679
+ /**
19680
+ * @param api - API client for backend communication.
19681
+ * @param eventEmitter - Shared event emitter for wallet lifecycle events.
19682
+ * @param serviceId - The service ID for the Apple Pay configuration.
19683
+ * @param container - The DOM container that will hold the Apple Pay button.
19684
+ * @param meta - Apple Pay-specific metadata (amount, currency, shipping config, etc.).
19685
+ * @param serviceConfig - The service configuration response from the API.
19686
+ */
18933
19687
  function ApplePayOpenWalletService(api, eventEmitter, serviceId, container, meta, serviceConfig) {
18934
19688
  var _this;
18935
19689
  _classCallCheck(this, ApplePayOpenWalletService);
@@ -18938,7 +19692,9 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
18938
19692
  _this.serviceConfig = serviceConfig;
18939
19693
  _this.latestShippingData = {};
18940
19694
  _this.onCancelPayment = function () {
18941
- return _this.eventEmitter.emit(EVENT$2.CHECKOUT_CLOSE);
19695
+ return _this.eventEmitter.emit(EVENT$2.CHECKOUT_CLOSE, {
19696
+ event: EVENT$2.CHECKOUT_CLOSE
19697
+ });
18942
19698
  };
18943
19699
  _this.onValidateMerchant = function () {
18944
19700
  _this.handleMerchantOnButtonClickEvent().then(function () {
@@ -18952,7 +19708,7 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
18952
19708
  });
18953
19709
  };
18954
19710
  _this.onPaymentAuthorized = function (event) {
18955
- var _a;
19711
+ var _a, _b, _c, _d, _e;
18956
19712
  var _event$payment = event.payment,
18957
19713
  token = _event$payment.token,
18958
19714
  billingContact = _event$payment.billingContact,
@@ -18964,8 +19720,8 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
18964
19720
  }), _this.hasShippingOptions() && {
18965
19721
  options: _this.meta.shipping_options
18966
19722
  }), {
18967
- address_line1: shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.addressLines[0],
18968
- address_line2: shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.addressLines[1],
19723
+ address_line1: (_b = shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.addressLines) === null || _b === void 0 ? void 0 : _b[0],
19724
+ address_line2: (_c = shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.addressLines) === null || _c === void 0 ? void 0 : _c[1],
18969
19725
  address_country: shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.countryCode,
18970
19726
  address_city: shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.locality,
18971
19727
  address_postcode: shippingContact === null || shippingContact === void 0 ? void 0 : shippingContact.postalCode,
@@ -18978,8 +19734,8 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
18978
19734
  }
18979
19735
  });
18980
19736
  var billing = {
18981
- address_line1: billingContact === null || billingContact === void 0 ? void 0 : billingContact.addressLines[0],
18982
- address_line2: billingContact === null || billingContact === void 0 ? void 0 : billingContact.addressLines[1],
19737
+ address_line1: (_d = billingContact === null || billingContact === void 0 ? void 0 : billingContact.addressLines) === null || _d === void 0 ? void 0 : _d[0],
19738
+ address_line2: (_e = billingContact === null || billingContact === void 0 ? void 0 : billingContact.addressLines) === null || _e === void 0 ? void 0 : _e[1],
18983
19739
  address_country: billingContact === null || billingContact === void 0 ? void 0 : billingContact.countryCode,
18984
19740
  address_city: billingContact === null || billingContact === void 0 ? void 0 : billingContact.locality,
18985
19741
  address_postcode: billingContact === null || billingContact === void 0 ? void 0 : billingContact.postalCode,
@@ -19020,22 +19776,39 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19020
19776
  event: EVENT$2.ON_SHIPPING_ADDRESS_CHANGE,
19021
19777
  data: this.parseShippingContactUpdateEvent(data)
19022
19778
  }).then(function (response) {
19023
- var _a;
19779
+ var _a, _b;
19024
19780
  var mappedNewShippingMethods = [];
19025
- if (((_a = response === null || response === void 0 ? void 0 : response.shipping_options) === null || _a === void 0 ? void 0 : _a.length) > 0) {
19026
- _this2.meta.shipping_options = response.shipping_options;
19027
- _this2.selectedShippingOption = response.shipping_options[0];
19781
+ var errors = [];
19782
+ if ((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.code) {
19783
+ errors.push(_this2.formatErrorFields(response.error));
19784
+ }
19785
+ if (((_b = response === null || response === void 0 ? void 0 : response.shipping_options) === null || _b === void 0 ? void 0 : _b.length) > 0) {
19786
+ var appleShippingOptions = response.shipping_options;
19787
+ _this2.meta.shipping_options = appleShippingOptions;
19788
+ _this2.selectedShippingOption = appleShippingOptions[0];
19028
19789
  _this2.latestShippingData.shippingMethod = _this2.formatShippingOptions([_this2.selectedShippingOption])[0];
19029
- mappedNewShippingMethods = _this2.parseShippingMethod(response.shipping_options);
19790
+ mappedNewShippingMethods = _this2.parseShippingMethod(appleShippingOptions);
19791
+ }
19792
+ if (response.amount !== undefined) {
19793
+ _this2.meta.amount = response.amount;
19030
19794
  }
19031
- _this2.meta.amount = response.amount;
19032
19795
  _this2.paymentSession.completeShippingContactSelection({
19033
19796
  newTotal: {
19034
19797
  label: _this2.meta.amount_label,
19035
- amount: String(response.amount),
19798
+ amount: String(_this2.meta.amount),
19036
19799
  type: 'final'
19037
19800
  },
19038
- newShippingMethods: mappedNewShippingMethods
19801
+ newShippingMethods: mappedNewShippingMethods,
19802
+ errors: errors
19803
+ });
19804
+ })["catch"](function () {
19805
+ // No handler registered or handler threw — auto-accept with current data
19806
+ _this2.paymentSession.completeShippingContactSelection({
19807
+ newTotal: {
19808
+ label: _this2.meta.amount_label,
19809
+ amount: String(_this2.meta.amount),
19810
+ type: 'final'
19811
+ }
19039
19812
  });
19040
19813
  }));
19041
19814
  }
@@ -19052,11 +19825,36 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19052
19825
  event: EVENT$2.ON_SHIPPING_OPTIONS_CHANGE,
19053
19826
  data: this.parseShippingMethodUpdateEvent(data)
19054
19827
  }).then(function (response) {
19055
- _this3.meta.amount = response.amount;
19828
+ var _a;
19829
+ if ((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.code) {
19830
+ // Apple Pay's completeShippingMethodSelection does not support errors,
19831
+ // so emit the error to the merchant and complete with current data.
19832
+ _this3.handleOnError(new Error(response.error.message || 'Shipping method update error'), ERROR_OPERATION.SHIPPING_UPDATE);
19833
+ _this3.paymentSession.completeShippingMethodSelection({
19834
+ newTotal: {
19835
+ label: _this3.meta.amount_label,
19836
+ amount: String(_this3.meta.amount),
19837
+ type: 'final'
19838
+ }
19839
+ });
19840
+ return;
19841
+ }
19842
+ if (response.amount !== undefined) {
19843
+ _this3.meta.amount = response.amount;
19844
+ }
19845
+ _this3.paymentSession.completeShippingMethodSelection({
19846
+ newTotal: {
19847
+ label: _this3.meta.amount_label,
19848
+ amount: String(_this3.meta.amount),
19849
+ type: 'final'
19850
+ }
19851
+ });
19852
+ })["catch"](function () {
19853
+ // No handler registered or handler threw — auto-accept with current data
19056
19854
  _this3.paymentSession.completeShippingMethodSelection({
19057
19855
  newTotal: {
19058
19856
  label: _this3.meta.amount_label,
19059
- amount: String(response.amount),
19857
+ amount: String(_this3.meta.amount),
19060
19858
  type: 'final'
19061
19859
  }
19062
19860
  });
@@ -19070,6 +19868,12 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19070
19868
  }
19071
19869
  _inherits(ApplePayOpenWalletService, _OpenWalletService);
19072
19870
  return _createClass(ApplePayOpenWalletService, [{
19871
+ key: "setMeta",
19872
+ value: function setMeta(meta) {
19873
+ this.meta = _extends(_extends({}, this.meta), meta);
19874
+ this.adaptMeta();
19875
+ }
19876
+ }, {
19073
19877
  key: "adaptMeta",
19074
19878
  value: function adaptMeta() {
19075
19879
  var _a;
@@ -19114,12 +19918,11 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19114
19918
  }, {
19115
19919
  key: "getMetaStyles",
19116
19920
  value: function getMetaStyles() {
19117
- var _a, _b, _c;
19921
+ var _a, _b;
19118
19922
  if (((_a = this.meta) === null || _a === void 0 ? void 0 : _a.style) && _typeof$1((_b = this.meta) === null || _b === void 0 ? void 0 : _b.style) === 'object') {
19119
- var metaStyles = JSON.parse(JSON.stringify((_c = this.meta) === null || _c === void 0 ? void 0 : _c.style));
19120
- return metaStyles;
19923
+ return JSON.parse(JSON.stringify(this.meta.style));
19121
19924
  }
19122
- return null;
19925
+ return undefined;
19123
19926
  }
19124
19927
  }, {
19125
19928
  key: "isShippingRequired",
@@ -19197,10 +20000,10 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19197
20000
  key: "checkAvailability",
19198
20001
  value: function checkAvailability() {
19199
20002
  var _this6 = this;
19200
- return new Promise(function (resolve, _reject) {
20003
+ return new Promise(function (resolve) {
19201
20004
  var _a;
19202
20005
  if (!window.ApplePaySession || !ApplePaySession) {
19203
- resolve(false);
20006
+ return resolve(false);
19204
20007
  }
19205
20008
  var formattedCapabilities = DEFAULT_APPLE_PAY_CAPABILITIES$1;
19206
20009
  if (((_a = _this6.meta.apple_pay_capabilities) === null || _a === void 0 ? void 0 : _a.length) > 0) {
@@ -19209,7 +20012,7 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19209
20012
  ApplePaySession.applePayCapabilities(_this6.getMerchantId()).then(function (capabilities) {
19210
20013
  var canMakePayment = formattedCapabilities.includes(capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus);
19211
20014
  resolve(canMakePayment);
19212
- })["catch"](function (_err) {
20015
+ })["catch"](function () {
19213
20016
  resolve(false);
19214
20017
  });
19215
20018
  });
@@ -19232,7 +20035,7 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19232
20035
  }
19233
20036
  applePayButton.addEventListener('click', this.onApplePayButtonClicked.bind(this));
19234
20037
  this.eventEmitter.emit(EVENT$2.LOADED, {
19235
- wallet: WALLET_TYPES.APPLE_PAY
20038
+ event: EVENT$2.LOADED
19236
20039
  });
19237
20040
  }
19238
20041
  }, {
@@ -19251,11 +20054,10 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19251
20054
  value: function getMerchantSession() {
19252
20055
  var _this7 = this;
19253
20056
  return new Promise(function (resolve, reject) {
19254
- var _a;
19255
20057
  return _this7.api.paymentSource().createSession(_extends({
19256
20058
  service_id: _this7.serviceId,
19257
20059
  session_id: window.location.hostname,
19258
- store_name: (_a = _this7.meta.store_name) !== null && _a !== void 0 ? _a : ''
20060
+ store_name: _this7.meta.store_name
19259
20061
  }, _this7.isShippingRequired() && {
19260
20062
  request_shipping: _this7.meta.request_shipping
19261
20063
  })).then(function (res) {
@@ -19268,24 +20070,29 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19268
20070
  }, {
19269
20071
  key: "handleMerchantOnButtonClickEvent",
19270
20072
  value: function handleMerchantOnButtonClickEvent() {
19271
- var _this8 = this;
19272
- return new Promise(function (resolve, reject) {
19273
- var merchantResult;
19274
- _this8.eventEmitter.emit(EVENT$2.ON_CLICK, {
19275
- attachResult: function attachResult(value) {
19276
- merchantResult = value;
19277
- }
19278
- });
19279
- if (merchantResult instanceof Promise) {
19280
- merchantResult.then(resolve)["catch"](reject);
19281
- } else {
19282
- if (merchantResult === false) {
19283
- reject();
19284
- } else {
19285
- resolve();
20073
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
20074
+ var results;
20075
+ return _regenerator().w(function (_context4) {
20076
+ while (1) switch (_context4.n) {
20077
+ case 0:
20078
+ _context4.n = 1;
20079
+ return this.eventEmitter.emitWithResult(EVENT$2.ON_CLICK, {
20080
+ event: EVENT$2.ON_CLICK
20081
+ });
20082
+ case 1:
20083
+ results = _context4.v;
20084
+ if (!results.some(function (r) {
20085
+ return r === false;
20086
+ })) {
20087
+ _context4.n = 2;
20088
+ break;
20089
+ }
20090
+ throw new Error('onClick handler aborted the payment flow');
20091
+ case 2:
20092
+ return _context4.a(2);
19286
20093
  }
19287
- }
19288
- });
20094
+ }, _callee4, this);
20095
+ }));
19289
20096
  }
19290
20097
  }, {
19291
20098
  key: "formatCapabilities",
@@ -19299,6 +20106,29 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19299
20106
  return fieldMap[capability] || capability;
19300
20107
  });
19301
20108
  }
20109
+ }, {
20110
+ key: "formatErrorFields",
20111
+ value: function formatErrorFields(error) {
20112
+ var fieldMap = {
20113
+ phone: 'phoneNumber',
20114
+ email: 'emailAddress',
20115
+ phonetic_name: 'phoneticName',
20116
+ address_lines: 'addressLines',
20117
+ address_city: 'locality',
20118
+ address_postcode: 'postalCode',
20119
+ address_state: 'administrativeArea',
20120
+ address_country: 'country',
20121
+ address_country_code: 'countryCode'
20122
+ };
20123
+ var contactField = fieldMap[error.field] || error.field;
20124
+ var codeMap = {
20125
+ address_error: 'addressUnserviceable',
20126
+ shipping_contact_invalid: 'shippingContactInvalid',
20127
+ billing_contact_invalid: 'billingContactInvalid'
20128
+ };
20129
+ var code = codeMap[error.code] || 'unknown';
20130
+ return new ApplePayError(code, contactField, error.message);
20131
+ }
19302
20132
  }, {
19303
20133
  key: "createButtonStyle",
19304
20134
  value: function createButtonStyle() {
@@ -19445,19 +20275,139 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19445
20275
  }]);
19446
20276
  }(OpenWalletService);
19447
20277
 
20278
+ /**
20279
+ * @classdesc Apple Pay wallet button that creates One-Time Tokens (OTT) via Apple Pay.
20280
+ *
20281
+ * Provides a fully typed Apple Pay integration with Apple Pay-specific metadata
20282
+ * and validates that the service configuration corresponds to an Apple Pay service.
20283
+ * On `load()`, the button fetches the service configuration and raises an error via `onError`
20284
+ * if the service type does not match Apple Pay.
20285
+ *
20286
+ * @class ApplePayOpenWalletButton
20287
+ * @extends OpenWalletButtons
20288
+ *
20289
+ * @param {string} selector - CSS selector of the HTML element that will contain the Apple Pay button.
20290
+ * @param {string} publicKeyOrAccessToken - Public key or access token for API authentication.
20291
+ * @param {string} serviceId - The Apple Pay service ID configured in PayDock dashboard.
20292
+ * @param {ApplePayOpenWalletMeta} meta - Apple Pay-specific metadata (amount, currency, country, amount_label, store_name, style, apple_pay_capabilities, etc.).
20293
+ *
20294
+ * @example
20295
+ * const button = new ApplePayOpenWalletButton(
20296
+ * '#wallet-container',
20297
+ * publicKeyOrAccessToken,
20298
+ * serviceId,
20299
+ * {
20300
+ * amount: 100,
20301
+ * currency: 'AUD',
20302
+ * country: 'AU',
20303
+ * amount_label: 'TOTAL',
20304
+ * store_name: 'My Store',
20305
+ * apple_pay_capabilities: ['credentials_available'],
20306
+ * },
20307
+ * );
20308
+ * button.setEnv('sandbox');
20309
+ * button.onSuccess((data) => console.log('OTT:', data.token));
20310
+ * button.onError((error) => console.error('Error:', error));
20311
+ * button.load();
20312
+ */
20313
+ var ApplePayOpenWalletButton = /*#__PURE__*/function (_OpenWalletButtons) {
20314
+ function ApplePayOpenWalletButton() {
20315
+ var _this;
20316
+ _classCallCheck(this, ApplePayOpenWalletButton);
20317
+ _this = _callSuper(this, ApplePayOpenWalletButton, arguments);
20318
+ /** @private */
20319
+ _this.walletType = WALLET_TYPES.APPLE_PAY;
20320
+ return _this;
20321
+ }
20322
+ /**
20323
+ * Validates Apple Pay-specific required metadata fields.
20324
+ * Apple Pay requires `amount_label` and `store_name` to be present and strings.
20325
+ *
20326
+ * @private
20327
+ * @throws {Error} If `amount_label` is missing or not a string.
20328
+ * @throws {Error} If `store_name` is missing or not a string.
20329
+ */
20330
+ _inherits(ApplePayOpenWalletButton, _OpenWalletButtons);
20331
+ return _createClass(ApplePayOpenWalletButton, [{
20332
+ key: "validateWalletMeta",
20333
+ value: function validateWalletMeta() {
20334
+ if (typeof this.meta.amount_label !== 'string' || this.meta.amount_label.trim() === '') {
20335
+ throw new Error("meta.amount_label is required for Apple Pay and must be a non-empty string (e.g. 'TOTAL').");
20336
+ }
20337
+ if (typeof this.meta.store_name !== 'string' || this.meta.store_name.trim() === '') {
20338
+ throw new Error('meta.store_name is required for Apple Pay and must be a non-empty string.');
20339
+ }
20340
+ }
20341
+ /**
20342
+ * Validates that the service configuration type is Apple Pay.
20343
+ *
20344
+ * @private
20345
+ * @param serviceConfig - The service configuration response from the API.
20346
+ * @throws {Error} If the service type is not Apple Pay.
20347
+ */
20348
+ }, {
20349
+ key: "validateServiceType",
20350
+ value: function validateServiceType(serviceConfig) {
20351
+ if (serviceConfig.type !== SERVICE_TYPES.APPLE_PAY) {
20352
+ throw new Error("Service configuration type '".concat(serviceConfig.type, "' does not match expected wallet type '").concat(WALLET_TYPES.APPLE_PAY, "'. ") + "Ensure the service ID '".concat(this.serviceId, "' corresponds to an Apple Pay service."));
20353
+ }
20354
+ }
20355
+ /**
20356
+ * Creates an Apple Pay wallet service instance.
20357
+ *
20358
+ * @private
20359
+ * @param serviceConfig - The service configuration response from the API.
20360
+ * @returns The Apple Pay wallet service instance.
20361
+ */
20362
+ }, {
20363
+ key: "createWalletService",
20364
+ value: function createWalletService(serviceConfig) {
20365
+ return new ApplePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
20366
+ }
20367
+ }]);
20368
+ }(OpenWalletButtons);
20369
+
20370
+ /**
20371
+ * Token types returned in the OTT (One-Time Token) creation response.
20372
+ */
20373
+ var TOKEN_TYPE;
20374
+ (function (TOKEN_TYPE) {
20375
+ /** FPAN - Funding Primary Account Number (Google Pay only). */
20376
+ TOKEN_TYPE["CARD"] = "card";
20377
+ /** DPAN - Device Primary Account Number (Apple Pay & Google Pay). */
20378
+ TOKEN_TYPE["CARD_SCHEME_TOKEN"] = "card_scheme_token";
20379
+ })(TOKEN_TYPE || (TOKEN_TYPE = {}));
20380
+
20381
+ /** URL for the Google Pay JavaScript SDK. */
19448
20382
  var GOOGLE_PAY_SCRIPT_URL = 'https://pay.google.com/gp/p/js/pay.js';
20383
+ /** The default gateway identifier for Paydock. */
19449
20384
  var GOOGLE_PAY_GATEWAY = 'paydock';
20385
+ /** Google Pay API version configuration. */
19450
20386
  var GOOGLE_PAY_API_CONFIG = {
19451
20387
  apiVersion: 2,
19452
20388
  apiVersionMinor: 0
19453
20389
  };
20390
+ /** Default allowed authentication methods for Google Pay card payments. */
19454
20391
  var GOOGLE_PAY_AUTH_METHODS = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];
20392
+ /** Default allowed card networks for Google Pay payments. */
19455
20393
  var GOOGLE_PAY_CARD_NETWORKS = ['AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCARD', 'VISA'];
19456
- var GOOGLE_EVENT_TO_WALLET_EVENT = {
20394
+ /**
20395
+ * Maps Google Pay callback triggers to OpenWallet event names.
20396
+ * Used to translate shipping-related Google Pay events to the unified event system.
20397
+ */
20398
+ ({
19457
20399
  SHIPPING_ADDRESS: EVENT$2.ON_SHIPPING_ADDRESS_CHANGE,
19458
20400
  SHIPPING_OPTION: EVENT$2.ON_SHIPPING_OPTIONS_CHANGE
19459
- };
20401
+ });
19460
20402
 
20403
+ /**
20404
+ * Parses intermediate payment data from Google Pay into a normalized format
20405
+ * for use in shipping address/option change events.
20406
+ *
20407
+ * @param data - The intermediate payment data from the Google Pay callback.
20408
+ * @param meta - The current Google Pay wallet metadata.
20409
+ * @returns Parsed shipping address and selected shipping option data.
20410
+ */
19461
20411
  var parseUpdateData = function parseUpdateData(data, meta) {
19462
20412
  var _a, _b, _c, _d, _e;
19463
20413
  var shippingOption = (_a = meta === null || meta === void 0 ? void 0 : meta.shipping_options) === null || _a === void 0 ? void 0 : _a.find(function (o) {
@@ -19481,6 +20431,13 @@ var parseUpdateData = function parseUpdateData(data, meta) {
19481
20431
  }
19482
20432
  });
19483
20433
  };
20434
+ /**
20435
+ * Converts an array of shipping options from the internal format
20436
+ * to Google Pay's `SelectionOption` format.
20437
+ *
20438
+ * @param shipping_options - The shipping options in internal format.
20439
+ * @returns An array of Google Pay selection options.
20440
+ */
19484
20441
  var formatShippingOptions = function formatShippingOptions(shipping_options) {
19485
20442
  return shipping_options.map(function (option) {
19486
20443
  return {
@@ -19490,6 +20447,14 @@ var formatShippingOptions = function formatShippingOptions(shipping_options) {
19490
20447
  };
19491
20448
  });
19492
20449
  };
20450
+ /**
20451
+ * Maps Google Pay payment data to the format required for OTT creation.
20452
+ * Extracts billing/shipping addresses, card info, and the tokenization token.
20453
+ *
20454
+ * @param paymentData - The payment data from Google Pay's `onPaymentAuthorized` callback.
20455
+ * @param meta - The current Google Pay wallet metadata.
20456
+ * @returns The data required to create an OTT.
20457
+ */
19493
20458
  var mapGooglePayData = function mapGooglePayData(paymentData, meta) {
19494
20459
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
19495
20460
  var billingAddressLine1 = (_c = (_b = (_a = paymentData.paymentMethodData) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.billingAddress) === null || _c === void 0 ? void 0 : _c.address1;
@@ -19529,6 +20494,37 @@ var mapGooglePayData = function mapGooglePayData(paymentData, meta) {
19529
20494
  ref_token: paymentData.paymentMethodData.tokenizationData.token
19530
20495
  };
19531
20496
  };
20497
+ /**
20498
+ * Maps a Paydock-defined shipping error code to the corresponding
20499
+ * Google Pay {@link google.payments.api.ErrorReason}.
20500
+ *
20501
+ * @param errorCode - The error code from the merchant's shipping change response.
20502
+ * @returns The Google Pay error reason string.
20503
+ */
20504
+ var mapShippingErrorCodeToGooglePayReason = function mapShippingErrorCodeToGooglePayReason(errorCode) {
20505
+ switch (errorCode) {
20506
+ case 'country_error':
20507
+ case 'state_error':
20508
+ return 'SHIPPING_ADDRESS_UNSERVICEABLE';
20509
+ case 'address_error':
20510
+ case 'zip_error':
20511
+ case 'shipping_contact_invalid':
20512
+ return 'SHIPPING_ADDRESS_INVALID';
20513
+ case 'method_unavailable':
20514
+ case 'store_unavailable':
20515
+ return 'SHIPPING_OPTION_INVALID';
20516
+ case 'billing_contact_invalid':
20517
+ default:
20518
+ return 'OTHER_ERROR';
20519
+ }
20520
+ };
20521
+ /**
20522
+ * Maps billing address parameters from internal snake_case format
20523
+ * to Google Pay's camelCase format.
20524
+ *
20525
+ * @param billingAddressParams - The billing address parameters in internal format.
20526
+ * @returns Google Pay billing address parameters, or `undefined` if input is falsy.
20527
+ */
19532
20528
  var mapBillingAddressParameters = function mapBillingAddressParameters(billingAddressParams) {
19533
20529
  if (!billingAddressParams) {
19534
20530
  return undefined;
@@ -19539,6 +20535,13 @@ var mapBillingAddressParameters = function mapBillingAddressParameters(billingAd
19539
20535
  phoneNumberRequired: billingAddressParams.phone_number_required
19540
20536
  });
19541
20537
  };
20538
+ /**
20539
+ * Maps card network parameters from internal snake_case format
20540
+ * to Google Pay's camelCase format.
20541
+ *
20542
+ * @param cardNetworkParams - The card network parameters in internal format.
20543
+ * @returns Google Pay card network parameters, or `undefined` if input is falsy.
20544
+ */
19542
20545
  var mapCardNetworkParameters = function mapCardNetworkParameters(cardNetworkParams) {
19543
20546
  if (!cardNetworkParams) {
19544
20547
  return undefined;
@@ -19554,6 +20557,19 @@ var mapCardNetworkParameters = function mapCardNetworkParameters(cardNetworkPara
19554
20557
  });
19555
20558
  };
19556
20559
 
20560
+ /**
20561
+ * Validates a Google Pay card configuration object.
20562
+ *
20563
+ * Checks that required fields are present and correctly structured:
20564
+ * - `allowed_auth_methods` must be a non-empty array.
20565
+ * - `allowed_card_networks` must be a non-empty array.
20566
+ * - If a `tokenization_specification` is provided:
20567
+ * - `DIRECT` requires `protocol_version` and `public_key`.
20568
+ * - `PAYMENT_GATEWAY` requires non-empty `parameters`.
20569
+ *
20570
+ * @param cardConfig - The Google Pay card configuration to validate.
20571
+ * @returns An array of human-readable error messages. Empty array means valid.
20572
+ */
19557
20573
  var validateCardConfiguration = function validateCardConfiguration(cardConfig) {
19558
20574
  var errors = [];
19559
20575
  if (!cardConfig.parameters.allowed_auth_methods || cardConfig.parameters.allowed_auth_methods.length === 0) {
@@ -19580,7 +20596,24 @@ var validateCardConfiguration = function validateCardConfiguration(cardConfig) {
19580
20596
  return errors;
19581
20597
  };
19582
20598
 
20599
+ /**
20600
+ * Google Pay implementation of the OpenWallet service.
20601
+ *
20602
+ * Handles loading the Google Pay SDK, checking device/browser availability,
20603
+ * rendering the Google Pay button, and managing the full payment lifecycle
20604
+ * including payment authorization, shipping address/option changes, and OTT creation.
20605
+ *
20606
+ * @extends OpenWalletService
20607
+ */
19583
20608
  var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
20609
+ /**
20610
+ * @param api - API client for backend communication.
20611
+ * @param eventEmitter - Shared event emitter for wallet lifecycle events.
20612
+ * @param serviceId - The service ID for the Google Pay configuration.
20613
+ * @param container - The DOM container that will hold the Google Pay button.
20614
+ * @param meta - Google Pay-specific metadata (amount, currency, card config, etc.).
20615
+ * @param serviceConfig - The service configuration response from the API.
20616
+ */
19584
20617
  function GooglePayOpenWalletService(api, eventEmitter, serviceId, container, meta, serviceConfig) {
19585
20618
  var _this;
19586
20619
  _classCallCheck(this, GooglePayOpenWalletService);
@@ -19651,7 +20684,7 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19651
20684
  googlePayJs.onload = function () {
19652
20685
  if (!window.google) {
19653
20686
  _this2.handleOnUnavailable('Google Pay not available');
19654
- reject();
20687
+ reject(new Error('Google Pay not available'));
19655
20688
  return;
19656
20689
  }
19657
20690
  _this2.onScriptLoaded();
@@ -19659,7 +20692,7 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19659
20692
  };
19660
20693
  googlePayJs.onerror = function () {
19661
20694
  _this2.handleOnUnavailable('Failed to load Google Pay script');
19662
- reject();
20695
+ reject(new Error('Failed to load Google Pay script'));
19663
20696
  };
19664
20697
  document.head.appendChild(googlePayJs);
19665
20698
  });
@@ -19729,6 +20762,9 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19729
20762
  buttonColor: ((_c = this.getMetaStyles()) === null || _c === void 0 ? void 0 : _c.button_color) || 'default'
19730
20763
  });
19731
20764
  button.appendChild(googlePayButton);
20765
+ this.eventEmitter.emit(EVENT$2.LOADED, {
20766
+ event: EVENT$2.LOADED
20767
+ });
19732
20768
  }
19733
20769
  }, {
19734
20770
  key: "onGooglePayButtonClicked",
@@ -19750,51 +20786,55 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19750
20786
  }, {
19751
20787
  key: "handleMerchantOnButtonClickEvent",
19752
20788
  value: function handleMerchantOnButtonClickEvent() {
19753
- var _this6 = this;
19754
- return new Promise(function (resolve, reject) {
19755
- var merchantResult;
19756
- _this6.eventEmitter.emit(EVENT$2.ON_CLICK, {
19757
- request_type: 'google_pay_button_click',
19758
- wallet_type: _this6.walletType,
19759
- meta: _this6.meta,
19760
- attachResult: function attachResult(value) {
19761
- merchantResult = value;
19762
- }
19763
- });
19764
- if (merchantResult instanceof Promise) {
19765
- merchantResult.then(resolve)["catch"](reject);
19766
- } else {
19767
- if (merchantResult === false) {
19768
- reject();
19769
- } else {
19770
- resolve();
20789
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
20790
+ var results;
20791
+ return _regenerator().w(function (_context3) {
20792
+ while (1) switch (_context3.n) {
20793
+ case 0:
20794
+ _context3.n = 1;
20795
+ return this.eventEmitter.emitWithResult(EVENT$2.ON_CLICK, {
20796
+ event: EVENT$2.ON_CLICK
20797
+ });
20798
+ case 1:
20799
+ results = _context3.v;
20800
+ if (!results.some(function (r) {
20801
+ return r === false;
20802
+ })) {
20803
+ _context3.n = 2;
20804
+ break;
20805
+ }
20806
+ throw new Error('onClick handler aborted the payment flow');
20807
+ case 2:
20808
+ return _context3.a(2);
19771
20809
  }
19772
- }
19773
- });
20810
+ }, _callee3, this);
20811
+ }));
19774
20812
  }
19775
20813
  }, {
19776
20814
  key: "loadPaymentData",
19777
20815
  value: function loadPaymentData() {
19778
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
19779
- var _this7 = this;
19780
- return _regenerator().w(function (_context3) {
19781
- while (1) switch (_context3.n) {
20816
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
20817
+ var _this6 = this;
20818
+ return _regenerator().w(function (_context4) {
20819
+ while (1) switch (_context4.n) {
19782
20820
  case 0:
19783
- return _context3.a(2, this.paymentsClient.loadPaymentData(this.createPaymentDataRequest())["catch"](function (err) {
19784
- _this7.eventEmitter.emit(EVENT$2.ON_CHECKOUT_CLOSE);
19785
- _this7.processingButtonClick = false;
20821
+ return _context4.a(2, this.paymentsClient.loadPaymentData(this.createPaymentDataRequest())["catch"](function (err) {
20822
+ _this6.eventEmitter.emit(EVENT$2.CHECKOUT_CLOSE, {
20823
+ event: EVENT$2.CHECKOUT_CLOSE
20824
+ });
20825
+ _this6.processingButtonClick = false;
19786
20826
  throw err;
19787
20827
  }));
19788
20828
  }
19789
- }, _callee3, this);
20829
+ }, _callee4, this);
19790
20830
  }));
19791
20831
  }
19792
20832
  }, {
19793
20833
  key: "onPaymentAuthorized",
19794
20834
  value: function onPaymentAuthorized(paymentData) {
19795
- var _this8 = this;
20835
+ var _this7 = this;
19796
20836
  var onPaymentAuthorizedResponse = new Promise(function (resolve) {
19797
- if (_this8.isProcessingAuthorization) {
20837
+ if (_this7.isProcessingAuthorization) {
19798
20838
  console.warn('Duplicate payment authorization detected. Ignoring.');
19799
20839
  resolve({
19800
20840
  transactionState: 'ERROR',
@@ -19806,17 +20846,17 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19806
20846
  });
19807
20847
  return;
19808
20848
  }
19809
- _this8.isProcessingAuthorization = true;
19810
- _this8.createOTT(mapGooglePayData(paymentData, _this8.meta)).then(function () {
19811
- _this8.processingButtonClick = false;
19812
- _this8.isProcessingAuthorization = false;
20849
+ _this7.isProcessingAuthorization = true;
20850
+ _this7.createOTT(mapGooglePayData(paymentData, _this7.meta)).then(function () {
20851
+ _this7.processingButtonClick = false;
20852
+ _this7.isProcessingAuthorization = false;
19813
20853
  resolve({
19814
20854
  transactionState: 'SUCCESS'
19815
20855
  });
19816
20856
  })["catch"](function (error) {
19817
20857
  var _a;
19818
- _this8.processingButtonClick = false;
19819
- _this8.isProcessingAuthorization = false;
20858
+ _this7.processingButtonClick = false;
20859
+ _this7.isProcessingAuthorization = false;
19820
20860
  resolve({
19821
20861
  transactionState: 'ERROR',
19822
20862
  error: {
@@ -19832,69 +20872,75 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19832
20872
  }, {
19833
20873
  key: "onPaymentDataChanged",
19834
20874
  value: function onPaymentDataChanged(intermediatePaymentData) {
19835
- var _this9 = this;
19836
- var _a, _b, _c, _d, _e, _f, _g, _h;
20875
+ var _this8 = this;
20876
+ var _a, _b, _c;
19837
20877
  var returnPromise = new Promise(function (res, rej) {
19838
- _this9.latestShippingChangePromiseResolve = res;
19839
- _this9.latestShippingChangePromiseReject = rej;
20878
+ _this8.latestShippingChangePromiseResolve = res;
20879
+ _this8.latestShippingChangePromiseReject = rej;
19840
20880
  });
19841
- if (intermediatePaymentData.callbackTrigger === 'INITIALIZE') {
19842
- return Promise.resolve(_extends({
19843
- newTransactionInfo: {
19844
- totalPriceStatus: 'FINAL',
19845
- totalPriceLabel: this.meta.amount_label,
19846
- totalPrice: (_a = this.meta.amount) === null || _a === void 0 ? void 0 : _a.toString(),
19847
- currencyCode: (_b = this.meta.currency) === null || _b === void 0 ? void 0 : _b.toUpperCase(),
19848
- countryCode: (_c = this.meta.country) === null || _c === void 0 ? void 0 : _c.toUpperCase()
19849
- }
19850
- }, this.hasShippingOptions() && {
19851
- newShippingOptionParameters: {
19852
- defaultSelectedOptionId: (_e = (_d = this.meta.shipping_options) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id,
19853
- shippingOptions: formatShippingOptions(this.meta.shipping_options)
19854
- }
19855
- }));
19856
- }
19857
20881
  var parsedUpdateData = parseUpdateData(intermediatePaymentData, this.meta);
19858
20882
  var eventData;
19859
- var eventType = GOOGLE_EVENT_TO_WALLET_EVENT[intermediatePaymentData.callbackTrigger];
19860
- if (eventType === EVENT$2.ON_SHIPPING_ADDRESS_CHANGE) {
20883
+ var callbackIntent;
20884
+ if (intermediatePaymentData.callbackTrigger === 'INITIALIZE' || intermediatePaymentData.callbackTrigger === 'SHIPPING_ADDRESS') {
20885
+ callbackIntent = 'SHIPPING_ADDRESS';
19861
20886
  eventData = {
19862
- event: eventType,
20887
+ event: EVENT$2.ON_SHIPPING_ADDRESS_CHANGE,
19863
20888
  data: parsedUpdateData.shipping
19864
20889
  };
19865
- } else if (eventType === EVENT$2.ON_SHIPPING_OPTIONS_CHANGE) {
20890
+ } else if (intermediatePaymentData.callbackTrigger === 'SHIPPING_OPTION') {
20891
+ callbackIntent = 'SHIPPING_OPTION';
19866
20892
  eventData = {
19867
- event: eventType,
20893
+ event: EVENT$2.ON_SHIPPING_OPTIONS_CHANGE,
19868
20894
  data: {
19869
- shipping_option_id: (_f = parsedUpdateData.selected_shipping_option) === null || _f === void 0 ? void 0 : _f.id,
19870
- label: (_g = parsedUpdateData.selected_shipping_option) === null || _g === void 0 ? void 0 : _g.label,
19871
- detail: (_h = parsedUpdateData.selected_shipping_option) === null || _h === void 0 ? void 0 : _h.detail
20895
+ shipping_option_id: (_a = parsedUpdateData.selected_shipping_option) === null || _a === void 0 ? void 0 : _a.id,
20896
+ label: (_b = parsedUpdateData.selected_shipping_option) === null || _b === void 0 ? void 0 : _b.label,
20897
+ detail: (_c = parsedUpdateData.selected_shipping_option) === null || _c === void 0 ? void 0 : _c.detail
19872
20898
  }
19873
20899
  };
19874
20900
  } else {
19875
- this.update({
19876
- success: false
19877
- });
20901
+ // Unknown callback trigger — auto-accept with current data
20902
+ this.autoAcceptWithCurrentData();
19878
20903
  return returnPromise;
19879
20904
  }
19880
- if (eventData) {
19881
- this.handleMerchantOnShippingChangedEvent(eventData).then(function (response) {
19882
- _this9.update({
19883
- success: true,
19884
- body: _extends({
19885
- amount: response.amount
19886
- }, 'shipping_options' in response && response.shipping_options && {
19887
- shipping_options: response.shipping_options
19888
- })
19889
- });
19890
- })["catch"](function () {
19891
- _this9.update({
19892
- success: false
20905
+ this.handleMerchantOnShippingChangedEvent(eventData).then(function (response) {
20906
+ var _a;
20907
+ if ((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.code) {
20908
+ _this8.update({
20909
+ success: false,
20910
+ error: {
20911
+ reason: mapShippingErrorCodeToGooglePayReason(response.error.code),
20912
+ message: response.error.message || 'Shipping update error',
20913
+ intent: callbackIntent
20914
+ }
19893
20915
  });
20916
+ return;
20917
+ }
20918
+ _this8.update({
20919
+ success: true,
20920
+ body: _extends({
20921
+ amount: response.amount
20922
+ }, 'shipping_options' in response && response.shipping_options && {
20923
+ shipping_options: response.shipping_options
20924
+ })
19894
20925
  });
19895
- }
20926
+ })["catch"](function () {
20927
+ // No handler registered or handler threw — auto-accept with current data
20928
+ _this8.autoAcceptWithCurrentData();
20929
+ });
19896
20930
  return returnPromise;
19897
20931
  }
20932
+ }, {
20933
+ key: "autoAcceptWithCurrentData",
20934
+ value: function autoAcceptWithCurrentData() {
20935
+ this.update({
20936
+ success: true,
20937
+ body: _extends({
20938
+ amount: this.meta.amount
20939
+ }, this.hasShippingOptions() && {
20940
+ shipping_options: this.meta.shipping_options
20941
+ })
20942
+ });
20943
+ }
19898
20944
  }, {
19899
20945
  key: "createRequest",
19900
20946
  value: function createRequest() {
@@ -19988,9 +21034,7 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
19988
21034
  var validationErrors = validateCardConfiguration(cardConfig);
19989
21035
  if (validationErrors.length > 0) {
19990
21036
  var errorMessage = validationErrors.join(', ');
19991
- this.handleOnError({
19992
- message: errorMessage
19993
- });
21037
+ this.handleOnError(new Error(errorMessage), ERROR_OPERATION.CONFIGURATION);
19994
21038
  }
19995
21039
  var parameters = {
19996
21040
  allowedAuthMethods: cardConfig.parameters.allowed_auth_methods,
@@ -20033,7 +21077,7 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
20033
21077
  parameters: this.buildCardParameters(cardConfig)
20034
21078
  };
20035
21079
  } catch (error) {
20036
- console.error('Invalid Google Pay card configuration:', error.message);
21080
+ console.error('Invalid Google Pay card configuration:', error instanceof Error ? error.message : error);
20037
21081
  console.warn('Falling back to default card configuration');
20038
21082
  return this.getDefaultCardConfiguration();
20039
21083
  }
@@ -20041,12 +21085,11 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
20041
21085
  }, {
20042
21086
  key: "getMetaStyles",
20043
21087
  value: function getMetaStyles() {
20044
- var _a, _b, _c;
21088
+ var _a, _b;
20045
21089
  if (((_a = this.meta) === null || _a === void 0 ? void 0 : _a.style) && _typeof$1((_b = this.meta) === null || _b === void 0 ? void 0 : _b.style) === 'object') {
20046
- var metaStyles = JSON.parse(JSON.stringify((_c = this.meta) === null || _c === void 0 ? void 0 : _c.style));
20047
- return metaStyles;
21090
+ return JSON.parse(JSON.stringify(this.meta.style));
20048
21091
  }
20049
- return null;
21092
+ return undefined;
20050
21093
  }
20051
21094
  }, {
20052
21095
  key: "isShippingRequired",
@@ -20063,14 +21106,10 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
20063
21106
  }, {
20064
21107
  key: "update",
20065
21108
  value: function update(data) {
20066
- var _a, _b, _c, _d, _e, _f;
21109
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
20067
21110
  if (!this.latestShippingChangePromiseResolve || !this.latestShippingChangePromiseReject) {
20068
21111
  return;
20069
21112
  }
20070
- if (!data.success) {
20071
- this.latestShippingChangePromiseReject();
20072
- return;
20073
- }
20074
21113
  var newAmount = ((_a = data === null || data === void 0 ? void 0 : data.body) === null || _a === void 0 ? void 0 : _a.amount) || this.meta.amount;
20075
21114
  var newShippingOptions = (_b = data === null || data === void 0 ? void 0 : data.body) === null || _b === void 0 ? void 0 : _b.shipping_options;
20076
21115
  if (newAmount) {
@@ -20080,377 +21119,124 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
20080
21119
  this.meta.shipping_options = newShippingOptions;
20081
21120
  this.selectedShippingOption = newShippingOptions ? newShippingOptions[0] : undefined;
20082
21121
  }
20083
- var paymentDataRequestUpdate = _extends({
21122
+ if (!data.success) {
21123
+ this.latestShippingChangePromiseResolve({
21124
+ newTransactionInfo: {
21125
+ totalPriceStatus: 'FINAL',
21126
+ totalPriceLabel: this.meta.amount_label,
21127
+ totalPrice: (_c = this.meta.amount) === null || _c === void 0 ? void 0 : _c.toString(),
21128
+ currencyCode: (_d = this.meta.currency) === null || _d === void 0 ? void 0 : _d.toUpperCase(),
21129
+ countryCode: (_e = this.meta.country) === null || _e === void 0 ? void 0 : _e.toUpperCase()
21130
+ },
21131
+ error: {
21132
+ reason: ((_f = data.error) === null || _f === void 0 ? void 0 : _f.reason) || 'OTHER_ERROR',
21133
+ message: ((_g = data.error) === null || _g === void 0 ? void 0 : _g.message) || 'An error occurred',
21134
+ intent: ((_h = data.error) === null || _h === void 0 ? void 0 : _h.intent) || 'SHIPPING_ADDRESS'
21135
+ }
21136
+ });
21137
+ return;
21138
+ }
21139
+ this.latestShippingChangePromiseResolve(_extends({
20084
21140
  newTransactionInfo: {
20085
21141
  totalPriceStatus: 'FINAL',
20086
21142
  totalPriceLabel: this.meta.amount_label,
20087
- totalPrice: (_c = this.meta.amount) === null || _c === void 0 ? void 0 : _c.toString(),
20088
- currencyCode: (_d = this.meta.currency) === null || _d === void 0 ? void 0 : _d.toUpperCase(),
20089
- countryCode: (_e = this.meta.country) === null || _e === void 0 ? void 0 : _e.toUpperCase()
21143
+ totalPrice: (_j = this.meta.amount) === null || _j === void 0 ? void 0 : _j.toString(),
21144
+ currencyCode: (_k = this.meta.currency) === null || _k === void 0 ? void 0 : _k.toUpperCase(),
21145
+ countryCode: (_l = this.meta.country) === null || _l === void 0 ? void 0 : _l.toUpperCase()
20090
21146
  }
20091
21147
  }, this.isShippingRequired() && this.hasShippingOptions() && newShippingOptions && {
20092
21148
  newShippingOptionParameters: {
20093
- defaultSelectedOptionId: (_f = this.selectedShippingOption) === null || _f === void 0 ? void 0 : _f.id,
21149
+ defaultSelectedOptionId: (_m = this.selectedShippingOption) === null || _m === void 0 ? void 0 : _m.id,
20094
21150
  shippingOptions: formatShippingOptions(this.meta.shipping_options)
20095
21151
  }
20096
- });
20097
- this.latestShippingChangePromiseResolve(paymentDataRequestUpdate);
21152
+ }));
20098
21153
  }
20099
21154
  }]);
20100
21155
  }(OpenWalletService);
20101
21156
 
20102
- var OpenWalletButtons = /*#__PURE__*/function () {
20103
- function OpenWalletButtons(selector, publicKeyOrAccessToken, serviceId, meta, requiredMetaFields) {
20104
- _classCallCheck(this, OpenWalletButtons);
20105
- this.env = DEFAULT_ENV;
20106
- this.eventEmitter = new EventEmitter();
20107
- this.container = new Container(selector);
20108
- this.api = new ApiInternal(publicKeyOrAccessToken, this.getApiAuthType(publicKeyOrAccessToken));
20109
- this.serviceId = serviceId;
20110
- this.meta = meta;
20111
- this.validateRequiredMetaFields(requiredMetaFields);
21157
+ /**
21158
+ * @classdesc Google Pay wallet button that creates One-Time Tokens (OTT) via Google Pay.
21159
+ *
21160
+ * Provides a fully typed Google Pay integration with Google Pay-specific metadata
21161
+ * and validates that the service configuration corresponds to a Google Pay service.
21162
+ * On `load()`, the button fetches the service configuration and raises an error via `onError`
21163
+ * if the service type does not match Google Pay.
21164
+ *
21165
+ * @class GooglePayOpenWalletButton
21166
+ * @extends OpenWalletButtons
21167
+ *
21168
+ * @param {string} selector - CSS selector of the HTML element that will contain the Google Pay button.
21169
+ * @param {string} publicKeyOrAccessToken - Public key or access token for API authentication.
21170
+ * @param {string} serviceId - The Google Pay service ID configured in PayDock dashboard.
21171
+ * @param {GooglePayOpenWalletMeta} meta - Google Pay-specific metadata (amount, currency, country, card_config, merchant_name, style, etc.).
21172
+ *
21173
+ * @example
21174
+ * const button = new GooglePayOpenWalletButton(
21175
+ * '#wallet-container',
21176
+ * publicKeyOrAccessToken,
21177
+ * serviceId,
21178
+ * {
21179
+ * amount: 100,
21180
+ * currency: 'AUD',
21181
+ * country: 'AU',
21182
+ * merchant_name: 'Your Store',
21183
+ * },
21184
+ * );
21185
+ * button.setEnv('sandbox');
21186
+ * button.onSuccess((data) => console.log('OTT:', data.token));
21187
+ * button.onError((error) => console.error('Error:', error));
21188
+ * button.load();
21189
+ */
21190
+ var GooglePayOpenWalletButton = /*#__PURE__*/function (_OpenWalletButtons) {
21191
+ function GooglePayOpenWalletButton() {
21192
+ var _this;
21193
+ _classCallCheck(this, GooglePayOpenWalletButton);
21194
+ _this = _callSuper(this, GooglePayOpenWalletButton, arguments);
21195
+ /** @private */
21196
+ _this.walletType = WALLET_TYPES.GOOGLE_PAY;
21197
+ return _this;
20112
21198
  }
20113
- return _createClass(OpenWalletButtons, [{
20114
- key: "getApiAuthType",
20115
- value: function getApiAuthType(publicKeyOrAccessToken) {
20116
- if (AccessToken.validateJWT(publicKeyOrAccessToken)) {
20117
- return API_AUTH_TYPE.TOKEN;
20118
- }
20119
- return API_AUTH_TYPE.PUBLIC_KEY;
20120
- }
20121
- }, {
20122
- key: "validateRequiredMetaFields",
20123
- value: function validateRequiredMetaFields(requiredFields) {
20124
- var _iterator = _createForOfIteratorHelper(requiredFields),
20125
- _step;
20126
- try {
20127
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
20128
- var field = _step.value;
20129
- if (!(field in this.meta) || this.meta[field] === undefined) {
20130
- throw new Error("Required meta field '".concat(field, "' is missing"));
20131
- }
20132
- }
20133
- } catch (err) {
20134
- _iterator.e(err);
20135
- } finally {
20136
- _iterator.f();
20137
- }
20138
- }
20139
- }, {
20140
- key: "getOpenWalletServiceConfig",
20141
- value: function getOpenWalletServiceConfig() {
20142
- var _this = this;
20143
- var storageKey = "serviceConfig-".concat(this.serviceId);
20144
- var cachedData = localStorage.getItem(storageKey);
20145
- return new Promise(function (resolve, reject) {
20146
- if (cachedData) {
20147
- try {
20148
- var _JSON$parse = JSON.parse(atob(cachedData)),
20149
- data = _JSON$parse.data,
20150
- timestamp = _JSON$parse.timestamp;
20151
- var oneDay = 86400000;
20152
- if (Date.now() - timestamp < oneDay) {
20153
- return resolve(JSON.parse(data));
20154
- }
20155
- } catch (_error) {
20156
- localStorage.removeItem(storageKey);
20157
- }
20158
- }
20159
- _this.api.service().getConfig(_this.serviceId).then(function (serviceConfigResponse) {
20160
- try {
20161
- var encodedData = btoa(JSON.stringify({
20162
- data: JSON.stringify(serviceConfigResponse),
20163
- timestamp: Date.now()
20164
- }));
20165
- localStorage.setItem(storageKey, encodedData);
20166
- return resolve(serviceConfigResponse);
20167
- } catch (_error) {
20168
- return resolve(serviceConfigResponse);
20169
- }
20170
- })["catch"](reject);
20171
- });
20172
- }
20173
- }, {
20174
- key: "handleOnError",
20175
- value: function handleOnError(error) {
20176
- var errorData = {
20177
- error: error,
20178
- context: {
20179
- operation: 'wallet_operation',
20180
- wallet_type: this.walletType
20181
- }
20182
- };
20183
- if (error) {
20184
- console.error('Wallet operation error:', error);
20185
- }
20186
- this.eventEmitter.emit(EVENT$2.ERROR, errorData);
20187
- }
20188
- /**
20189
- * Loads and initializes the wallet button based on the service configuration.
20190
- * This method fetches the wallet service configuration and creates the appropriate wallet service instance.
20191
- * Bear in mind that you must call this method after setting up all event handlers.
20192
- *
20193
- * @example
20194
- * button.load();
20195
- */
20196
- }, {
20197
- key: "load",
20198
- value: function load() {
20199
- var _this2 = this;
20200
- this.getOpenWalletServiceConfig().then(function (serviceConfig) {
20201
- var walletService;
20202
- switch (serviceConfig.type) {
20203
- case SERVICE_TYPES.APPLE_PAY:
20204
- walletService = new ApplePayOpenWalletService(_this2.api, _this2.eventEmitter, _this2.serviceId, _this2.container, _this2.meta, serviceConfig);
20205
- break;
20206
- case SERVICE_TYPES.GOOGLE_PAY:
20207
- walletService = new GooglePayOpenWalletService(_this2.api, _this2.eventEmitter, _this2.serviceId, _this2.container, _this2.meta, serviceConfig);
20208
- break;
20209
- }
20210
- if (!walletService) {
20211
- _this2.handleOnError(new Error("Invalid service type: ".concat(serviceConfig.type)));
20212
- return;
20213
- }
20214
- walletService.load();
20215
- })["catch"](function (error) {
20216
- _this2.handleOnError(error);
20217
- });
20218
- }
20219
- /**
20220
- * Current method can change environment. By default environment = sandbox.
20221
- * Also we can change domain alias for this environment. By default domain_alias = paydock.com
20222
- * Bear in mind that you must set an environment before calling `button.load()`.
20223
- *
20224
- * @example
20225
- * button.setEnv('production', 'paydock.com');
20226
- * @param {string} env - sandbox, production
20227
- * @param {string} [alias] - Own domain alias
20228
- */
20229
- }, {
20230
- key: "setEnv",
20231
- value: function setEnv(env, alias) {
20232
- this.env = env;
20233
- this.api.setEnv(env, alias);
20234
- }
20235
- /**
20236
- * Callback for onClick method.
20237
- *
20238
- * @callback OnClickCallback
20239
- * @param {OnClickEventData} data
20240
- */
20241
- /**
20242
- /**
20243
- * Registers a callback function to be invoked when the wallet button gets clicked.
20244
- * There are two operational modes supported, Synchronous and Asynchronous.
20245
- * When asynchronous operations need to occur on the callback handler, attaching the Promise via `attachResult` is required to have the wallet wait for a result.
20246
- * When synchronous operations occur on the callback handler, attaching a boolean result via `attachResult` is optional to control the execution flow.
20247
- * Note this is supported for Paypal, GooglePay and ApplePay wallet buttons at the moment.
20248
- *
20249
- * @example
20250
- * button.onClick((data) => {
20251
- * performValidationLogic();
20252
- * });
20253
- *
20254
- * @param {listener} handler - Function to be called when the wallet button is clicked.
20255
- */
20256
- }, {
20257
- key: "onClick",
20258
- value: function onClick(handler) {
20259
- if (typeof handler === 'function') {
20260
- return this.eventEmitter.subscribe(EVENT$2.ON_CLICK, handler);
20261
- }
20262
- }
20263
- /**
20264
- * Callback for onSuccess method.
20265
- *
20266
- * @callback OnSuccessCallback
20267
- * @param {OnCrateOTTSuccessfulEventData} data
20268
- * @return {Promise<string>} OTT (One Time Token) string result
20269
- */
20270
- /**
20271
- * If the OTT creation was successful, the function passed as parameter will be called.
20272
- * Important: Do not perform thread blocking operations in callback such as window.alert() calls.
20273
- *
20274
- * @example
20275
- * button.onSuccess((data) => {
20276
- * console.log('OTT creation successful!', data);
20277
- * });
20278
- *
20279
- * @example
20280
- * button.onSuccess().then((data) => console.log('OTT creation successful!', data));
20281
- *
20282
- * @param {OnSuccessCallback} [handler] - Function to be called when the OTT creation was successful.
20283
- */
20284
- }, {
20285
- key: "onSuccess",
20286
- value: function onSuccess(handler) {
20287
- if (typeof handler === 'function') {
20288
- return this.eventEmitter.subscribe(EVENT$2.SUCCESS, handler);
20289
- }
20290
- this.handleOnError(new Error('onSuccess event handler is required to receive the OTT token string.'));
20291
- }
20292
- /**
20293
- * Callback for onUnavailable method.
20294
- *
20295
- * @callback OnUnavailableCallback
20296
- * @param {OnUnavailableEventData} data
20297
- */
20298
- /**
20299
- * Registers a callback function to be invoked when the wallet is not available in the current context.
20300
- * This can happen when the wallet service is not supported on the current device or browser.
20301
- *
20302
- * @example
20303
- * button.onUnavailable((data) => {
20304
- * console.log('Wallet not available', data);
20305
- * });
20306
- *
20307
- * @example
20308
- * button.onUnavailable().then((data) => console.log('Wallet not available', data));
20309
- *
20310
- * @param {OnUnavailableCallback} [handler] - Function to be called when the wallet is not available in the current context.
20311
- */
20312
- }, {
20313
- key: "onUnavailable",
20314
- value: function onUnavailable(handler) {
20315
- var _this3 = this;
20316
- if (typeof handler === 'function') {
20317
- return this.eventEmitter.subscribe(EVENT$2.UNAVAILABLE, handler);
20318
- }
20319
- return new Promise(function (resolve) {
20320
- return _this3.eventEmitter.subscribe(EVENT$2.UNAVAILABLE, function (data) {
20321
- return resolve(data);
20322
- });
20323
- });
20324
- }
20325
- /**
20326
- * Callback for onError method.
20327
- *
20328
- * @callback OnErrorCallback
20329
- * @param {OnErrorEventData} data
20330
- */
20331
- /**
20332
- * Registers a callback function to be invoked when an error that is not related to payment execution occurs.
20333
- * For example, if there are configuration issues or validation errors during wallet initialization.
20334
- *
20335
- * @example
20336
- * button.onError((error) => {
20337
- * console.log('OpenWallet error', error);
20338
- * });
20339
- *
20340
- * @example
20341
- * button.onError().then((error) => console.log('OpenWallet error', error));
20342
- *
20343
- * @param {OnErrorCallback} [handler] - Function to be called when the OpenWallet has an error.
20344
- */
20345
- }, {
20346
- key: "onError",
20347
- value: function onError(handler) {
20348
- var _this4 = this;
20349
- if (typeof handler === 'function') {
20350
- return this.eventEmitter.subscribe(EVENT$2.ERROR, handler);
20351
- }
20352
- return new Promise(function (resolve) {
20353
- return _this4.eventEmitter.subscribe(EVENT$2.ERROR, function (data) {
20354
- return resolve(data);
20355
- });
20356
- });
20357
- }
20358
- /**
20359
- * Callback for onCancel method.
20360
- *
20361
- * @callback OnCancelCallback
20362
- * @param {any} data
20363
- */
20364
- /**
20365
- * Registers a callback function to be invoked when the wallet checkout is cancelled or closed by the user.
20366
- * This event is triggered when the user dismisses the wallet payment interface without completing the transaction.
20367
- *
20368
- * @example
20369
- * button.onCancel((data) => {
20370
- * console.log('Wallet checkout cancelled', data);
20371
- * });
20372
- *
20373
- * @example
20374
- * button.onCancel().then((data) => console.log('Wallet checkout cancelled', data));
20375
- *
20376
- * @param {OnCancelCallback} [handler] - Function to be called when the wallet checkout is cancelled.
20377
- */
20378
- }, {
20379
- key: "onCancel",
20380
- value: function onCancel(handler) {
20381
- var _this5 = this;
20382
- if (typeof handler === 'function') {
20383
- return this.eventEmitter.subscribe(EVENT$2.CHECKOUT_CLOSE, handler);
20384
- }
20385
- return new Promise(function (resolve) {
20386
- return _this5.eventEmitter.subscribe(EVENT$2.CHECKOUT_CLOSE, function (data) {
20387
- return resolve(data);
20388
- });
20389
- });
21199
+ /**
21200
+ * Validates Google Pay-specific required metadata fields.
21201
+ * Google Pay has no additional required fields beyond the base (amount, currency, country).
21202
+ * @private
21203
+ */
21204
+ _inherits(GooglePayOpenWalletButton, _OpenWalletButtons);
21205
+ return _createClass(GooglePayOpenWalletButton, [{
21206
+ key: "validateWalletMeta",
21207
+ value: function validateWalletMeta() {
21208
+ // Google Pay has no additional required meta fields beyond the base.
21209
+ // Optional fields (merchant_name, card_config, etc.) are validated
21210
+ // at runtime by the Google Pay SDK.
20390
21211
  }
20391
21212
  /**
20392
- * Callback for onShippingAddressChange method.
20393
- *
20394
- * @callback OnShippingAddressChangeCallback
20395
- * @param {OnShippingAddressChangeEventData} data
20396
- * @return {Promise<OnShippingAddressChangeEventResponse>} Address update result containing updated amount and/or shipping options
20397
- */
20398
- /**
20399
- * If shipping address data is updated, the function passed as parameter will be called.
20400
- * Use this method to listen for shipping address selection or input from customer when shipping is enabled.
20401
- * The event handler should return updated payment information including the new amount and available shipping options based on the selected address.
20402
- *
20403
- * @example
20404
- * button.onShippingAddressChange(async (data) => {
20405
- * const responseData = await fetch('https://your-server.com/update-shipping-address');
20406
- * return {
20407
- * amount: responseData.newAmount,
20408
- * shipping_options: responseData.availableShippingOptions
20409
- * };
20410
- * });
21213
+ * Validates that the service configuration type is Google Pay.
20411
21214
  *
20412
- * @param {OnShippingAddressChangeCallback} [handler] - Function to be called when the shipping address data is updated.
21215
+ * @private
21216
+ * @param serviceConfig - The service configuration response from the API.
21217
+ * @throws {Error} If the service type is not Google Pay.
20413
21218
  */
20414
21219
  }, {
20415
- key: "onShippingAddressChange",
20416
- value: function onShippingAddressChange(handler) {
20417
- if (typeof handler === 'function') {
20418
- return this.eventEmitter.subscribe(EVENT$2.ON_SHIPPING_ADDRESS_CHANGE, handler);
21220
+ key: "validateServiceType",
21221
+ value: function validateServiceType(serviceConfig) {
21222
+ if (serviceConfig.type !== SERVICE_TYPES.GOOGLE_PAY) {
21223
+ throw new Error("Service configuration type '".concat(serviceConfig.type, "' does not match expected wallet type '").concat(WALLET_TYPES.GOOGLE_PAY, "'. ") + "Ensure the service ID '".concat(this.serviceId, "' corresponds to a Google Pay service."));
20419
21224
  }
20420
- this.handleOnError(new Error('onShippingAddressChange event handler is required.'));
20421
21225
  }
20422
21226
  /**
20423
- * Callback for onShippingOptionsChange method.
21227
+ * Creates a Google Pay wallet service instance.
20424
21228
  *
20425
- * @callback OnShippingOptionsChangeCallback
20426
- * @param {OnShippingOptionChangeEventData} data
20427
- * @return {Promise<OnShippingOptionChangeEventResponse>} Shipping options update result containing updated amount
20428
- */
20429
- /**
20430
- * If shipping options data is updated, the function passed as parameter will be called.
20431
- * Use this method to listen for shipping option selection from customer when shipping is enabled.
20432
- * The event handler should return the updated payment amount based on the selected shipping option.
20433
- *
20434
- * @example
20435
- * button.onShippingOptionsChange(async (data) => {
20436
- * const responseData = await fetch('https://your-server.com/update-shipping-option');
20437
- * return {
20438
- * amount: responseData.newTotalAmount
20439
- * };
20440
- * });
20441
- *
20442
- * @param {OnShippingOptionsChangeCallback} [handler] - Function to be called when the shipping options data is updated.
21229
+ * @private
21230
+ * @param serviceConfig - The service configuration response from the API.
21231
+ * @returns The Google Pay wallet service instance.
20443
21232
  */
20444
21233
  }, {
20445
- key: "onShippingOptionsChange",
20446
- value: function onShippingOptionsChange(handler) {
20447
- if (typeof handler === 'function') {
20448
- return this.eventEmitter.subscribe(EVENT$2.ON_SHIPPING_OPTIONS_CHANGE, handler);
20449
- }
20450
- this.handleOnError(new Error('onShippingOptionsChange event handler is required.'));
21234
+ key: "createWalletService",
21235
+ value: function createWalletService(serviceConfig) {
21236
+ return new GooglePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
20451
21237
  }
20452
21238
  }]);
20453
- }();
21239
+ }(OpenWalletButtons);
20454
21240
 
20455
21241
  /**
20456
21242
  *
@@ -41454,4 +42240,4 @@ var browser = /*#__PURE__*/Object.freeze({
41454
42240
  strToU8: strToU8
41455
42241
  });
41456
42242
 
41457
- export { AfterpayCheckoutButton, AfterpayOnSiteMessaging, Api, ApplePayWalletButtonExpress, CHECKOUT_BUTTON_EVENT, Canvas3ds, Checkout, ClickToPay, Configuration, ELEMENT, EVENT$5 as EVENT, Builder$1 as ExternalCheckoutBuilder, Checker as ExternalCheckoutChecker, FORM_FIELD$1 as FORM_FIELD, FRAUD_PREVENTION_EVENTS, FraudPreventionService, HtmlMultiWidget, HtmlPaymentSourceWidget, HtmlWidget, InstructionDebugger, MultiWidget, OpenWalletButtons, PAYMENT_TYPE, PURPOSE, PayPalDataCollector, PayPalSavePaymentSourceWidget, Builder as PaymentSourceBuilder, PaymentSourceWidget, PaypalCheckoutButton, PaypalWalletButtonExpress, STYLABLE_ELEMENT, STYLABLE_ELEMENT_STATE, STYLE$2 as STYLE, SUPPORTED_CARD_TYPES, TEXT, TRIGGER$1 as TRIGGER, TYPE, VAULT_DISPLAY_STYLE, VaultDisplayWidget, WALLET_TYPES, WalletButtons, ZipmoneyCheckoutButton };
42243
+ export { AfterpayCheckoutButton, AfterpayOnSiteMessaging, Api, ApplePayOpenWalletButton, ApplePayWalletButtonExpress, CHECKOUT_BUTTON_EVENT, Canvas3ds, Checkout, ClickToPay, Configuration, ELEMENT, ERROR_OPERATION, EVENT$5 as EVENT, Builder$1 as ExternalCheckoutBuilder, Checker as ExternalCheckoutChecker, FORM_FIELD$1 as FORM_FIELD, FRAUD_PREVENTION_EVENTS, FraudPreventionService, GooglePayOpenWalletButton, HtmlMultiWidget, HtmlPaymentSourceWidget, HtmlWidget, InstructionDebugger, MultiWidget, OpenWalletButtons, PAYMENT_TYPE, PURPOSE, PayPalDataCollector, PayPalSavePaymentSourceWidget, Builder as PaymentSourceBuilder, PaymentSourceWidget, PaypalCheckoutButton, PaypalWalletButtonExpress, STYLABLE_ELEMENT, STYLABLE_ELEMENT_STATE, STYLE$2 as STYLE, SUPPORTED_CARD_TYPES, TEXT, TOKEN_TYPE, TRIGGER$1 as TRIGGER, TYPE, VAULT_DISPLAY_STYLE, VaultDisplayWidget, WALLET_TYPES, WalletButtons, ZipmoneyCheckoutButton };