@tap-payments/apple-pay-button 1.1.5 → 1.2.0-staging

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.
@@ -57,3 +57,4 @@ export declare const RSA_SANDBOX_MW_PUBLIC_KEY = "";
57
57
  export declare const RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
58
58
  export declare const RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
59
59
  export declare const RSA_PRODUCTION_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
60
+ export declare const APPLE_PAY_SCRIPT = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
@@ -57,3 +57,4 @@ export var RSA_SANDBOX_MW_PUBLIC_KEY = "";
57
57
  export var RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
58
58
  export var RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
59
59
  export var RSA_PRODUCTION_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
60
+ export var APPLE_PAY_SCRIPT = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
@@ -32,15 +32,25 @@ var ApplePay = React.memo(function (props) {
32
32
  console.log('ApplePayButtonProps', props);
33
33
  }
34
34
  }, []);
35
- return (_jsx("button", { className: 'button-applepay-tap', style: {
36
- ApplePayButtonType: mappedProps.interface.type,
37
- ApplePayButtonStyle: mappedProps.interface.theme === ThemeMode.DARK ? ButtonStyle.Black : ButtonStyle.White,
38
- borderRadius: mappedProps.interface.edges === Edges.STRAIGHT ? '0' : '10px'
39
- }, onClick: function () {
35
+ React.useEffect(function () {
36
+ var lisnterCallback = function (e) {
40
37
  var _a;
38
+ e.preventDefault();
41
39
  onApplePayButtonClicked();
42
40
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
43
- }, lang: mappedProps.interface.locale, disabled: loading || disabled }));
41
+ };
42
+ var applepayButton = document.getElementById('tap-apple-pay-button');
43
+ applepayButton === null || applepayButton === void 0 ? void 0 : applepayButton.addEventListener('click', lisnterCallback);
44
+ return function () {
45
+ applepayButton === null || applepayButton === void 0 ? void 0 : applepayButton.removeEventListener('click', lisnterCallback);
46
+ };
47
+ }, [onApplePayButtonClicked]);
48
+ return (_jsx("apple-pay-button", { id: 'tap-apple-pay-button', style: {
49
+ '--apple-pay-button-width': '100%',
50
+ '--apple-pay-button-height': '48px',
51
+ '--apple-pay-button-border-radius': mappedProps.interface.edges === Edges.STRAIGHT ? '0' : '10px',
52
+ cursor: loading || disabled ? 'default' : 'pointer'
53
+ }, buttonstyle: mappedProps.interface.theme === ThemeMode.DARK ? ButtonStyle.Black : ButtonStyle.White, type: mappedProps.interface.type, locale: mappedProps.interface.locale }));
44
54
  });
45
55
  export function ApplePayButton(props) {
46
56
  return _jsx(ApplePay, __assign({}, props));
@@ -62,12 +62,14 @@ import { ApplePayVersion } from '../constants';
62
62
  import { setAxiosGlobalHeaders } from '../api/httpClient';
63
63
  import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
64
64
  import { getMerchantCapaplities } from '../utils/defaultValues';
65
+ import { useApplePayScript } from './useApplePayScript';
65
66
  export var useApplePay = function (_a) {
66
67
  var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, interfaceObj = _a.interface, customer = _a.customer, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, acceptance = _a.acceptance, features = _a.features, metaData = _a.metaData, debug = _a.debug, environment = _a.environment, platform = _a.platform, onReady = _a.onReady, onMerchantValidation = _a.onMerchantValidation, onShippingMethodSelected = _a.onShippingMethodSelected, onShippingContactSelected = _a.onShippingContactSelected, onPaymentMethodSelected = _a.onPaymentMethodSelected, onCouponChanged = _a.onCouponChanged;
67
68
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
68
69
  var _c = useState(null), profileData = _c[0], setProfile = _c[1];
69
70
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
70
71
  var _e = useState(undefined), applePaySession = _e[0], setApplePaySession = _e[1];
72
+ var isScriptLoaded = useApplePayScript(onError);
71
73
  var abortApplePaySession = useCallback(function () {
72
74
  applePaySession === null || applePaySession === void 0 ? void 0 : applePaySession.abort();
73
75
  }, [applePaySession]);
@@ -143,8 +145,10 @@ export var useApplePay = function (_a) {
143
145
  });
144
146
  }); }, [environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, merchant.domain, publicKey, debug, onError]);
145
147
  useEffect(function () {
148
+ if (!isScriptLoaded)
149
+ return;
146
150
  initialize(metaData);
147
- }, [initialize, metaData]);
151
+ }, [isScriptLoaded, initialize, metaData]);
148
152
  var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
149
153
  var ApplePaySession, paymentMethod, currency, cardBrands, request, session_1;
150
154
  var _a;
@@ -0,0 +1 @@
1
+ export declare const useApplePayScript: (onError?: ((error: any) => void) | undefined) => boolean;
@@ -0,0 +1,11 @@
1
+ import { APPLE_PAY_SCRIPT } from '../constants';
2
+ import { useEffect } from 'react';
3
+ import { useScript } from './useScript';
4
+ export var useApplePayScript = function (onError) {
5
+ var bStatus = useScript(APPLE_PAY_SCRIPT);
6
+ useEffect(function () {
7
+ if (bStatus === 'error')
8
+ onError === null || onError === void 0 ? void 0 : onError('Apple Pay loading script error');
9
+ }, [bStatus]);
10
+ return bStatus === 'ready';
11
+ };
@@ -1 +1 @@
1
- export declare function useScript(src: string, async?: boolean): "error" | "loading" | "ready" | "idle";
1
+ export declare function useScript(src: string, async?: boolean): "error" | "ready" | "loading" | "idle";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "1.1.5",
3
+ "version": "1.2.0-staging",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",
@@ -20,7 +20,7 @@
20
20
  "copy:files": "copyfiles -u 1 src/**/*.css build/",
21
21
  "tsc:alias": "tsc-alias -p tsconfig.json",
22
22
  "ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
23
- "push": "npm publish --access public"
23
+ "push": "npm publish --access public --tag staging"
24
24
  },
25
25
  "keywords": [],
26
26
  "author": {