@tap-payments/apple-pay-button 0.0.37-development → 0.0.37-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/build/@types/ApplePayButtonProps.d.ts +129 -0
  2. package/build/@types/ApplePayButtonProps.js +1 -0
  3. package/build/@types/charge.d.ts +57 -0
  4. package/build/@types/charge.js +1 -0
  5. package/build/@types/checkoutProfile.d.ts +195 -0
  6. package/build/@types/checkoutProfile.js +1 -0
  7. package/build/@types/enums.d.ts +65 -0
  8. package/build/@types/enums.js +76 -0
  9. package/build/@types/index.d.ts +6 -122
  10. package/build/@types/index.js +6 -1
  11. package/build/@types/tapLocalisation.d.ts +193 -0
  12. package/build/@types/tapLocalisation.js +1 -0
  13. package/build/@types/tapTheme.d.ts +842 -0
  14. package/build/@types/tapTheme.js +1 -0
  15. package/build/api.d.ts +29 -0
  16. package/build/{api/app.service.js → api.js} +87 -95
  17. package/build/constants/index.d.ts +2 -58
  18. package/build/constants/index.js +2 -58
  19. package/build/features/ApplePayButton/ApplePayButton.d.ts +3 -5
  20. package/build/features/ApplePayButton/ApplePayButton.js +8 -14
  21. package/build/features/ApplePayButton/index.d.ts +2 -2
  22. package/build/hooks/index.d.ts +0 -2
  23. package/build/hooks/index.js +0 -2
  24. package/build/hooks/useApplePay.d.ts +89 -5
  25. package/build/hooks/useApplePay.js +289 -117
  26. package/build/hooks/useMerchantApplePay.d.ts +20 -0
  27. package/build/hooks/useMerchantApplePay.js +176 -0
  28. package/build/index.d.ts +4 -6
  29. package/build/index.js +3 -9
  30. package/build/utils/config.d.ts +10 -9
  31. package/build/utils/config.js +40 -47
  32. package/build/utils/defaultValues.d.ts +2 -30
  33. package/build/utils/defaultValues.js +10 -31
  34. package/build/utils/index.d.ts +3 -0
  35. package/build/utils/index.js +3 -0
  36. package/build/utils/theme.d.ts +12 -0
  37. package/build/utils/theme.js +61 -0
  38. package/package.json +16 -11
  39. package/build/api/app.service.d.ts +0 -23
  40. package/build/api/base.d.ts +0 -9
  41. package/build/api/base.js +0 -45
  42. package/build/api/httpClient.d.ts +0 -8
  43. package/build/api/httpClient.js +0 -33
  44. package/build/features/ApplePayButton/ApplePayButton.css +0 -21
  45. package/build/hooks/useApplePayFromMerchantSide.d.ts +0 -11
  46. package/build/hooks/useApplePayFromMerchantSide.js +0 -177
  47. package/build/hooks/useScript.d.ts +0 -1
  48. package/build/hooks/useScript.js +0 -39
package/build/api/base.js DELETED
@@ -1,45 +0,0 @@
1
- var BaseService = (function () {
2
- function BaseService(httpClient) {
3
- Object.defineProperty(this, "httpClient", {
4
- enumerable: true,
5
- configurable: true,
6
- writable: true,
7
- value: void 0
8
- });
9
- this.httpClient = httpClient;
10
- }
11
- Object.defineProperty(BaseService.prototype, "get", {
12
- enumerable: false,
13
- configurable: true,
14
- writable: true,
15
- value: function (url, config) {
16
- return this.httpClient.get(url, config);
17
- }
18
- });
19
- Object.defineProperty(BaseService.prototype, "post", {
20
- enumerable: false,
21
- configurable: true,
22
- writable: true,
23
- value: function (url, data, config) {
24
- return this.httpClient.post(url, data, config);
25
- }
26
- });
27
- Object.defineProperty(BaseService.prototype, "put", {
28
- enumerable: false,
29
- configurable: true,
30
- writable: true,
31
- value: function (url, data, config) {
32
- return this.httpClient.put(url, data, config);
33
- }
34
- });
35
- Object.defineProperty(BaseService.prototype, "delete", {
36
- enumerable: false,
37
- configurable: true,
38
- writable: true,
39
- value: function (url, config) {
40
- return this.httpClient.delete(url, config);
41
- }
42
- });
43
- return BaseService;
44
- }());
45
- export default BaseService;
@@ -1,8 +0,0 @@
1
- export declare const MW_BASE_LIVE_URL = "https://mw-sdk.tap.company/v2/checkout";
2
- export declare const MW_BASE_STAGING_URL = "https://mw-sdk.staging.tap.company/v2/checkout";
3
- export declare const MW_BASE_DEV_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
4
- export declare const MW_BASE_BETA_URL = "https://mw-sdk.beta.tap.company/v2/checkout";
5
- export declare const MW_BASE_SANDBOX_URL = "https://mw-sdk.sandbox.tap.company/v2/checkout";
6
- declare const httpClient: import("axios").AxiosInstance;
7
- export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
8
- export default httpClient;
@@ -1,33 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import axios from 'axios';
13
- export var MW_BASE_LIVE_URL = 'https://mw-sdk.tap.company/v2/checkout';
14
- export var MW_BASE_STAGING_URL = 'https://mw-sdk.staging.tap.company/v2/checkout';
15
- export var MW_BASE_DEV_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
16
- export var MW_BASE_BETA_URL = 'https://mw-sdk.beta.tap.company/v2/checkout';
17
- export var MW_BASE_SANDBOX_URL = 'https://mw-sdk.sandbox.tap.company/v2/checkout';
18
- var httpClient = axios.create({
19
- headers: {
20
- 'Content-Type': 'application/json',
21
- Accept: 'application/json'
22
- }
23
- });
24
- httpClient.interceptors.request.use(function (config) {
25
- return config;
26
- });
27
- httpClient.interceptors.response.use(function (response) {
28
- return response;
29
- });
30
- export var setAxiosGlobalHeaders = function (headers) {
31
- httpClient.defaults.headers.common = __assign(__assign({}, httpClient.defaults.headers.common), headers);
32
- };
33
- export default httpClient;
@@ -1,21 +0,0 @@
1
- .button-applepay-tap {
2
- -webkit-appearance: -apple-pay-button;
3
- display: block;
4
- width: 100%;
5
- height: 48px;
6
- min-height: 30px;
7
- cursor: pointer;
8
- }
9
- .button-applepay-tap:disabled {
10
- cursor: default;
11
- }
12
- .black {
13
- -apple-pay-button-style: black;
14
- }
15
- .white {
16
- -apple-pay-button-style: white;
17
- }
18
- .whiteOutline {
19
- -apple-pay-button-style: white;
20
- border: solid 1px gray;
21
- }
@@ -1,11 +0,0 @@
1
- export declare enum ApplePayGetFromMerchantEvents {
2
- APPLE_PAY_CLICKED = "APPLE_PAY_CLICKED"
3
- }
4
- export declare enum ApplePayPostFromMerchantEvents {
5
- APPLE_PAY_BUTTON_READY = "APPLE_PAY_BUTTON_READY",
6
- APPLE_PAY_BUTTON_SUCCESS = "APPLE_PAY_BUTTON_SUCCESS",
7
- APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS = "APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS",
8
- APPLE_PAY_BUTTON_ERROR = "APPLE_PAY_BUTTON_ERROR",
9
- APPLE_PAY_BUTTON_CANCELLED = "APPLE_PAY_BUTTON_CANCELLED"
10
- }
11
- export declare const useApplePayFromMerchantSide: (frameId: string) => void;
@@ -1,177 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import { useCallback, useEffect } from 'react';
49
- import appService from '../api/app.service';
50
- import { setAxiosGlobalHeaders } from '../api/httpClient';
51
- export var ApplePayGetFromMerchantEvents;
52
- (function (ApplePayGetFromMerchantEvents) {
53
- ApplePayGetFromMerchantEvents["APPLE_PAY_CLICKED"] = "APPLE_PAY_CLICKED";
54
- })(ApplePayGetFromMerchantEvents || (ApplePayGetFromMerchantEvents = {}));
55
- export var ApplePayPostFromMerchantEvents;
56
- (function (ApplePayPostFromMerchantEvents) {
57
- ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_READY"] = "APPLE_PAY_BUTTON_READY";
58
- ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_SUCCESS"] = "APPLE_PAY_BUTTON_SUCCESS";
59
- ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS"] = "APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS";
60
- ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_ERROR"] = "APPLE_PAY_BUTTON_ERROR";
61
- ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_CANCELLED"] = "APPLE_PAY_BUTTON_CANCELLED";
62
- })(ApplePayPostFromMerchantEvents || (ApplePayPostFromMerchantEvents = {}));
63
- var usePostEventsToIframe = function (frameId) {
64
- var send = function (event, data) {
65
- var _a;
66
- var frame = document.getElementById(frameId);
67
- if (!frame)
68
- return;
69
- (_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ event: event, data: data }, frame.src);
70
- };
71
- return {
72
- send: send
73
- };
74
- };
75
- export var useApplePayFromMerchantSide = function (frameId) {
76
- var send = usePostEventsToIframe(frameId).send;
77
- var onApplePayButtonClicked = function (applePaymentOptionsMetaData) { return __awaiter(void 0, void 0, void 0, function () {
78
- var ApplePaySession, _a, merchant, supportedNetworks, transaction, billingContact, merchantCapabilities, debug, applePaySDKVersion, headers, merchantRegisteredDomain, environment, request, session;
79
- return __generator(this, function (_b) {
80
- send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_READY, {});
81
- ApplePaySession = window.ApplePaySession;
82
- if (!ApplePaySession) {
83
- console.error('ApplePaySession is not available, please check if you are using Safari browser');
84
- return [2];
85
- }
86
- if (!applePaymentOptionsMetaData) {
87
- console.error('Make sure you have passed prerequisites options for Apple Pay');
88
- return [2];
89
- }
90
- _a = __assign(__assign({}, applePaymentOptionsMetaData), { merchantRegisteredDomain: window.location.hostname }), merchant = _a.merchant, supportedNetworks = _a.supportedNetworks, transaction = _a.transaction, billingContact = _a.billingContact, merchantCapabilities = _a.merchantCapabilities, debug = _a.debug, applePaySDKVersion = _a.applePaySDKVersion, headers = _a.headers, merchantRegisteredDomain = _a.merchantRegisteredDomain, environment = _a.environment;
91
- if (debug)
92
- console.log('apple payment options metadata', applePaymentOptionsMetaData);
93
- appService.setEnv(environment);
94
- appService.setBaseUrl();
95
- request = {
96
- countryCode: merchant.country_code,
97
- currencyCode: transaction.currency,
98
- merchantCapabilities: merchantCapabilities,
99
- supportedNetworks: supportedNetworks,
100
- billingContact: billingContact && {
101
- phoneNumber: billingContact.phoneNumber,
102
- emailAddress: billingContact.emailAddress,
103
- givenName: billingContact.givenName,
104
- familyName: billingContact.familyName
105
- },
106
- total: {
107
- amount: Number(transaction.amount),
108
- label: merchant.name
109
- }
110
- };
111
- if (debug) {
112
- console.info("Creating ApplePaySession with version: ".concat(applePaySDKVersion, " and request: ").concat(JSON.stringify(request)));
113
- }
114
- session = new ApplePaySession(applePaySDKVersion, request);
115
- session.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
116
- var data, error_1;
117
- var _a;
118
- return __generator(this, function (_b) {
119
- switch (_b.label) {
120
- case 0:
121
- if (debug) {
122
- console.info('Creating merchant session and validating merchant session');
123
- console.info('onvalidatemerchant event', event);
124
- }
125
- _b.label = 1;
126
- case 1:
127
- _b.trys.push([1, 3, , 4]);
128
- setAxiosGlobalHeaders(headers);
129
- return [4, appService.appleSession(__assign({}, merchant), event.validationURL, merchantRegisteredDomain)];
130
- case 2:
131
- data = _b.sent();
132
- if (debug)
133
- console.info('merchant session created', data);
134
- session.completeMerchantValidation(data);
135
- send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS, data);
136
- return [3, 4];
137
- case 3:
138
- error_1 = _b.sent();
139
- if (debug)
140
- console.error('error in onvalidatemerchant', error_1);
141
- session.completePayment({ status: ApplePaySession.STATUS_FAILURE });
142
- send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_ERROR, ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) || error_1.message);
143
- return [3, 4];
144
- case 4: return [2];
145
- }
146
- });
147
- }); };
148
- session.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
149
- return __generator(this, function (_a) {
150
- if (debug)
151
- console.info('onpaymentauthorized event', event);
152
- send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_SUCCESS, event.payment.token.paymentData);
153
- session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
154
- return [2];
155
- });
156
- }); };
157
- session.oncancel = function (event) {
158
- console.info('oncancel event', event);
159
- send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_CANCELLED, event);
160
- };
161
- session.begin();
162
- return [2];
163
- });
164
- }); };
165
- var onMessage = useCallback(function (message) {
166
- var _a = message.data, event = _a.event, data = _a.data;
167
- if (event === ApplePayGetFromMerchantEvents.APPLE_PAY_CLICKED) {
168
- onApplePayButtonClicked(data);
169
- }
170
- }, []);
171
- useEffect(function () {
172
- window.addEventListener('message', onMessage);
173
- return function () {
174
- window.removeEventListener('message', onMessage);
175
- };
176
- }, []);
177
- };
@@ -1 +0,0 @@
1
- export declare function useScript(src: string, async?: boolean): "error" | "loading" | "ready" | "idle";
@@ -1,39 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- export function useScript(src, async) {
3
- if (async === void 0) { async = true; }
4
- var _a = useState(src ? 'loading' : 'idle'), status = _a[0], setStatus = _a[1];
5
- useEffect(function () {
6
- if (!src) {
7
- setStatus('idle');
8
- return;
9
- }
10
- var script = document.querySelector("script[src=\"".concat(src, "\"]"));
11
- if (!script) {
12
- script = document.createElement('script');
13
- script.src = src;
14
- script.async = async;
15
- script.setAttribute('data-status', 'loading');
16
- document.body.appendChild(script);
17
- var setAttributeFromEvent = function (event) {
18
- script.setAttribute('data-status', event.type === 'load' ? 'ready' : 'error');
19
- };
20
- script.addEventListener('load', setAttributeFromEvent);
21
- script.addEventListener('error', setAttributeFromEvent);
22
- }
23
- else {
24
- setStatus(script.getAttribute('data-status'));
25
- }
26
- var setStateFromEvent = function (event) {
27
- setStatus(event.type === 'load' ? 'ready' : 'error');
28
- };
29
- script.addEventListener('load', setStateFromEvent);
30
- script.addEventListener('error', setStateFromEvent);
31
- return function () {
32
- if (script) {
33
- script.removeEventListener('load', setStateFromEvent);
34
- script.removeEventListener('error', setStateFromEvent);
35
- }
36
- };
37
- }, [src]);
38
- return status;
39
- }