@tap-payments/apple-pay-button 1.0.0 → 1.0.2
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/LICENSE +21 -21
- package/README.md +194 -194
- package/build/@types/index.d.ts +82 -73
- package/build/@types/index.js +1 -1
- package/build/api/app.service.d.ts +23 -11
- package/build/api/app.service.js +253 -217
- package/build/api/base.d.ts +9 -9
- package/build/api/base.js +45 -45
- package/build/api/httpClient.d.ts +8 -2
- package/build/api/httpClient.js +33 -16
- package/build/constants/index.d.ts +51 -26
- package/build/constants/index.js +51 -26
- package/build/features/ApplePayButton/ApplePayButton.css +21 -51
- package/build/features/ApplePayButton/ApplePayButton.d.ts +6 -6
- package/build/features/ApplePayButton/ApplePayButton.js +80 -51
- package/build/features/ApplePayButton/index.d.ts +3 -3
- package/build/features/ApplePayButton/index.js +2 -2
- package/build/hooks/index.d.ts +1 -1
- package/build/hooks/index.js +1 -1
- package/build/hooks/useApplePay.d.ts +9 -9
- package/build/hooks/useApplePay.js +243 -206
- package/build/hooks/useScript.d.ts +1 -1
- package/build/hooks/useScript.js +39 -39
- package/build/index.d.ts +4 -4
- package/build/index.js +10 -9
- package/build/utils/config.d.ts +11 -9
- package/build/utils/config.js +72 -54
- package/build/utils/html.d.ts +1 -1
- package/build/utils/html.js +9 -9
- package/build/utils/index.d.ts +1 -1
- package/build/utils/index.js +1 -1
- package/package.json +104 -102
|
@@ -1,206 +1,243 @@
|
|
|
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, useState } from 'react';
|
|
49
|
-
import appService from '../api/app.service';
|
|
50
|
-
import { ApplePayVersion } from '../constants';
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
_a
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
session_1.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
case
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
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, useState } from 'react';
|
|
49
|
+
import appService from '../api/app.service';
|
|
50
|
+
import { ApplePayVersion } from '../constants';
|
|
51
|
+
import { setAxiosGlobalHeaders } from '../api/httpClient';
|
|
52
|
+
import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
|
|
53
|
+
export var useApplePay = function (_a) {
|
|
54
|
+
var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, billingContact = _a.billingContact, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, supportedNetworks = _a.supportedNetworks, metaData = _a.metaData, debug = _a.debug, merchantIdentifier = _a.merchantIdentifier, environment = _a.environment, locale = _a.locale, onReady = _a.onReady;
|
|
55
|
+
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
56
|
+
var _c = useState(null), profileData = _c[0], setProfile = _c[1];
|
|
57
|
+
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
58
|
+
var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var merchantProfile, payment_options, headers, data, err_1;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
setLoading(true);
|
|
64
|
+
appService.setEnv(environment);
|
|
65
|
+
appService.setBaseUrl();
|
|
66
|
+
_a.label = 1;
|
|
67
|
+
case 1:
|
|
68
|
+
_a.trys.push([1, 4, 5, 6]);
|
|
69
|
+
if (metaData) {
|
|
70
|
+
merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers = metaData.headers;
|
|
71
|
+
setAxiosGlobalHeaders(__assign({}, headers));
|
|
72
|
+
setProfile({ merchant: merchantProfile, payment_options: payment_options });
|
|
73
|
+
return [2];
|
|
74
|
+
}
|
|
75
|
+
return [4, appService.setBrowserHeaders({ locale: locale, domain: merchant.domain, pk: publicKey })];
|
|
76
|
+
case 2:
|
|
77
|
+
_a.sent();
|
|
78
|
+
return [4, appService.checkoutProfile()];
|
|
79
|
+
case 3:
|
|
80
|
+
data = _a.sent();
|
|
81
|
+
if (debug)
|
|
82
|
+
console.log('merchant configuration: ', data);
|
|
83
|
+
setProfile(data);
|
|
84
|
+
return [3, 6];
|
|
85
|
+
case 4:
|
|
86
|
+
err_1 = _a.sent();
|
|
87
|
+
onError && onError(err_1.errors || err_1);
|
|
88
|
+
return [3, 6];
|
|
89
|
+
case 5:
|
|
90
|
+
setLoading(false);
|
|
91
|
+
onReady && onReady();
|
|
92
|
+
return [7];
|
|
93
|
+
case 6: return [2];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}); }, [environment, locale, merchant.domain, publicKey, debug, onError]);
|
|
97
|
+
useEffect(function () {
|
|
98
|
+
initialize(metaData);
|
|
99
|
+
}, [initialize, metaData]);
|
|
100
|
+
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
101
|
+
var ApplePaySession, paymentMethod, currency, cardBrands, request, session_1;
|
|
102
|
+
var _a;
|
|
103
|
+
return __generator(this, function (_b) {
|
|
104
|
+
ApplePaySession = window.ApplePaySession;
|
|
105
|
+
if (!ApplePaySession) {
|
|
106
|
+
setDisabled(true);
|
|
107
|
+
console.error('ApplePaySession is not available, please check if you are using Safari browser');
|
|
108
|
+
return [2];
|
|
109
|
+
}
|
|
110
|
+
if (!profileData) {
|
|
111
|
+
setDisabled(true);
|
|
112
|
+
console.error('The profile data is not available, please check networks and try again');
|
|
113
|
+
return [2];
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
117
|
+
currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
|
|
118
|
+
cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, supportedNetworks);
|
|
119
|
+
request = getApplePayRequest({
|
|
120
|
+
countryCode: profileData.merchant.country_code,
|
|
121
|
+
transaction: __assign(__assign({}, transaction), { currency: currency }),
|
|
122
|
+
billingContact: billingContact,
|
|
123
|
+
supportedNetworks: cardBrands,
|
|
124
|
+
name: profileData.merchant.name
|
|
125
|
+
});
|
|
126
|
+
if (debug) {
|
|
127
|
+
console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(request)));
|
|
128
|
+
}
|
|
129
|
+
session_1 = new ApplePaySession(ApplePayVersion, request);
|
|
130
|
+
session_1.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
|
+
var merchantSession, error_1;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
if (debug) {
|
|
136
|
+
console.info('Creating merchant session and validating merchant session');
|
|
137
|
+
console.info('onvalidatemerchant event', event);
|
|
138
|
+
}
|
|
139
|
+
setLoading(true);
|
|
140
|
+
_a.label = 1;
|
|
141
|
+
case 1:
|
|
142
|
+
_a.trys.push([1, 3, , 4]);
|
|
143
|
+
if (debug) {
|
|
144
|
+
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
|
|
145
|
+
}
|
|
146
|
+
return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain, merchantIdentifier)];
|
|
147
|
+
case 2:
|
|
148
|
+
merchantSession = _a.sent();
|
|
149
|
+
if (debug)
|
|
150
|
+
console.info('merchantSession', merchantSession);
|
|
151
|
+
session_1.completeMerchantValidation(merchantSession);
|
|
152
|
+
console.info('merchantSession completed successfully!');
|
|
153
|
+
return [3, 4];
|
|
154
|
+
case 3:
|
|
155
|
+
error_1 = _a.sent();
|
|
156
|
+
if (debug)
|
|
157
|
+
console.error('error in onvalidatemerchant', error_1);
|
|
158
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
159
|
+
throw error_1;
|
|
160
|
+
case 4:
|
|
161
|
+
setLoading(false);
|
|
162
|
+
return [2];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); };
|
|
166
|
+
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
+
var _a, data, error_2;
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
switch (_b.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
setLoading(true);
|
|
172
|
+
if (debug)
|
|
173
|
+
console.info('onpaymentauthorized event', event);
|
|
174
|
+
_b.label = 1;
|
|
175
|
+
case 1:
|
|
176
|
+
_b.trys.push([1, 9, 10, 11]);
|
|
177
|
+
_a = scope;
|
|
178
|
+
switch (_a) {
|
|
179
|
+
case 'AppleToken': return [3, 2];
|
|
180
|
+
case 'TapToken': return [3, 4];
|
|
181
|
+
}
|
|
182
|
+
return [3, 7];
|
|
183
|
+
case 2: return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token.paymentData))];
|
|
184
|
+
case 3:
|
|
185
|
+
_b.sent();
|
|
186
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
187
|
+
return [3, 8];
|
|
188
|
+
case 4: return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
189
|
+
case 5:
|
|
190
|
+
data = _b.sent();
|
|
191
|
+
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
|
|
192
|
+
case 6:
|
|
193
|
+
_b.sent();
|
|
194
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
195
|
+
return [3, 8];
|
|
196
|
+
case 7:
|
|
197
|
+
console.error('We only support AppleToken and TapToken for now');
|
|
198
|
+
console.info('Completing payment with status: STATUS_FAILURE');
|
|
199
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
200
|
+
_b.label = 8;
|
|
201
|
+
case 8: return [3, 11];
|
|
202
|
+
case 9:
|
|
203
|
+
error_2 = _b.sent();
|
|
204
|
+
if (debug)
|
|
205
|
+
console.error('error in onpaymentauthorized', error_2);
|
|
206
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
207
|
+
throw error_2;
|
|
208
|
+
case 10:
|
|
209
|
+
setLoading(false);
|
|
210
|
+
return [7];
|
|
211
|
+
case 11: return [2];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}); };
|
|
215
|
+
session_1.oncancel = function (event) {
|
|
216
|
+
console.info('oncancel event', event);
|
|
217
|
+
if (onCancel)
|
|
218
|
+
onCancel();
|
|
219
|
+
};
|
|
220
|
+
session_1.begin();
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
if (!onError)
|
|
224
|
+
return [2];
|
|
225
|
+
if (e.errors) {
|
|
226
|
+
onError(e.errors);
|
|
227
|
+
return [2];
|
|
228
|
+
}
|
|
229
|
+
if ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data.errors) {
|
|
230
|
+
onError(e.response.data.errors);
|
|
231
|
+
return [2];
|
|
232
|
+
}
|
|
233
|
+
if (e.message) {
|
|
234
|
+
onError([{ description: e.message, code: '400' }]);
|
|
235
|
+
return [2];
|
|
236
|
+
}
|
|
237
|
+
onError(e);
|
|
238
|
+
}
|
|
239
|
+
return [2];
|
|
240
|
+
});
|
|
241
|
+
}); };
|
|
242
|
+
return { loading: loading, onApplePayButtonClicked: onApplePayButtonClicked, disabled: !profileData || disabled };
|
|
243
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useScript(src: string, async?: boolean): "loading" | "ready" | "idle" | "error";
|
|
1
|
+
export declare function useScript(src: string, async?: boolean): "loading" | "ready" | "idle" | "error";
|
package/build/hooks/useScript.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
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
|
-
}
|
|
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
|
+
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
|
|
2
|
-
import { ButtonStyle, Scope, SupportedNetworks } from './constants';
|
|
3
|
-
export type { ApplePayButtonProps };
|
|
4
|
-
export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks };
|
|
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 };
|
package/build/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
|
|
2
|
-
import { ButtonStyle, Scope, SupportedNetworks } from './constants';
|
|
3
|
-
export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks };
|
|
4
|
-
window['TapSDKs'] = {
|
|
5
|
-
renderApplePayButton: renderApplePayButton,
|
|
6
|
-
ButtonStyle: ButtonStyle,
|
|
7
|
-
Scope: Scope,
|
|
8
|
-
SupportedNetworks: SupportedNetworks
|
|
9
|
-
|
|
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
|
+
};
|
package/build/utils/config.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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;
|
|
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;
|