@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.
- package/build/@types/ApplePayButtonProps.d.ts +129 -0
- package/build/@types/ApplePayButtonProps.js +1 -0
- package/build/@types/charge.d.ts +57 -0
- package/build/@types/charge.js +1 -0
- package/build/@types/checkoutProfile.d.ts +195 -0
- package/build/@types/checkoutProfile.js +1 -0
- package/build/@types/enums.d.ts +65 -0
- package/build/@types/enums.js +76 -0
- package/build/@types/index.d.ts +6 -122
- package/build/@types/index.js +6 -1
- package/build/@types/tapLocalisation.d.ts +193 -0
- package/build/@types/tapLocalisation.js +1 -0
- package/build/@types/tapTheme.d.ts +842 -0
- package/build/@types/tapTheme.js +1 -0
- package/build/api.d.ts +29 -0
- package/build/{api/app.service.js → api.js} +87 -95
- package/build/constants/index.d.ts +2 -58
- package/build/constants/index.js +2 -58
- package/build/features/ApplePayButton/ApplePayButton.d.ts +3 -5
- package/build/features/ApplePayButton/ApplePayButton.js +8 -14
- package/build/features/ApplePayButton/index.d.ts +2 -2
- package/build/hooks/index.d.ts +0 -2
- package/build/hooks/index.js +0 -2
- package/build/hooks/useApplePay.d.ts +89 -5
- package/build/hooks/useApplePay.js +289 -117
- package/build/hooks/useMerchantApplePay.d.ts +20 -0
- package/build/hooks/useMerchantApplePay.js +176 -0
- package/build/index.d.ts +4 -6
- package/build/index.js +3 -9
- package/build/utils/config.d.ts +10 -9
- package/build/utils/config.js +40 -47
- package/build/utils/defaultValues.d.ts +2 -30
- package/build/utils/defaultValues.js +10 -31
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.js +3 -0
- package/build/utils/theme.d.ts +12 -0
- package/build/utils/theme.js +61 -0
- package/package.json +16 -11
- package/build/api/app.service.d.ts +0 -23
- package/build/api/base.d.ts +0 -9
- package/build/api/base.js +0 -45
- package/build/api/httpClient.d.ts +0 -8
- package/build/api/httpClient.js +0 -33
- package/build/features/ApplePayButton/ApplePayButton.css +0 -21
- package/build/hooks/useApplePayFromMerchantSide.d.ts +0 -11
- package/build/hooks/useApplePayFromMerchantSide.js +0 -177
- package/build/hooks/useScript.d.ts +0 -1
- package/build/hooks/useScript.js +0 -39
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import * as React from 'react';
|
|
38
|
+
import appService from '../api';
|
|
39
|
+
import { Scope, CHARGE_CODE } from '../@types';
|
|
40
|
+
var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
|
|
41
|
+
export var useMerchantApplePay = function (_a) {
|
|
42
|
+
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;
|
|
43
|
+
var onMessageReceived = React.useCallback(function (_a) {
|
|
44
|
+
var message = _a.data;
|
|
45
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var _b, event, data, _c, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _d, successState, e_1;
|
|
47
|
+
var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
48
|
+
return __generator(this, function (_w) {
|
|
49
|
+
switch (_w.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
_b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
|
|
52
|
+
if (!data || event !== EVENT_NAME)
|
|
53
|
+
return [2];
|
|
54
|
+
_w.label = 1;
|
|
55
|
+
case 1:
|
|
56
|
+
_w.trys.push([1, 13, 14, 15]);
|
|
57
|
+
_c = scope;
|
|
58
|
+
switch (_c) {
|
|
59
|
+
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
60
|
+
case Scope.TAP_TOKEN: return [3, 3];
|
|
61
|
+
case Scope.AUTHORIZE: return [3, 5];
|
|
62
|
+
case Scope.CHARGE: return [3, 5];
|
|
63
|
+
}
|
|
64
|
+
return [3, 11];
|
|
65
|
+
case 2:
|
|
66
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
67
|
+
return [3, 12];
|
|
68
|
+
case 3:
|
|
69
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
70
|
+
return [4, appService.tapTokenization(data)];
|
|
71
|
+
case 4:
|
|
72
|
+
response = _w.sent();
|
|
73
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
74
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
75
|
+
return [3, 12];
|
|
76
|
+
case 5:
|
|
77
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
78
|
+
return [4, appService.tapTokenization(data)];
|
|
79
|
+
case 6:
|
|
80
|
+
tokenId = (_w.sent()).id;
|
|
81
|
+
supportCurrency = ((_f = (_e = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _e === void 0 ? void 0 : _e.supported_currencies) !== null && _f !== void 0 ? _f : [])[0];
|
|
82
|
+
transactionRequest = {
|
|
83
|
+
auto: (_g = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _g === void 0 ? void 0 : _g.auto,
|
|
84
|
+
amount: order.amount,
|
|
85
|
+
currency: order.currency,
|
|
86
|
+
selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
|
|
87
|
+
selected_currency: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.currency,
|
|
88
|
+
customer: (customer === null || customer === void 0 ? void 0 : customer.id)
|
|
89
|
+
? { id: customer === null || customer === void 0 ? void 0 : customer.id }
|
|
90
|
+
: {
|
|
91
|
+
email: (_h = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _h === void 0 ? void 0 : _h.email,
|
|
92
|
+
first_name: ((_j = customer === null || customer === void 0 ? void 0 : customer.name) === null || _j === void 0 ? void 0 : _j.length) ? customer.name[0].first : '',
|
|
93
|
+
last_name: ((_k = customer === null || customer === void 0 ? void 0 : customer.name) === null || _k === void 0 ? void 0 : _k.length) ? customer.name[0].last : '',
|
|
94
|
+
phone: {
|
|
95
|
+
country_code: (_o = (_m = (_l = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _l === void 0 ? void 0 : _l.phone) === null || _m === void 0 ? void 0 : _m.countryCode) !== null && _o !== void 0 ? _o : '',
|
|
96
|
+
number: (_r = (_q = (_p = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _p === void 0 ? void 0 : _p.phone) === null || _q === void 0 ? void 0 : _q.number) !== null && _r !== void 0 ? _r : ''
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
fee: 0,
|
|
100
|
+
merchant: {
|
|
101
|
+
id: (_t = (_s = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _s === void 0 ? void 0 : _s.id) !== null && _t !== void 0 ? _t : ''
|
|
102
|
+
},
|
|
103
|
+
order: (_u = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _u === void 0 ? void 0 : _u.order,
|
|
104
|
+
product: 'Apple-Pay-Button',
|
|
105
|
+
save_card: false,
|
|
106
|
+
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
107
|
+
threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
|
|
108
|
+
hashstring: operator.hashstring,
|
|
109
|
+
redirect: redirect,
|
|
110
|
+
metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
|
|
111
|
+
post: post,
|
|
112
|
+
payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
|
|
113
|
+
destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
|
|
114
|
+
reference: {
|
|
115
|
+
order: order === null || order === void 0 ? void 0 : order.reference,
|
|
116
|
+
transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
if (!(scope === Scope.AUTHORIZE)) return [3, 8];
|
|
120
|
+
return [4, appService.createAuthorize(transactionRequest)];
|
|
121
|
+
case 7:
|
|
122
|
+
_d = _w.sent();
|
|
123
|
+
return [3, 10];
|
|
124
|
+
case 8: return [4, appService.createCharge(transactionRequest)];
|
|
125
|
+
case 9:
|
|
126
|
+
_d = _w.sent();
|
|
127
|
+
_w.label = 10;
|
|
128
|
+
case 10:
|
|
129
|
+
transactionResponse = _d;
|
|
130
|
+
successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
|
|
131
|
+
if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
|
|
132
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
setError === null || setError === void 0 ? void 0 : setError(true);
|
|
136
|
+
}
|
|
137
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
|
|
138
|
+
return [3, 12];
|
|
139
|
+
case 11:
|
|
140
|
+
console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
|
|
141
|
+
onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '000' });
|
|
142
|
+
return [3, 12];
|
|
143
|
+
case 12: return [3, 15];
|
|
144
|
+
case 13:
|
|
145
|
+
e_1 = _w.sent();
|
|
146
|
+
if (!onError)
|
|
147
|
+
return [2];
|
|
148
|
+
if (e_1.errors) {
|
|
149
|
+
onError(e_1.errors);
|
|
150
|
+
return [2];
|
|
151
|
+
}
|
|
152
|
+
if ((_v = e_1.response) === null || _v === void 0 ? void 0 : _v.data.errors) {
|
|
153
|
+
onError(e_1.response.data.errors);
|
|
154
|
+
return [2];
|
|
155
|
+
}
|
|
156
|
+
if (e_1.message) {
|
|
157
|
+
onError([{ message: e_1.message, code: '400' }]);
|
|
158
|
+
return [2];
|
|
159
|
+
}
|
|
160
|
+
onError(e_1);
|
|
161
|
+
return [3, 15];
|
|
162
|
+
case 14:
|
|
163
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
|
|
164
|
+
return [7];
|
|
165
|
+
case 15: return [2];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}, [onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post]);
|
|
170
|
+
React.useEffect(function () {
|
|
171
|
+
if (!isIframeIntegration)
|
|
172
|
+
return;
|
|
173
|
+
window.addEventListener('message', onMessageReceived);
|
|
174
|
+
return function () { return window.removeEventListener('message', onMessageReceived); };
|
|
175
|
+
}, [isIframeIntegration, onMessageReceived]);
|
|
176
|
+
};
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type { ApplePayButtonProps };
|
|
6
|
-
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities, ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide, ApplePayGetFromMerchantEvents };
|
|
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,19 +1,13 @@
|
|
|
1
|
-
import { ApplePayGetFromMerchantEvents } from './hooks/useApplePayFromMerchantSide';
|
|
2
1
|
import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities, ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide, ApplePayGetFromMerchantEvents };
|
|
2
|
+
import { ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities } from './@types/enums';
|
|
3
|
+
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
|
|
6
4
|
window['TapSDKs'] = {
|
|
7
5
|
renderApplePayButton: renderApplePayButton,
|
|
8
6
|
Scope: Scope,
|
|
9
7
|
SupportedNetworks: SupportedNetworks,
|
|
10
|
-
Environment: Environment,
|
|
11
8
|
Locale: Locale,
|
|
12
9
|
ButtonType: ButtonType,
|
|
13
10
|
ThemeMode: ThemeMode,
|
|
14
11
|
Edges: Edges,
|
|
15
|
-
MerchantCapabilities: MerchantCapabilities
|
|
16
|
-
ApplePayPostFromMerchantEvents: ApplePayPostFromMerchantEvents,
|
|
17
|
-
useApplePayFromMerchantSide: useApplePayFromMerchantSide,
|
|
18
|
-
ApplePayGetFromMerchantEvents: ApplePayGetFromMerchantEvents
|
|
12
|
+
MerchantCapabilities: MerchantCapabilities
|
|
19
13
|
};
|
package/build/utils/config.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Acceptance, ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
6
|
-
supportedNetworks: Acceptance['supportedBrands'];
|
|
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'];
|
|
7
6
|
merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
|
|
8
7
|
countryCode: string;
|
|
9
8
|
name: string;
|
|
10
9
|
}) => ApplePayRequestData;
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
package/build/utils/config.js
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export var validateSupportedNetworks = function (
|
|
1
|
+
import { getMerchantCapabilities } from './defaultValues';
|
|
2
|
+
export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
|
|
3
3
|
var toLowerCase = function (item) { return item.toLowerCase(); };
|
|
4
|
-
if (!
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var isSupported = supportedNetworksConfig.some(function (item) { return item.toLowerCase() === network.toLowerCase(); });
|
|
13
|
-
if (!isSupported) {
|
|
14
|
-
throw new Error("The supported network ".concat(network, " is not supported"));
|
|
15
|
-
}
|
|
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(); });
|
|
16
12
|
});
|
|
17
|
-
|
|
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);
|
|
18
17
|
};
|
|
19
|
-
export var
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
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');
|
|
23
25
|
}
|
|
24
|
-
return
|
|
26
|
+
return paymentMethod;
|
|
25
27
|
};
|
|
26
28
|
export var getApplePayRequest = function (_a) {
|
|
27
29
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
28
|
-
var
|
|
30
|
+
var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
|
|
29
31
|
return {
|
|
30
32
|
countryCode: countryCode,
|
|
31
|
-
currencyCode:
|
|
33
|
+
currencyCode: order.currency,
|
|
32
34
|
merchantCapabilities: merchantCapabilities,
|
|
33
35
|
supportedNetworks: supportedNetworks,
|
|
34
36
|
billingContact: customer && {
|
|
@@ -38,35 +40,26 @@ export var getApplePayRequest = function (_a) {
|
|
|
38
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 : ''
|
|
39
41
|
},
|
|
40
42
|
total: {
|
|
41
|
-
amount: Number(
|
|
43
|
+
amount: Number(Number(order.amount).toFixed(2)),
|
|
42
44
|
label: name
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
47
|
};
|
|
46
|
-
export var
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
50
59
|
});
|
|
51
|
-
|
|
52
|
-
throw new Error('Apple Pay is not configured in your payment options');
|
|
53
|
-
}
|
|
54
|
-
return paymentMethod;
|
|
60
|
+
return { applePaySessionRequest: request, paymentMethod: paymentMethod };
|
|
55
61
|
};
|
|
56
|
-
export var
|
|
57
|
-
var
|
|
58
|
-
|
|
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
|
-
};
|
|
62
|
+
export var shallRenderApplePay = function () {
|
|
63
|
+
var https = window.location.protocol === 'https:';
|
|
64
|
+
return https;
|
|
67
65
|
};
|
|
68
|
-
export function generateApplicationHeader(obj) {
|
|
69
|
-
return Object.keys(obj)
|
|
70
|
-
.map(function (key) { return "".concat(key, "=").concat(obj[key]); })
|
|
71
|
-
.join('|');
|
|
72
|
-
}
|
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
interface: {
|
|
4
|
-
locale?: "en" | "ar" | "fr" | undefined;
|
|
5
|
-
theme?: "dark" | "light" | undefined;
|
|
6
|
-
edges?: "straight" | "curved" | undefined;
|
|
7
|
-
type?: "book" | "buy" | "check-out" | "pay" | "plain" | "subscribe" | undefined;
|
|
8
|
-
};
|
|
9
|
-
scope?: "AppleToken" | "TapToken" | undefined;
|
|
10
|
-
publicKey: string;
|
|
11
|
-
environment: "production" | "sandbox" | "beta" | "development" | "staging";
|
|
12
|
-
merchant: {
|
|
13
|
-
id: string;
|
|
14
|
-
domain: string;
|
|
15
|
-
};
|
|
16
|
-
customer?: import("../@types").Customer | undefined;
|
|
17
|
-
acceptance: import("../@types").Acceptance;
|
|
18
|
-
transaction: {
|
|
19
|
-
amount: string;
|
|
20
|
-
currency: string;
|
|
21
|
-
};
|
|
22
|
-
onCancel?: (() => void) | undefined;
|
|
23
|
-
onError?: ((error: any) => void) | undefined;
|
|
24
|
-
onSuccess?: ((data: Record<string, any>) => Promise<void>) | undefined;
|
|
25
|
-
onClick?: (() => void) | undefined;
|
|
26
|
-
onReady?: (() => void) | undefined;
|
|
27
|
-
metaData?: import("../@types").MetaData | undefined;
|
|
28
|
-
debug?: boolean | undefined;
|
|
29
|
-
};
|
|
30
|
-
export declare const getMerchantCapaplities: (supportedCards?: Array<string>) => ("supports3DS" | "supportsCredit" | "supportsDebit")[];
|
|
1
|
+
import { MerchantCapabilities } from '../@types/enums';
|
|
2
|
+
export declare const getMerchantCapabilities: (supportedCards?: Array<string>) => MerchantCapabilities[];
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
2
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
3
|
if (ar || !(i in from)) {
|
|
@@ -18,31 +7,21 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
18
7
|
}
|
|
19
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
9
|
};
|
|
21
|
-
import {
|
|
22
|
-
export var
|
|
23
|
-
var
|
|
24
|
-
var userLang = navigator.language.toLowerCase().includes(Locale.AR) ? Locale.AR : Locale.EN;
|
|
25
|
-
var defaultInterface = {
|
|
26
|
-
locale: userLang,
|
|
27
|
-
theme: userThemeMode,
|
|
28
|
-
type: ButtonType.PLAIN,
|
|
29
|
-
edges: Edges.CURVED
|
|
30
|
-
};
|
|
31
|
-
return __assign(__assign({}, mainObject), { interface: __assign(__assign({}, defaultInterface), mainObject.interface) });
|
|
32
|
-
};
|
|
33
|
-
export var getMerchantCapaplities = function (supportedCards) {
|
|
34
|
-
var merchantCapaplities = [MerchantCapabilities.Supports3DS];
|
|
10
|
+
import { MerchantCapabilities } from '../@types/enums';
|
|
11
|
+
export var getMerchantCapabilities = function (supportedCards) {
|
|
12
|
+
var merchantCapabilities = [MerchantCapabilities.Supports3DS];
|
|
35
13
|
if (!supportedCards) {
|
|
36
|
-
|
|
14
|
+
merchantCapabilities = __spreadArray(__spreadArray([], merchantCapabilities, true), [
|
|
37
15
|
MerchantCapabilities.SupportsCredit,
|
|
38
16
|
MerchantCapabilities.SupportsDebit
|
|
39
17
|
], false);
|
|
18
|
+
return merchantCapabilities;
|
|
40
19
|
}
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
if (supportedCards.includes('CREDIT')) {
|
|
21
|
+
merchantCapabilities.push(MerchantCapabilities.SupportsCredit);
|
|
43
22
|
}
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
if (supportedCards.includes('DEBIT')) {
|
|
24
|
+
merchantCapabilities.push(MerchantCapabilities.SupportsDebit);
|
|
46
25
|
}
|
|
47
|
-
return
|
|
26
|
+
return merchantCapabilities;
|
|
48
27
|
};
|
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/apple-pay-button",
|
|
3
|
-
"version": "0.0.37-
|
|
3
|
+
"version": "0.0.37-test",
|
|
4
4
|
"description": "Apple Pay Button React Component",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"module": "build/index.js",
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
+
"start": "cross-env NODE_ENV=development webpack serve",
|
|
13
14
|
"prepare": "npx husky install",
|
|
14
15
|
"prettier": "prettier --list-different \"src/**/*.{md,mdx,ts,js,tsx,jsx,json}\" *.json *.js",
|
|
15
16
|
"prettier:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md,css,json}\" *.json *.js",
|
|
16
17
|
"lint": "eslint src --color --ext .js,.jsx,.ts,.tsx,.json",
|
|
17
18
|
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
18
|
-
"start": "cross-env NODE_ENV=development webpack serve",
|
|
19
19
|
"build": "cross-env NODE_ENV=production webpack",
|
|
20
|
-
"copy:files": "copyfiles -u 1 src/**/*.css build/",
|
|
20
|
+
"copy:files": "copyfiles -u 1 src/**/*.gif build/ && 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 --tag
|
|
23
|
+
"push": "npm publish --access public --tag test"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [],
|
|
26
26
|
"author": {
|
|
@@ -28,11 +28,23 @@
|
|
|
28
28
|
"email": "a.elsharkawy@tap.company"
|
|
29
29
|
},
|
|
30
30
|
"license": "ISC",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@tap-payments/acceptance-sdk": "^0.0.46",
|
|
33
|
+
"@tap-payments/browser-info": "^1.0.2",
|
|
34
|
+
"@tap-payments/web-error-handing": "^1.0.1",
|
|
35
|
+
"axios": "^1.2.2",
|
|
36
|
+
"framer-motion": "^10.16.5",
|
|
37
|
+
"jsencrypt": "^3.3.2",
|
|
38
|
+
"lottie-react": "^2.4.0",
|
|
39
|
+
"react": "^18.2.0",
|
|
40
|
+
"react-dom": "^18.2.0"
|
|
41
|
+
},
|
|
31
42
|
"devDependencies": {
|
|
32
43
|
"@babel/core": "^7.18.6",
|
|
33
44
|
"@babel/preset-env": "^7.18.6",
|
|
34
45
|
"@babel/preset-react": "^7.18.6",
|
|
35
46
|
"@babel/preset-typescript": "^7.18.6",
|
|
47
|
+
"@types/applepayjs": "^14.0.3",
|
|
36
48
|
"@types/crypto-js": "^4.1.1",
|
|
37
49
|
"@types/react": "^18.0.15",
|
|
38
50
|
"@types/react-dom": "^18.0.6",
|
|
@@ -71,13 +83,6 @@
|
|
|
71
83
|
"webpack-dev-server": "^4.9.3",
|
|
72
84
|
"webpack-merge": "^5.8.0"
|
|
73
85
|
},
|
|
74
|
-
"dependencies": {
|
|
75
|
-
"@tap-payments/browser-info": "^1.0.2",
|
|
76
|
-
"axios": "^1.2.2",
|
|
77
|
-
"jsencrypt": "^3.3.2",
|
|
78
|
-
"react": ">=17.0.2",
|
|
79
|
-
"react-dom": ">=17.0.2"
|
|
80
|
-
},
|
|
81
86
|
"peerDependencies": {
|
|
82
87
|
"react": ">=17.0.2",
|
|
83
88
|
"react-dom": ">=17.0.2"
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { MerchantResponse, ApplePayButtonProps, CheckoutProfileRequest } from '../@types';
|
|
2
|
-
import BaseService from './base';
|
|
3
|
-
declare class APPService extends BaseService {
|
|
4
|
-
private baseUrl;
|
|
5
|
-
private env;
|
|
6
|
-
constructor();
|
|
7
|
-
setEnv(env: ApplePayButtonProps['environment']): void;
|
|
8
|
-
setBaseUrl(): void;
|
|
9
|
-
getHeaderPublicKey(): "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----" | "" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
|
|
10
|
-
setBrowserHeaders({ locale, pk, domain }: {
|
|
11
|
-
locale: string;
|
|
12
|
-
pk: string;
|
|
13
|
-
domain: string;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
checkoutProfile(request: CheckoutProfileRequest): Promise<{
|
|
16
|
-
merchant: any;
|
|
17
|
-
payment_options: any;
|
|
18
|
-
}>;
|
|
19
|
-
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
|
|
20
|
-
tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
|
|
21
|
-
}
|
|
22
|
-
declare const appService: APPService;
|
|
23
|
-
export default appService;
|
package/build/api/base.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
export default class BaseService {
|
|
3
|
-
httpClient: AxiosInstance;
|
|
4
|
-
constructor(httpClient: AxiosInstance);
|
|
5
|
-
get(url: string, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
6
|
-
post(url: string, data?: any, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
7
|
-
put(url: string, data?: any, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
8
|
-
delete(url: string, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
|
-
}
|