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