@tap-payments/apple-pay-button 0.0.90-development → 0.0.92-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.
Files changed (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +240 -240
  3. package/build/@types/ApplePayButtonProps.d.ts +56 -56
  4. package/build/@types/ApplePayButtonProps.js +1 -1
  5. package/build/@types/charge.d.ts +56 -56
  6. package/build/@types/charge.js +1 -1
  7. package/build/@types/checkoutProfile.d.ts +216 -216
  8. package/build/@types/checkoutProfile.js +1 -1
  9. package/build/@types/enums.d.ts +44 -45
  10. package/build/@types/enums.js +51 -52
  11. package/build/@types/index.d.ts +6 -6
  12. package/build/@types/index.js +6 -6
  13. package/build/@types/tapLocalisation.d.ts +193 -193
  14. package/build/@types/tapLocalisation.js +1 -1
  15. package/build/@types/tapTheme.d.ts +842 -842
  16. package/build/@types/tapTheme.js +1 -1
  17. package/build/api.d.ts +31 -31
  18. package/build/api.js +236 -236
  19. package/build/constants/index.d.ts +3 -3
  20. package/build/constants/index.js +3 -3
  21. package/build/features/ApplePayButton/ApplePayButton.d.ts +4 -4
  22. package/build/features/ApplePayButton/ApplePayButton.js +48 -48
  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 +81 -81
  28. package/build/hooks/useApplePay.js +424 -425
  29. package/build/hooks/useMerchantApplePay.d.ts +22 -22
  30. package/build/hooks/useMerchantApplePay.js +190 -190
  31. package/build/index.d.ts +5 -5
  32. package/build/index.js +14 -14
  33. package/build/utils/config.d.ts +14 -14
  34. package/build/utils/config.js +59 -57
  35. package/build/utils/defaultValues.d.ts +2 -2
  36. package/build/utils/defaultValues.js +27 -27
  37. package/build/utils/index.d.ts +3 -3
  38. package/build/utils/index.js +3 -3
  39. package/build/utils/theme.d.ts +13 -13
  40. package/build/utils/theme.js +62 -62
  41. package/package.json +109 -109
@@ -1,22 +1,22 @@
1
- import { MetaData, ApplePayButtonProps, ProfileData } from '../@types';
2
- import { Scope } from '@tap-payments/acceptance-sdk';
3
- interface ApplePayRequestData {
4
- isIframeIntegration: boolean;
5
- onError?: (error: any) => void;
6
- onSuccess?: (data: Record<string, any>) => void;
7
- setLoading?: (loading: boolean) => void;
8
- setSuccess?: (success: boolean) => void;
9
- setError?: (error: boolean) => void;
10
- scope: Scope;
11
- profileData?: ProfileData;
12
- merchant: Pick<MetaData['merchant'], 'id'>;
13
- order: ApplePayButtonProps['order'];
14
- customer: ApplePayButtonProps['customer'];
15
- transaction: ApplePayButtonProps['transaction'];
16
- operator: ApplePayButtonProps['operator'];
17
- redirect?: ApplePayButtonProps['redirect'];
18
- post?: ApplePayButtonProps['post'];
19
- features?: ApplePayButtonProps['features'];
20
- }
21
- export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post, features }: ApplePayRequestData) => void;
22
- export {};
1
+ import { MetaData, ApplePayButtonProps, ProfileData } from '../@types';
2
+ import { Scope } from '@tap-payments/acceptance-sdk';
3
+ interface ApplePayRequestData {
4
+ isIframeIntegration: boolean;
5
+ onError?: (error: any) => void;
6
+ onSuccess?: (data: Record<string, any>) => void;
7
+ setLoading?: (loading: boolean) => void;
8
+ setSuccess?: (success: boolean) => void;
9
+ setError?: (error: boolean) => void;
10
+ scope: Scope;
11
+ profileData?: ProfileData;
12
+ merchant: Pick<MetaData['merchant'], 'id'>;
13
+ order: ApplePayButtonProps['order'];
14
+ customer: ApplePayButtonProps['customer'];
15
+ transaction: ApplePayButtonProps['transaction'];
16
+ operator: ApplePayButtonProps['operator'];
17
+ redirect?: ApplePayButtonProps['redirect'];
18
+ post?: ApplePayButtonProps['post'];
19
+ features?: ApplePayButtonProps['features'];
20
+ }
21
+ export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post, features }: ApplePayRequestData) => void;
22
+ export {};
@@ -1,190 +1,190 @@
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 { CHARGE_CODE } from '../@types';
51
- import { getPaymentMethod, Scope } from '@tap-payments/acceptance-sdk';
52
- import { PAYMENT_METHOD_KEY } from '../utils';
53
- var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
54
- export var useMerchantApplePay = function (_a) {
55
- 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, features = _a.features;
56
- var onMessageReceived = React.useCallback(function (_a) {
57
- var message = _a.data;
58
- return __awaiter(void 0, void 0, void 0, function () {
59
- var _b, event, data, _c, paymentData, paymentMethod, transactionIdentifier, applyPayPaymentMethod, _d, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _e, successState, e_1;
60
- var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
61
- return __generator(this, function (_6) {
62
- switch (_6.label) {
63
- case 0:
64
- _b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
65
- if (!data || event !== EVENT_NAME)
66
- return [2];
67
- _c = data !== null && data !== void 0 ? data : {}, paymentData = _c.paymentData, paymentMethod = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
68
- applyPayPaymentMethod = getPaymentMethod((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods) || [], PAYMENT_METHOD_KEY);
69
- _6.label = 1;
70
- case 1:
71
- _6.trys.push([1, 13, 14, 15]);
72
- _d = scope;
73
- switch (_d) {
74
- case Scope.APPLE_PAY_TOKEN: return [3, 2];
75
- case Scope.TOKEN: return [3, 3];
76
- case Scope.AUTHORIZE: return [3, 5];
77
- case Scope.CHARGE: return [3, 5];
78
- }
79
- return [3, 11];
80
- case 2:
81
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
82
- return [3, 12];
83
- case 3:
84
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
85
- return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
86
- case 4:
87
- response = _6.sent();
88
- setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
89
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
90
- return [3, 12];
91
- case 5:
92
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
93
- return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
94
- case 6:
95
- tokenId = (_6.sent()).id;
96
- 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];
97
- transactionRequest = {
98
- auto: (_h = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _h === void 0 ? void 0 : _h.auto,
99
- 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,
100
- 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,
101
- selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
102
- selected_currency: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.currency,
103
- customer: (customer === null || customer === void 0 ? void 0 : customer.id)
104
- ? { id: customer === null || customer === void 0 ? void 0 : customer.id }
105
- : {
106
- email: (_q = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _q === void 0 ? void 0 : _q.email,
107
- first_name: ((_r = customer === null || customer === void 0 ? void 0 : customer.name) === null || _r === void 0 ? void 0 : _r.length) ? customer.name[0].first : '',
108
- last_name: ((_s = customer === null || customer === void 0 ? void 0 : customer.name) === null || _s === void 0 ? void 0 : _s.length) ? customer.name[0].last : '',
109
- phone: {
110
- 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 : '',
111
- 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 : ''
112
- }
113
- },
114
- merchant: {
115
- 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 : ''
116
- },
117
- order: (_1 = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _1 === void 0 ? void 0 : _1.order,
118
- product: 'Apple-Pay-Button',
119
- save_card: !!((_2 = features === null || features === void 0 ? void 0 : features.customerCards) === null || _2 === void 0 ? void 0 : _2.saveCard),
120
- source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
121
- threeDSecure: (_4 = (_3 = transaction === null || transaction === void 0 ? void 0 : transaction.authenticate) === null || _3 === void 0 ? void 0 : _3.required) !== null && _4 !== void 0 ? _4 : true,
122
- hashstring: operator.hashstring,
123
- redirect: redirect,
124
- metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
125
- post: post,
126
- payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
127
- destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
128
- reference: {
129
- order: order === null || order === void 0 ? void 0 : order.reference,
130
- transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
131
- }
132
- };
133
- if (!(scope === Scope.AUTHORIZE)) return [3, 8];
134
- return [4, appService.createAuthorize(transactionRequest)];
135
- case 7:
136
- _e = _6.sent();
137
- return [3, 10];
138
- case 8: return [4, appService.createCharge(transactionRequest)];
139
- case 9:
140
- _e = _6.sent();
141
- _6.label = 10;
142
- case 10:
143
- transactionResponse = _e;
144
- successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
145
- if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
146
- setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
147
- }
148
- else {
149
- setError === null || setError === void 0 ? void 0 : setError(true);
150
- }
151
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
152
- return [3, 12];
153
- case 11:
154
- console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
155
- onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '000' });
156
- return [3, 12];
157
- case 12: return [3, 15];
158
- case 13:
159
- e_1 = _6.sent();
160
- if (!onError)
161
- return [2];
162
- if (e_1.errors) {
163
- onError(e_1.errors);
164
- return [2];
165
- }
166
- if ((_5 = e_1.response) === null || _5 === void 0 ? void 0 : _5.data.errors) {
167
- onError(e_1.response.data.errors);
168
- return [2];
169
- }
170
- if (e_1.message) {
171
- onError([{ message: e_1.message, code: '400' }]);
172
- return [2];
173
- }
174
- onError(e_1);
175
- return [3, 15];
176
- case 14:
177
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
178
- return [7];
179
- case 15: return [2];
180
- }
181
- });
182
- });
183
- }, [onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post]);
184
- React.useEffect(function () {
185
- if (!isIframeIntegration)
186
- return;
187
- window.addEventListener('message', onMessageReceived);
188
- return function () { return window.removeEventListener('message', onMessageReceived); };
189
- }, [isIframeIntegration, onMessageReceived]);
190
- };
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 { CHARGE_CODE } from '../@types';
51
+ import { getPaymentMethod, Scope, getSelectedCurrency } from '@tap-payments/acceptance-sdk';
52
+ import { PAYMENT_METHOD_KEY } from '../utils';
53
+ var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
54
+ export var useMerchantApplePay = function (_a) {
55
+ 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, features = _a.features;
56
+ var onMessageReceived = React.useCallback(function (_a) {
57
+ var message = _a.data;
58
+ return __awaiter(void 0, void 0, void 0, function () {
59
+ var _b, event, data, _c, paymentData, paymentMethod, transactionIdentifier, applyPayPaymentMethod, _d, response, tokenId, supportedCurrency, transactionRequest, transactionResponse, _e, successState, e_1;
60
+ var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
61
+ return __generator(this, function (_4) {
62
+ switch (_4.label) {
63
+ case 0:
64
+ _b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
65
+ if (!data || event !== EVENT_NAME)
66
+ return [2];
67
+ _c = data !== null && data !== void 0 ? data : {}, paymentData = _c.paymentData, paymentMethod = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
68
+ applyPayPaymentMethod = getPaymentMethod((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods) || [], PAYMENT_METHOD_KEY);
69
+ _4.label = 1;
70
+ case 1:
71
+ _4.trys.push([1, 13, 14, 15]);
72
+ _d = scope;
73
+ switch (_d) {
74
+ case Scope.APPLE_PAY_TOKEN: return [3, 2];
75
+ case Scope.TOKEN: return [3, 3];
76
+ case Scope.AUTHORIZE: return [3, 5];
77
+ case Scope.CHARGE: return [3, 5];
78
+ }
79
+ return [3, 11];
80
+ case 2:
81
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
82
+ return [3, 12];
83
+ case 3:
84
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
85
+ return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
86
+ case 4:
87
+ response = _4.sent();
88
+ setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
89
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
90
+ return [3, 12];
91
+ case 5:
92
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
93
+ return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
94
+ case 6:
95
+ tokenId = (_4.sent()).id;
96
+ supportedCurrency = getSelectedCurrency((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.supported_currencies) || [], order, applyPayPaymentMethod);
97
+ transactionRequest = {
98
+ auto: (_f = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _f === void 0 ? void 0 : _f.auto,
99
+ amount: (_j = (_h = (_g = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _g === void 0 ? void 0 : _g.order) === null || _h === void 0 ? void 0 : _h.amount) !== null && _j !== void 0 ? _j : order.amount,
100
+ currency: (_m = (_l = (_k = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _k === void 0 ? void 0 : _k.order) === null || _l === void 0 ? void 0 : _l.currency) !== null && _m !== void 0 ? _m : order.currency,
101
+ selected_amount: supportedCurrency === null || supportedCurrency === void 0 ? void 0 : supportedCurrency.amount,
102
+ selected_currency: supportedCurrency === null || supportedCurrency === void 0 ? void 0 : supportedCurrency.currency,
103
+ customer: (customer === null || customer === void 0 ? void 0 : customer.id)
104
+ ? { id: customer === null || customer === void 0 ? void 0 : customer.id }
105
+ : {
106
+ email: (_o = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _o === void 0 ? void 0 : _o.email,
107
+ first_name: ((_p = customer === null || customer === void 0 ? void 0 : customer.name) === null || _p === void 0 ? void 0 : _p.length) ? customer.name[0].first : '',
108
+ last_name: ((_q = customer === null || customer === void 0 ? void 0 : customer.name) === null || _q === void 0 ? void 0 : _q.length) ? customer.name[0].last : '',
109
+ phone: {
110
+ country_code: (_t = (_s = (_r = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _r === void 0 ? void 0 : _r.phone) === null || _s === void 0 ? void 0 : _s.countryCode) !== null && _t !== void 0 ? _t : '',
111
+ number: (_w = (_v = (_u = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _u === void 0 ? void 0 : _u.phone) === null || _v === void 0 ? void 0 : _v.number) !== null && _w !== void 0 ? _w : ''
112
+ }
113
+ },
114
+ merchant: {
115
+ id: (_y = (_x = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _x === void 0 ? void 0 : _x.id) !== null && _y !== void 0 ? _y : ''
116
+ },
117
+ order: (_z = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _z === void 0 ? void 0 : _z.order,
118
+ product: 'Apple-Pay-Button',
119
+ save_card: !!((_0 = features === null || features === void 0 ? void 0 : features.customerCards) === null || _0 === void 0 ? void 0 : _0.saveCard),
120
+ source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
121
+ threeDSecure: (_2 = (_1 = transaction === null || transaction === void 0 ? void 0 : transaction.authenticate) === null || _1 === void 0 ? void 0 : _1.required) !== null && _2 !== void 0 ? _2 : true,
122
+ hashstring: operator.hashstring,
123
+ redirect: redirect,
124
+ metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
125
+ post: post,
126
+ payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
127
+ destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
128
+ reference: {
129
+ order: order === null || order === void 0 ? void 0 : order.reference,
130
+ transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
131
+ }
132
+ };
133
+ if (!(scope === Scope.AUTHORIZE)) return [3, 8];
134
+ return [4, appService.createAuthorize(transactionRequest)];
135
+ case 7:
136
+ _e = _4.sent();
137
+ return [3, 10];
138
+ case 8: return [4, appService.createCharge(transactionRequest)];
139
+ case 9:
140
+ _e = _4.sent();
141
+ _4.label = 10;
142
+ case 10:
143
+ transactionResponse = _e;
144
+ successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
145
+ if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
146
+ setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
147
+ }
148
+ else {
149
+ setError === null || setError === void 0 ? void 0 : setError(true);
150
+ }
151
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
152
+ return [3, 12];
153
+ case 11:
154
+ console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
155
+ onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '000' });
156
+ return [3, 12];
157
+ case 12: return [3, 15];
158
+ case 13:
159
+ e_1 = _4.sent();
160
+ if (!onError)
161
+ return [2];
162
+ if (e_1.errors) {
163
+ onError(e_1.errors);
164
+ return [2];
165
+ }
166
+ if ((_3 = e_1.response) === null || _3 === void 0 ? void 0 : _3.data.errors) {
167
+ onError(e_1.response.data.errors);
168
+ return [2];
169
+ }
170
+ if (e_1.message) {
171
+ onError([{ message: e_1.message, code: '400' }]);
172
+ return [2];
173
+ }
174
+ onError(e_1);
175
+ return [3, 15];
176
+ case 14:
177
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
178
+ return [7];
179
+ case 15: return [2];
180
+ }
181
+ });
182
+ });
183
+ }, [onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post]);
184
+ React.useEffect(function () {
185
+ if (!isIframeIntegration)
186
+ return;
187
+ window.addEventListener('message', onMessageReceived);
188
+ return function () { return window.removeEventListener('message', onMessageReceived); };
189
+ }, [isIframeIntegration, onMessageReceived]);
190
+ };
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Edges, Locale, Scope, ThemeMode } from '@tap-payments/acceptance-sdk';
2
- import { ApplePayButtonProps, ApplePayButton, ApplePayRequestData } from './features/ApplePayButton';
3
- import { SupportedNetworks, ButtonType, MerchantCapabilities } from './@types/enums';
4
- export type { ApplePayButtonProps, ApplePayRequestData };
5
- export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
1
+ import { Edges, Locale, Scope, ThemeMode } from '@tap-payments/acceptance-sdk';
2
+ import { ApplePayButtonProps, ApplePayButton, ApplePayRequestData } from './features/ApplePayButton';
3
+ import { SupportedNetworks, ButtonType, MerchantCapabilities } from './@types/enums';
4
+ export type { ApplePayButtonProps, ApplePayRequestData };
5
+ export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
package/build/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { Edges, Locale, Scope, ThemeMode } from '@tap-payments/acceptance-sdk';
2
- import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
3
- import { SupportedNetworks, ButtonType, MerchantCapabilities } from './@types/enums';
4
- export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
5
- window['TapSDKs'] = {
6
- renderApplePayButton: renderApplePayButton,
7
- Scope: Scope,
8
- SupportedNetworks: SupportedNetworks,
9
- Locale: Locale,
10
- ButtonType: ButtonType,
11
- ThemeMode: ThemeMode,
12
- Edges: Edges,
13
- MerchantCapabilities: MerchantCapabilities
14
- };
1
+ import { Edges, Locale, Scope, ThemeMode } from '@tap-payments/acceptance-sdk';
2
+ import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
3
+ import { SupportedNetworks, ButtonType, MerchantCapabilities } from './@types/enums';
4
+ export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
5
+ window['TapSDKs'] = {
6
+ renderApplePayButton: renderApplePayButton,
7
+ Scope: Scope,
8
+ SupportedNetworks: SupportedNetworks,
9
+ Locale: Locale,
10
+ ButtonType: ButtonType,
11
+ ThemeMode: ThemeMode,
12
+ Edges: Edges,
13
+ MerchantCapabilities: MerchantCapabilities
14
+ };
@@ -1,14 +1,14 @@
1
- import { Acceptance, ApplePayButtonProps, ApplePayRequestData, ProfileData } from '../@types';
2
- export declare const PAYMENT_METHOD_KEY = "apple_pay";
3
- export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
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 }: ProfileData & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
11
- applePaySessionRequest: ApplePayRequestData;
12
- paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod | undefined;
13
- };
14
- export declare const shallRenderApplePay: () => boolean;
1
+ import { Acceptance, ApplePayButtonProps, ApplePayRequestData, ProfileData } from '../@types';
2
+ export declare const PAYMENT_METHOD_KEY = "apple_pay";
3
+ export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
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 }: ProfileData & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
11
+ applePaySessionRequest: ApplePayRequestData;
12
+ paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod | undefined;
13
+ };
14
+ export declare const shallRenderApplePay: () => boolean;