@tap-payments/apple-pay-button 0.0.70-development → 0.0.71-development
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 +1 -0
- package/build/api.d.ts +1 -1
- package/build/api.js +2 -2
- package/build/hooks/useApplePay.js +27 -17
- package/package.json +1 -1
package/build/api.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class APPService {
|
|
|
20
20
|
merchant: any;
|
|
21
21
|
payment_options: any;
|
|
22
22
|
}>;
|
|
23
|
-
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string,
|
|
23
|
+
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string, paymentProcessor: string): Promise<any>;
|
|
24
24
|
tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
|
|
25
25
|
createCharge(request: ChargeRequestBody): Promise<any>;
|
|
26
26
|
createAuthorize(request: AuthorizeRequestBody): Promise<any>;
|
package/build/api.js
CHANGED
|
@@ -149,7 +149,7 @@ var APPService = (function () {
|
|
|
149
149
|
enumerable: false,
|
|
150
150
|
configurable: true,
|
|
151
151
|
writable: true,
|
|
152
|
-
value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier,
|
|
152
|
+
value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier, paymentProcessor) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
154
|
var body, data;
|
|
155
155
|
return __generator(this, function (_a) {
|
|
@@ -161,7 +161,7 @@ var APPService = (function () {
|
|
|
161
161
|
merchantIdentifier: merchantIdentifier,
|
|
162
162
|
merchantId: merchant.id,
|
|
163
163
|
merchantName: merchant.name,
|
|
164
|
-
|
|
164
|
+
paymentProcessor: paymentProcessor
|
|
165
165
|
};
|
|
166
166
|
return [4, axiosInstance.post('/validatemerchant', body)];
|
|
167
167
|
case 1:
|
|
@@ -58,7 +58,7 @@ export var useApplePay = function (_a) {
|
|
|
58
58
|
var buttonProps = _a.buttonProps;
|
|
59
59
|
var _c = useState(), applePayRequestData = _c[0], setApplePayRequestData = _c[1];
|
|
60
60
|
var _d = useState(), applePayRequestConfiguration = _d[0], setApplePayRequestConfiguration = _d[1];
|
|
61
|
-
var _e = useState(),
|
|
61
|
+
var _e = useState(), paymentMethodIdentifier = _e[0], setPaymentMethodIdentifier = _e[1];
|
|
62
62
|
var _f = useState(), profileData = _f[0], setProfile = _f[1];
|
|
63
63
|
var _g = useState(false), disabled = _g[0], setDisabled = _g[1];
|
|
64
64
|
var _h = useState(false), initialLoading = _h[0], setInitialLoading = _h[1];
|
|
@@ -66,6 +66,9 @@ export var useApplePay = function (_a) {
|
|
|
66
66
|
var _k = useState(false), success = _k[0], setSuccess = _k[1];
|
|
67
67
|
var _l = useState(false), loading = _l[0], setLoading = _l[1];
|
|
68
68
|
var _m = useState(false), isRounded = _m[0], setIsRounded = _m[1];
|
|
69
|
+
var paymentProcessor = useMemo(function () {
|
|
70
|
+
return (paymentMethodIdentifier !== null && paymentMethodIdentifier !== void 0 ? paymentMethodIdentifier : '').toLowerCase().includes('knet') ? 'knet' : 'tap';
|
|
71
|
+
}, [paymentMethodIdentifier]);
|
|
69
72
|
var mappedProps = __assign(__assign({}, buttonProps), { interface: mapingInterface(buttonProps.interface) });
|
|
70
73
|
var interfaceObj = mappedProps.interface, merchant = mappedProps.merchant, customer = mappedProps.customer, acceptance = mappedProps.acceptance, scope = mappedProps.scope, debug = mappedProps.debug, onError = mappedProps.onError, onSuccess = mappedProps.onSuccess, onCancel = mappedProps.onCancel, onReady = mappedProps.onReady, metaData = mappedProps.metaData, headers = mappedProps.headers, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect;
|
|
71
74
|
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
@@ -94,14 +97,14 @@ export var useApplePay = function (_a) {
|
|
|
94
97
|
}, [profileData]);
|
|
95
98
|
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
99
|
var merchantProfile, payment_options, headers_1, data, applePayPreparedData, err_1;
|
|
97
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m
|
|
98
|
-
return __generator(this, function (
|
|
99
|
-
switch (
|
|
100
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
101
|
+
return __generator(this, function (_o) {
|
|
102
|
+
switch (_o.label) {
|
|
100
103
|
case 0:
|
|
101
104
|
setInitialLoading(true);
|
|
102
|
-
|
|
105
|
+
_o.label = 1;
|
|
103
106
|
case 1:
|
|
104
|
-
|
|
107
|
+
_o.trys.push([1, 7, , 8]);
|
|
105
108
|
if (!shallRenderApplePay()) {
|
|
106
109
|
throw new Error('The device/customer is not eligible to use ApplePay');
|
|
107
110
|
}
|
|
@@ -114,7 +117,7 @@ export var useApplePay = function (_a) {
|
|
|
114
117
|
if (!headers) return [3, 3];
|
|
115
118
|
return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
|
|
116
119
|
case 2:
|
|
117
|
-
|
|
120
|
+
_o.sent();
|
|
118
121
|
return [3, 5];
|
|
119
122
|
case 3: return [4, appService.setBrowserHeaders({
|
|
120
123
|
locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
|
|
@@ -122,8 +125,8 @@ export var useApplePay = function (_a) {
|
|
|
122
125
|
pk: operator.publicKey
|
|
123
126
|
})];
|
|
124
127
|
case 4:
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
_o.sent();
|
|
129
|
+
_o.label = 5;
|
|
127
130
|
case 5: return [4, appService.checkoutProfile({
|
|
128
131
|
supported_payment_methods: ['APPLE_PAY'],
|
|
129
132
|
supported_currencies: [order.currency],
|
|
@@ -155,24 +158,24 @@ export var useApplePay = function (_a) {
|
|
|
155
158
|
] })
|
|
156
159
|
})];
|
|
157
160
|
case 6:
|
|
158
|
-
data =
|
|
161
|
+
data = _o.sent();
|
|
159
162
|
if (debug)
|
|
160
163
|
console.log('merchant configuration: ', data);
|
|
161
164
|
setProfile(data);
|
|
162
165
|
applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, data), { order: order, acceptance: acceptance, customer: customer }));
|
|
163
166
|
setApplePayRequestData(applePayPreparedData.applePaySessionRequest);
|
|
164
|
-
|
|
165
|
-
onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((
|
|
167
|
+
setPaymentMethodIdentifier(applePayPreparedData.paymentMethod.identifier);
|
|
168
|
+
onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_l = (_k = data.payment_options) === null || _k === void 0 ? void 0 : _k.order) === null || _l === void 0 ? void 0 : _l.id);
|
|
166
169
|
setApplePayRequestConfiguration({
|
|
167
170
|
BASE_URL: MW_BASE_URL,
|
|
168
171
|
headers: getAxiosGlobalHeaders(),
|
|
169
|
-
merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((
|
|
172
|
+
merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_m = data.merchant) === null || _m === void 0 ? void 0 : _m.id) })
|
|
170
173
|
});
|
|
171
174
|
setInitialLoading(false);
|
|
172
175
|
onReady === null || onReady === void 0 ? void 0 : onReady();
|
|
173
176
|
return [3, 8];
|
|
174
177
|
case 7:
|
|
175
|
-
err_1 =
|
|
178
|
+
err_1 = _o.sent();
|
|
176
179
|
onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
|
|
177
180
|
console.log('error in initialize', err_1);
|
|
178
181
|
return [3, 8];
|
|
@@ -221,7 +224,7 @@ export var useApplePay = function (_a) {
|
|
|
221
224
|
if (debug) {
|
|
222
225
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.hostname));
|
|
223
226
|
}
|
|
224
|
-
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id || profileData.merchant.id }), event.validationURL, window.location.hostname, merchant.identifier || merchant.id || profileData.merchant.id,
|
|
227
|
+
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id || profileData.merchant.id }), event.validationURL, window.location.hostname, merchant.identifier || merchant.id || profileData.merchant.id, paymentProcessor)];
|
|
225
228
|
case 2:
|
|
226
229
|
merchantSession = _a.sent();
|
|
227
230
|
if (debug)
|
|
@@ -387,12 +390,19 @@ export var useApplePay = function (_a) {
|
|
|
387
390
|
var handleClick = useCallback(function () {
|
|
388
391
|
var _a, _b;
|
|
389
392
|
if (isIframeIntegration) {
|
|
390
|
-
(_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
|
|
393
|
+
(_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData, paymentProcessor: paymentProcessor }));
|
|
391
394
|
return;
|
|
392
395
|
}
|
|
393
396
|
onApplePayButtonClicked();
|
|
394
397
|
(_b = buttonProps.onClick) === null || _b === void 0 ? void 0 : _b.call(buttonProps);
|
|
395
|
-
}, [
|
|
398
|
+
}, [
|
|
399
|
+
applePayRequestConfiguration,
|
|
400
|
+
applePayRequestData,
|
|
401
|
+
buttonProps,
|
|
402
|
+
isIframeIntegration,
|
|
403
|
+
onApplePayButtonClicked,
|
|
404
|
+
paymentProcessor
|
|
405
|
+
]);
|
|
396
406
|
useEffect(function () {
|
|
397
407
|
initialize(metaData);
|
|
398
408
|
}, []);
|