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