@tap-payments/apple-pay-button 0.0.3 → 0.0.4-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.
Files changed (51) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +240 -194
  3. package/build/@types/ApplePayButtonProps.d.ts +129 -0
  4. package/build/@types/ApplePayButtonProps.js +1 -0
  5. package/build/@types/charge.d.ts +57 -0
  6. package/build/@types/charge.js +1 -0
  7. package/build/@types/checkoutProfile.d.ts +216 -0
  8. package/build/@types/checkoutProfile.js +1 -0
  9. package/build/@types/enums.d.ts +65 -0
  10. package/build/@types/enums.js +76 -0
  11. package/build/@types/index.d.ts +6 -82
  12. package/build/@types/index.js +6 -1
  13. package/build/@types/tapLocalisation.d.ts +193 -0
  14. package/build/@types/tapLocalisation.js +1 -0
  15. package/build/@types/tapTheme.d.ts +842 -0
  16. package/build/@types/tapTheme.js +1 -0
  17. package/build/api.d.ts +29 -0
  18. package/build/{api/app.service.js → api.js} +244 -253
  19. package/build/constants/index.d.ts +3 -51
  20. package/build/constants/index.js +3 -51
  21. package/build/features/ApplePayButton/ApplePayButton.d.ts +4 -6
  22. package/build/features/ApplePayButton/ApplePayButton.js +49 -80
  23. package/build/features/ApplePayButton/index.d.ts +3 -3
  24. package/build/features/ApplePayButton/index.js +2 -2
  25. package/build/hooks/index.d.ts +1 -1
  26. package/build/hooks/index.js +1 -1
  27. package/build/hooks/useApplePay.d.ts +93 -9
  28. package/build/hooks/useApplePay.js +449 -243
  29. package/build/hooks/useMerchantApplePay.d.ts +20 -0
  30. package/build/hooks/useMerchantApplePay.js +188 -0
  31. package/build/index.d.ts +4 -4
  32. package/build/index.js +13 -10
  33. package/build/utils/config.d.ts +14 -11
  34. package/build/utils/config.js +65 -72
  35. package/build/utils/defaultValues.d.ts +2 -0
  36. package/build/utils/defaultValues.js +27 -0
  37. package/build/utils/html.d.ts +1 -1
  38. package/build/utils/html.js +9 -9
  39. package/build/utils/index.d.ts +4 -1
  40. package/build/utils/index.js +4 -1
  41. package/build/utils/theme.d.ts +12 -0
  42. package/build/utils/theme.js +61 -0
  43. package/package.json +109 -104
  44. package/build/api/app.service.d.ts +0 -23
  45. package/build/api/base.d.ts +0 -9
  46. package/build/api/base.js +0 -45
  47. package/build/api/httpClient.d.ts +0 -8
  48. package/build/api/httpClient.js +0 -33
  49. package/build/features/ApplePayButton/ApplePayButton.css +0 -21
  50. package/build/hooks/useScript.d.ts +0 -1
  51. package/build/hooks/useScript.js +0 -39
@@ -0,0 +1,20 @@
1
+ import { MetaData, ApplePayButtonProps, Scope } from '../@types';
2
+ interface ApplePayRequestData {
3
+ isIframeIntegration: boolean;
4
+ onError?: (error: any) => void;
5
+ onSuccess?: (data: Record<string, any>) => void;
6
+ setLoading?: (loading: boolean) => void;
7
+ setSuccess?: (success: boolean) => void;
8
+ setError?: (error: boolean) => void;
9
+ scope: (typeof Scope)[keyof typeof Scope];
10
+ profileData?: Pick<MetaData, 'merchant' | 'payment_options'>;
11
+ merchant: Pick<MetaData['merchant'], 'id'>;
12
+ order: ApplePayButtonProps['order'];
13
+ customer: ApplePayButtonProps['customer'];
14
+ transaction: ApplePayButtonProps['transaction'];
15
+ operator: ApplePayButtonProps['operator'];
16
+ redirect?: ApplePayButtonProps['redirect'];
17
+ post?: ApplePayButtonProps['post'];
18
+ }
19
+ export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
20
+ export {};
@@ -0,0 +1,188 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 * as React from 'react';
49
+ import appService from '../api';
50
+ import { Scope, CHARGE_CODE } from '../@types';
51
+ var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
52
+ export var useMerchantApplePay = function (_a) {
53
+ var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, setLoading = _a.setLoading, setError = _a.setError, setSuccess = _a.setSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post;
54
+ var onMessageReceived = React.useCallback(function (_a) {
55
+ var message = _a.data;
56
+ return __awaiter(void 0, void 0, void 0, function () {
57
+ var _b, event, data, _c, paymentData, paymentMethod, transactionIdentifier, _d, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _e, successState, e_1;
58
+ var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
59
+ return __generator(this, function (_3) {
60
+ switch (_3.label) {
61
+ case 0:
62
+ _b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
63
+ if (!data || event !== EVENT_NAME)
64
+ return [2];
65
+ _c = data !== null && data !== void 0 ? data : {}, paymentData = _c.paymentData, paymentMethod = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
66
+ _3.label = 1;
67
+ case 1:
68
+ _3.trys.push([1, 13, 14, 15]);
69
+ _d = scope;
70
+ switch (_d) {
71
+ case Scope.APPLE_PAY_TOKEN: return [3, 2];
72
+ case Scope.TAP_TOKEN: return [3, 3];
73
+ case Scope.AUTHORIZE: return [3, 5];
74
+ case Scope.CHARGE: return [3, 5];
75
+ }
76
+ return [3, 11];
77
+ case 2:
78
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
79
+ return [3, 12];
80
+ case 3:
81
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
82
+ return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
83
+ case 4:
84
+ response = _3.sent();
85
+ setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
86
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
87
+ return [3, 12];
88
+ case 5:
89
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
90
+ return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
91
+ case 6:
92
+ tokenId = (_3.sent()).id;
93
+ supportCurrency = ((_g = (_f = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _f === void 0 ? void 0 : _f.supported_currencies) !== null && _g !== void 0 ? _g : [])[0];
94
+ transactionRequest = {
95
+ auto: (_h = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _h === void 0 ? void 0 : _h.auto,
96
+ amount: (_l = (_k = (_j = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _j === void 0 ? void 0 : _j.order) === null || _k === void 0 ? void 0 : _k.amount) !== null && _l !== void 0 ? _l : order.amount,
97
+ currency: (_p = (_o = (_m = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _m === void 0 ? void 0 : _m.order) === null || _o === void 0 ? void 0 : _o.currency) !== null && _p !== void 0 ? _p : order.currency,
98
+ selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
99
+ selected_currency: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.currency,
100
+ customer: (customer === null || customer === void 0 ? void 0 : customer.id)
101
+ ? { id: customer === null || customer === void 0 ? void 0 : customer.id }
102
+ : {
103
+ email: (_q = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _q === void 0 ? void 0 : _q.email,
104
+ first_name: ((_r = customer === null || customer === void 0 ? void 0 : customer.name) === null || _r === void 0 ? void 0 : _r.length) ? customer.name[0].first : '',
105
+ last_name: ((_s = customer === null || customer === void 0 ? void 0 : customer.name) === null || _s === void 0 ? void 0 : _s.length) ? customer.name[0].last : '',
106
+ phone: {
107
+ country_code: (_v = (_u = (_t = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _t === void 0 ? void 0 : _t.phone) === null || _u === void 0 ? void 0 : _u.countryCode) !== null && _v !== void 0 ? _v : '',
108
+ number: (_y = (_x = (_w = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _w === void 0 ? void 0 : _w.phone) === null || _x === void 0 ? void 0 : _x.number) !== null && _y !== void 0 ? _y : ''
109
+ }
110
+ },
111
+ fee: 0,
112
+ merchant: {
113
+ id: (_0 = (_z = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _z === void 0 ? void 0 : _z.id) !== null && _0 !== void 0 ? _0 : ''
114
+ },
115
+ order: (_1 = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _1 === void 0 ? void 0 : _1.order,
116
+ product: 'Apple-Pay-Button',
117
+ save_card: false,
118
+ source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
119
+ threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
120
+ hashstring: operator.hashstring,
121
+ redirect: redirect,
122
+ metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
123
+ post: post,
124
+ payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
125
+ destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
126
+ reference: {
127
+ order: order === null || order === void 0 ? void 0 : order.reference,
128
+ transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
129
+ }
130
+ };
131
+ if (!(scope === Scope.AUTHORIZE)) return [3, 8];
132
+ return [4, appService.createAuthorize(transactionRequest)];
133
+ case 7:
134
+ _e = _3.sent();
135
+ return [3, 10];
136
+ case 8: return [4, appService.createCharge(transactionRequest)];
137
+ case 9:
138
+ _e = _3.sent();
139
+ _3.label = 10;
140
+ case 10:
141
+ transactionResponse = _e;
142
+ successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
143
+ if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
144
+ setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
145
+ }
146
+ else {
147
+ setError === null || setError === void 0 ? void 0 : setError(true);
148
+ }
149
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
150
+ return [3, 12];
151
+ case 11:
152
+ console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
153
+ onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '000' });
154
+ return [3, 12];
155
+ case 12: return [3, 15];
156
+ case 13:
157
+ e_1 = _3.sent();
158
+ if (!onError)
159
+ return [2];
160
+ if (e_1.errors) {
161
+ onError(e_1.errors);
162
+ return [2];
163
+ }
164
+ if ((_2 = e_1.response) === null || _2 === void 0 ? void 0 : _2.data.errors) {
165
+ onError(e_1.response.data.errors);
166
+ return [2];
167
+ }
168
+ if (e_1.message) {
169
+ onError([{ message: e_1.message, code: '400' }]);
170
+ return [2];
171
+ }
172
+ onError(e_1);
173
+ return [3, 15];
174
+ case 14:
175
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
176
+ return [7];
177
+ case 15: return [2];
178
+ }
179
+ });
180
+ });
181
+ }, [onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post]);
182
+ React.useEffect(function () {
183
+ if (!isIframeIntegration)
184
+ return;
185
+ window.addEventListener('message', onMessageReceived);
186
+ return function () { return window.removeEventListener('message', onMessageReceived); };
187
+ }, [isIframeIntegration, onMessageReceived]);
188
+ };
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
2
- import { ButtonStyle, Scope, SupportedNetworks, Environment } from './constants';
3
- export type { ApplePayButtonProps };
4
- export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks, Environment };
1
+ import { ApplePayButtonProps, ApplePayButton, ApplePayRequestData } from './features/ApplePayButton';
2
+ import { ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities } from './@types/enums';
3
+ export type { ApplePayButtonProps, ApplePayRequestData };
4
+ export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
package/build/index.js CHANGED
@@ -1,10 +1,13 @@
1
- import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
2
- import { ButtonStyle, Scope, SupportedNetworks, Environment } from './constants';
3
- export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks, Environment };
4
- window['TapSDKs'] = {
5
- renderApplePayButton: renderApplePayButton,
6
- ButtonStyle: ButtonStyle,
7
- Scope: Scope,
8
- SupportedNetworks: SupportedNetworks,
9
- Environment: Environment
10
- };
1
+ import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
2
+ import { ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities } from './@types/enums';
3
+ export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
4
+ window['TapSDKs'] = {
5
+ renderApplePayButton: renderApplePayButton,
6
+ Scope: Scope,
7
+ SupportedNetworks: SupportedNetworks,
8
+ Locale: Locale,
9
+ ButtonType: ButtonType,
10
+ ThemeMode: ThemeMode,
11
+ Edges: Edges,
12
+ MerchantCapabilities: MerchantCapabilities
13
+ };
@@ -1,11 +1,14 @@
1
- import { ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
2
- import { SupportedNetworks } from '../constants';
3
- export declare const validateSupportedNetworks: (supportedNetworksConfig: Array<(typeof SupportedNetworks)[keyof typeof SupportedNetworks]>, supportedNetworks: ApplePayButtonProps['supportedNetworks']) => ("amex" | "mada" | "masterCard" | "visa" | "chinaUnionPay" | "discover" | "electron" | "jcb" | "maestro")[];
4
- export declare const validateCurrency: (currency: string, currencies: string[]) => string;
5
- export declare const getApplePayRequest: ({ transaction, billingContact, supportedNetworks, countryCode, name }: Pick<ApplePayButtonProps, "supportedNetworks" | "transaction" | "billingContact"> & {
6
- countryCode: string;
7
- name: string;
8
- }) => ApplePayRequestData;
9
- export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
10
- export declare const rsaSetup: (key: string) => (string: string) => string;
11
- export declare function generateApplicationHeader(obj: Record<string, string | any>): string;
1
+ import { Acceptance, ApplePayButtonProps, ApplePayRequestData, MetaData, PaymentMethod } from '../@types';
2
+ export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
3
+ export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
4
+ export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
5
+ supportedNetworks: Acceptance['supportedSchemes'];
6
+ merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
7
+ countryCode: string;
8
+ name: string;
9
+ }) => ApplePayRequestData;
10
+ export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
11
+ applePaySessionRequest: ApplePayRequestData;
12
+ paymentMethod: PaymentMethod;
13
+ };
14
+ export declare const shallRenderApplePay: () => boolean;
@@ -1,72 +1,65 @@
1
- import { MerchantCapabilities } from '../constants';
2
- import { JSEncrypt } from 'jsencrypt';
3
- export var validateSupportedNetworks = function (supportedNetworksConfig, supportedNetworks) {
4
- var toLowerCase = function (item) { return item.toLowerCase(); };
5
- if (!supportedNetworks)
6
- return supportedNetworksConfig.map(toLowerCase);
7
- if (supportedNetworks.length === 0)
8
- return supportedNetworksConfig.map(toLowerCase);
9
- if (supportedNetworks.length > supportedNetworksConfig.length) {
10
- throw new Error("The supported networks list is not valid");
11
- }
12
- supportedNetworks.forEach(function (network) {
13
- var isSupported = supportedNetworksConfig.some(function (item) { return item.toLowerCase() === network.toLowerCase(); });
14
- if (!isSupported) {
15
- throw new Error("The supported network ".concat(network, " is not supported"));
16
- }
17
- });
18
- return supportedNetworks;
19
- };
20
- export var validateCurrency = function (currency, currencies) {
21
- var isSupported = currencies.some(function (item) { return item.toLowerCase() === currency.toLowerCase(); });
22
- if (!isSupported) {
23
- throw new Error("The currency \"".concat(currency, "\" is not supported, you have to use one of these currencies: ").concat(currencies));
24
- }
25
- return currency;
26
- };
27
- export var getApplePayRequest = function (_a) {
28
- var transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, countryCode = _a.countryCode, name = _a.name;
29
- return {
30
- countryCode: countryCode,
31
- currencyCode: transaction.currency,
32
- merchantCapabilities: [MerchantCapabilities.Supports3DS],
33
- supportedNetworks: supportedNetworks,
34
- billingContact: billingContact && {
35
- phoneNumber: billingContact.phone.code + billingContact.phone.number,
36
- emailAddress: billingContact.email.address,
37
- givenName: billingContact.name.first,
38
- familyName: billingContact.name.last
39
- },
40
- total: {
41
- amount: Number(transaction.amount),
42
- label: name
43
- }
44
- };
45
- };
46
- export var getApplePayPaymentMethod = function (paymentMethods) {
47
- var paymentMethod = paymentMethods.find(function (_a) {
48
- var name = _a.name, payment_type = _a.payment_type;
49
- return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
50
- });
51
- if (!paymentMethod) {
52
- throw new Error('Apple Pay is not configured in your payment options');
53
- }
54
- return paymentMethod;
55
- };
56
- export var rsaSetup = function (key) {
57
- var rsa = new JSEncrypt();
58
- rsa.setPublicKey(key);
59
- return function (string) {
60
- if (typeof string !== 'string')
61
- throw new Error('string should be from type string');
62
- var encrypted = rsa.encrypt(string);
63
- if (!encrypted)
64
- throw new Error('encryption data reached max allowed length');
65
- return encrypted;
66
- };
67
- };
68
- export function generateApplicationHeader(obj) {
69
- return Object.keys(obj)
70
- .map(function (key) { return "".concat(key, "=").concat(obj[key]); })
71
- .join('|');
72
- }
1
+ import { getMerchantCapabilities } from './defaultValues';
2
+ export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
3
+ var toLowerCase = function (item) { return item.toLowerCase(); };
4
+ if (!supportedNetworksOptions)
5
+ throw new Error("There is no supported networks available in your acceptance object");
6
+ if (!merchantSupportedNetworks)
7
+ return supportedNetworksOptions.map(toLowerCase);
8
+ if (merchantSupportedNetworks.length === 0)
9
+ return supportedNetworksOptions.map(toLowerCase);
10
+ var supportedNetworks = supportedNetworksOptions.filter(function (item) {
11
+ return merchantSupportedNetworks.find(function (network) { return network.toLowerCase() === item.toLowerCase(); });
12
+ });
13
+ if (supportedNetworks.length === 0) {
14
+ throw new Error("It seems that there is no supported networks available in based on your acceptance object");
15
+ }
16
+ return supportedNetworks.map(toLowerCase);
17
+ };
18
+ export var getApplePayPaymentMethod = function (paymentMethods) {
19
+ var paymentMethod = paymentMethods.find(function (_a) {
20
+ var name = _a.name, payment_type = _a.payment_type;
21
+ return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
22
+ });
23
+ if (!paymentMethod) {
24
+ throw new Error('apple_pay is not configured in your payment options');
25
+ }
26
+ return paymentMethod;
27
+ };
28
+ export var getApplePayRequest = function (_a) {
29
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
30
+ var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
31
+ return {
32
+ countryCode: countryCode,
33
+ currencyCode: order.currency,
34
+ merchantCapabilities: merchantCapabilities,
35
+ supportedNetworks: supportedNetworks,
36
+ billingContact: customer && {
37
+ phoneNumber: ((_c = (_b = customer.contact) === null || _b === void 0 ? void 0 : _b.phone) === null || _c === void 0 ? void 0 : _c.countryCode) || '' + ((_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.number),
38
+ emailAddress: (_f = customer.contact) === null || _f === void 0 ? void 0 : _f.email,
39
+ givenName: ((_g = customer.name) === null || _g === void 0 ? void 0 : _g.length) ? (_h = customer.name[0]) === null || _h === void 0 ? void 0 : _h.first : '',
40
+ familyName: ((_j = customer.name) === null || _j === void 0 ? void 0 : _j.length) ? (_k = customer.name[0]) === null || _k === void 0 ? void 0 : _k.last : ''
41
+ },
42
+ total: {
43
+ amount: Number(Number(order.amount).toFixed(2)),
44
+ label: name
45
+ }
46
+ };
47
+ };
48
+ export var prepareApplePayRequest = function (_a) {
49
+ var payment_options = _a.payment_options, merchant = _a.merchant, order = _a.order, customer = _a.customer, acceptance = _a.acceptance;
50
+ var paymentMethod = getApplePayPaymentMethod(payment_options.payment_methods || []);
51
+ var supportedNetworks = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
52
+ var request = getApplePayRequest({
53
+ countryCode: merchant.country_code,
54
+ order: order,
55
+ customer: customer,
56
+ supportedNetworks: supportedNetworks,
57
+ merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
58
+ name: merchant.name
59
+ });
60
+ return { applePaySessionRequest: request, paymentMethod: paymentMethod };
61
+ };
62
+ export var shallRenderApplePay = function () {
63
+ var https = window.location.protocol === 'https:';
64
+ return https;
65
+ };
@@ -0,0 +1,2 @@
1
+ import { MerchantCapabilities } from '../@types/enums';
2
+ export declare const getMerchantCapabilities: (supportedCards?: Array<string>) => MerchantCapabilities[];
@@ -0,0 +1,27 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { MerchantCapabilities } from '../@types/enums';
11
+ export var getMerchantCapabilities = function (supportedCards) {
12
+ var merchantCapabilities = [MerchantCapabilities.Supports3DS];
13
+ if (!supportedCards) {
14
+ merchantCapabilities = __spreadArray(__spreadArray([], merchantCapabilities, true), [
15
+ MerchantCapabilities.SupportsCredit,
16
+ MerchantCapabilities.SupportsDebit
17
+ ], false);
18
+ return merchantCapabilities;
19
+ }
20
+ if (supportedCards.includes('CREDIT')) {
21
+ merchantCapabilities.push(MerchantCapabilities.SupportsCredit);
22
+ }
23
+ if (supportedCards.includes('DEBIT')) {
24
+ merchantCapabilities.push(MerchantCapabilities.SupportsDebit);
25
+ }
26
+ return merchantCapabilities;
27
+ };
@@ -1 +1 @@
1
- export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
1
+ export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
@@ -1,9 +1,9 @@
1
- export var findOrCreateElementAndInject = function (id) {
2
- var findElement = document.getElementById(id);
3
- if (findElement)
4
- return findElement;
5
- var element = document.createElement('div');
6
- element.setAttribute('id', id);
7
- document.body.appendChild(element);
8
- return element;
9
- };
1
+ export var findOrCreateElementAndInject = function (id) {
2
+ var findElement = document.getElementById(id);
3
+ if (findElement)
4
+ return findElement;
5
+ var element = document.createElement('div');
6
+ element.setAttribute('id', id);
7
+ document.body.appendChild(element);
8
+ return element;
9
+ };
@@ -1 +1,4 @@
1
- export * from './html';
1
+ export * from './html';
2
+ export * from './theme';
3
+ export * from './config';
4
+ export * from './defaultValues';
@@ -1 +1,4 @@
1
- export * from './html';
1
+ export * from './html';
2
+ export * from './theme';
3
+ export * from './config';
4
+ export * from './defaultValues';
@@ -0,0 +1,12 @@
1
+ import { TapThemeResponse } from '../@types';
2
+ import { ColorStyle, FullThemeMode, Locale, ThemeMode } from '../@types/enums';
3
+ import { ApplePayButtonProps } from '..';
4
+ export declare const mappingInterface: (interfaceParam?: ApplePayButtonProps['interface']) => ApplePayButtonProps['interface'];
5
+ export declare const getDefaultThemeMode: (themeMode?: ThemeMode) => ThemeMode;
6
+ export declare const getDefaultLocale: (locale?: Locale) => Locale;
7
+ export declare const getFullThemeMode: (themeMode?: ThemeMode, colorStyle?: ColorStyle) => FullThemeMode;
8
+ export declare const appendColors: (colors: Record<string, string>) => void;
9
+ export declare const getTapThemeValue: ({ tapTheme, value }: {
10
+ tapTheme: TapThemeResponse | null;
11
+ value?: string | undefined;
12
+ }) => string;
@@ -0,0 +1,61 @@
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 { ColorStyle, Edges, FullThemeMode, Locale, ThemeMode } from '../@types/enums';
13
+ export var mappingInterface = function (interfaceParam) {
14
+ return __assign(__assign({ edges: Edges.CURVED, colorStyle: ColorStyle.COLORED, loader: true }, interfaceParam), { locale: getDefaultLocale(interfaceParam === null || interfaceParam === void 0 ? void 0 : interfaceParam.locale), theme: getDefaultThemeMode(interfaceParam === null || interfaceParam === void 0 ? void 0 : interfaceParam.theme) });
15
+ };
16
+ export var getDefaultThemeMode = function (themeMode) {
17
+ return themeMode === ThemeMode.DYNAMIC || themeMode === undefined
18
+ ? window.matchMedia('(prefers-color-scheme: dark)').matches
19
+ ? ThemeMode.DARK
20
+ : ThemeMode.LIGHT
21
+ : themeMode;
22
+ };
23
+ export var getDefaultLocale = function (locale) {
24
+ var _a;
25
+ return locale === Locale.DYNAMIC || locale === undefined
26
+ ? (_a = window.navigator.language.split('-')) === null || _a === void 0 ? void 0 : _a[0]
27
+ : locale;
28
+ };
29
+ export var getFullThemeMode = function (themeMode, colorStyle) {
30
+ var themeModeValue = getDefaultThemeMode(themeMode);
31
+ if (themeModeValue === ThemeMode.DARK) {
32
+ return colorStyle === ColorStyle.MONOCHROME ? FullThemeMode.DARK : FullThemeMode.DARK_COLORED;
33
+ }
34
+ else {
35
+ return colorStyle === ColorStyle.MONOCHROME ? FullThemeMode.LIGHT_MONO : FullThemeMode.LIGHT;
36
+ }
37
+ };
38
+ export var appendColors = function (colors) {
39
+ try {
40
+ var root_1 = document.documentElement;
41
+ Object.entries(colors).forEach(function (_a) {
42
+ var key = _a[0], value = _a[1];
43
+ root_1.style.setProperty("--".concat(key), value);
44
+ });
45
+ }
46
+ catch (e) {
47
+ throw e;
48
+ }
49
+ };
50
+ export var getTapThemeValue = function (_a) {
51
+ var tapTheme = _a.tapTheme, value = _a.value;
52
+ if (!tapTheme)
53
+ return '';
54
+ if (!value)
55
+ return '';
56
+ if (value[0] === '#')
57
+ return value;
58
+ var colorsObject = tapTheme === null || tapTheme === void 0 ? void 0 : tapTheme.GlobalValues.Colors;
59
+ var valueFromGlobalColors = colorsObject === null || colorsObject === void 0 ? void 0 : colorsObject[value];
60
+ return valueFromGlobalColors !== null && valueFromGlobalColors !== void 0 ? valueFromGlobalColors : '';
61
+ };