@tap-payments/apple-pay-button 0.0.93-development → 0.0.95-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/checkoutProfile.d.ts +216 -216
  6. package/build/@types/checkoutProfile.js +1 -1
  7. package/build/@types/enums.d.ts +44 -44
  8. package/build/@types/enums.js +51 -51
  9. package/build/@types/index.d.ts +5 -6
  10. package/build/@types/index.js +5 -6
  11. package/build/@types/tapLocalisation.d.ts +193 -193
  12. package/build/@types/tapLocalisation.js +1 -1
  13. package/build/@types/tapTheme.d.ts +842 -842
  14. package/build/@types/tapTheme.js +1 -1
  15. package/build/api.d.ts +7 -31
  16. package/build/api.js +84 -236
  17. package/build/constants/index.d.ts +4 -4
  18. package/build/constants/index.js +4 -4
  19. package/build/features/ApplePayButton/ApplePayButton.d.ts +4 -4
  20. package/build/features/ApplePayButton/ApplePayButton.js +48 -48
  21. package/build/features/ApplePayButton/index.d.ts +3 -3
  22. package/build/features/ApplePayButton/index.js +2 -2
  23. package/build/hooks/index.d.ts +1 -1
  24. package/build/hooks/index.js +1 -1
  25. package/build/hooks/useApplePay.d.ts +84 -81
  26. package/build/hooks/useApplePay.js +402 -425
  27. package/build/hooks/useMerchantApplePay.d.ts +22 -22
  28. package/build/hooks/useMerchantApplePay.js +167 -190
  29. package/build/index.d.ts +5 -5
  30. package/build/index.js +14 -14
  31. package/build/utils/config.d.ts +14 -14
  32. package/build/utils/config.js +59 -59
  33. package/build/utils/defaultValues.d.ts +2 -2
  34. package/build/utils/defaultValues.js +27 -27
  35. package/build/utils/index.d.ts +3 -3
  36. package/build/utils/index.js +3 -3
  37. package/build/utils/theme.d.ts +13 -13
  38. package/build/utils/theme.js +62 -62
  39. package/package.json +109 -109
  40. package/build/@types/charge.d.ts +0 -56
  41. package/build/@types/charge.js +0 -1
@@ -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 }: ApplePayRequestData) => void;
22
+ export {};
@@ -1,190 +1,167 @@
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
- };
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 { checkoutService } 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;
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;
61
+ return __generator(this, function (_g) {
62
+ switch (_g.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
+ _g.label = 1;
70
+ case 1:
71
+ _g.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, checkoutService.tokenize({
86
+ type: 'applepay',
87
+ token_data: __assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier })
88
+ })];
89
+ case 4:
90
+ response = _g.sent();
91
+ setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
92
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
93
+ return [3, 12];
94
+ case 5:
95
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
96
+ return [4, checkoutService.tokenize({
97
+ type: 'applepay',
98
+ token_data: __assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier })
99
+ })];
100
+ case 6:
101
+ tokenId = (_g.sent()).id;
102
+ supportedCurrency = getSelectedCurrency((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.supported_currencies) || [], order, applyPayPaymentMethod);
103
+ transactionRequest = {
104
+ intent: transaction === null || transaction === void 0 ? void 0 : transaction.intent,
105
+ selected_amount: supportedCurrency === null || supportedCurrency === void 0 ? void 0 : supportedCurrency.amount,
106
+ selected_currency: supportedCurrency === null || supportedCurrency === void 0 ? void 0 : supportedCurrency.currency,
107
+ product: 'Apple-Pay-Button',
108
+ source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' }
109
+ };
110
+ if (!(scope === Scope.AUTHORIZE)) return [3, 8];
111
+ return [4, checkoutService.authorize(transactionRequest)];
112
+ case 7:
113
+ _e = _g.sent();
114
+ return [3, 10];
115
+ case 8: return [4, checkoutService.charge(transactionRequest)];
116
+ case 9:
117
+ _e = _g.sent();
118
+ _g.label = 10;
119
+ case 10:
120
+ transactionResponse = _e;
121
+ successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
122
+ if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
123
+ setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
124
+ }
125
+ else {
126
+ setError === null || setError === void 0 ? void 0 : setError(true);
127
+ }
128
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
129
+ return [3, 12];
130
+ case 11:
131
+ console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
132
+ onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '000' });
133
+ return [3, 12];
134
+ case 12: return [3, 15];
135
+ case 13:
136
+ e_1 = _g.sent();
137
+ if (!onError)
138
+ return [2];
139
+ if (e_1.errors) {
140
+ onError(e_1.errors);
141
+ return [2];
142
+ }
143
+ if ((_f = e_1.response) === null || _f === void 0 ? void 0 : _f.data.errors) {
144
+ onError(e_1.response.data.errors);
145
+ return [2];
146
+ }
147
+ if (e_1.message) {
148
+ onError([{ message: e_1.message, code: '400' }]);
149
+ return [2];
150
+ }
151
+ onError(e_1);
152
+ return [3, 15];
153
+ case 14:
154
+ setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
155
+ return [7];
156
+ case 15: return [2];
157
+ }
158
+ });
159
+ });
160
+ }, [onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post]);
161
+ React.useEffect(function () {
162
+ if (!isIframeIntegration)
163
+ return;
164
+ window.addEventListener('message', onMessageReceived);
165
+ return function () { return window.removeEventListener('message', onMessageReceived); };
166
+ }, [isIframeIntegration, onMessageReceived]);
167
+ };
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;
@@ -1,59 +1,59 @@
1
- import { getMerchantCapabilities } from './defaultValues';
2
- import { getPaymentMethod, getSelectedCurrency } from '@tap-payments/acceptance-sdk';
3
- export var PAYMENT_METHOD_KEY = 'apple_pay';
4
- export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
5
- var toLowerCase = function (item) { return item.toLowerCase(); };
6
- if (!supportedNetworksOptions)
7
- throw new Error("There is no supported networks available in your acceptance object");
8
- if (!merchantSupportedNetworks)
9
- return supportedNetworksOptions.map(toLowerCase);
10
- if (merchantSupportedNetworks.length === 0)
11
- return supportedNetworksOptions.map(toLowerCase);
12
- var supportedNetworks = supportedNetworksOptions.filter(function (item) {
13
- return merchantSupportedNetworks.find(function (network) { return network.toLowerCase() === item.toLowerCase(); });
14
- });
15
- if (supportedNetworks.length === 0) {
16
- throw new Error("It seems that there is no supported networks available in based on your acceptance object");
17
- }
18
- return supportedNetworks.map(toLowerCase);
19
- };
20
- export var getApplePayRequest = function (_a) {
21
- var _b, _c, _d, _e, _f, _g, _h, _j, _k;
22
- var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
23
- return {
24
- countryCode: countryCode,
25
- currencyCode: order.currency,
26
- merchantCapabilities: merchantCapabilities,
27
- supportedNetworks: supportedNetworks,
28
- billingContact: customer && {
29
- phoneNumber: ((_c = (_b = customer.contact) === null || _b === void 0 ? void 0 : _b.phone) === null || _c === void 0 ? void 0 : _c.countryCode) || '' + ((_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.number),
30
- emailAddress: (_f = customer.contact) === null || _f === void 0 ? void 0 : _f.email,
31
- givenName: ((_g = customer.name) === null || _g === void 0 ? void 0 : _g.length) ? (_h = customer.name[0]) === null || _h === void 0 ? void 0 : _h.first : '',
32
- familyName: ((_j = customer.name) === null || _j === void 0 ? void 0 : _j.length) ? (_k = customer.name[0]) === null || _k === void 0 ? void 0 : _k.last : ''
33
- },
34
- total: {
35
- amount: Number(order.amount),
36
- label: name
37
- }
38
- };
39
- };
40
- export var prepareApplePayRequest = function (_a) {
41
- var payment_options = _a.payment_options, merchant = _a.merchant, order = _a.order, customer = _a.customer, acceptance = _a.acceptance;
42
- var paymentMethod = getPaymentMethod(payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
43
- var supportedNetworks = validateSupportedNetworks(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
44
- var applypayMethod = getPaymentMethod(payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
45
- var supportedCurrency = getSelectedCurrency(payment_options.supported_currencies || [], order, applypayMethod);
46
- var request = getApplePayRequest({
47
- countryCode: merchant.country_code,
48
- order: supportedCurrency,
49
- customer: customer,
50
- supportedNetworks: supportedNetworks,
51
- merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
52
- name: merchant.name
53
- });
54
- return { applePaySessionRequest: request, paymentMethod: paymentMethod };
55
- };
56
- export var shallRenderApplePay = function () {
57
- var https = window.location.protocol === 'https:';
58
- return https;
59
- };
1
+ import { getMerchantCapabilities } from './defaultValues';
2
+ import { getPaymentMethod, getSelectedCurrency } from '@tap-payments/acceptance-sdk';
3
+ export var PAYMENT_METHOD_KEY = 'apple_pay';
4
+ export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
5
+ var toLowerCase = function (item) { return item.toLowerCase(); };
6
+ if (!supportedNetworksOptions)
7
+ throw new Error("There is no supported networks available in your acceptance object");
8
+ if (!merchantSupportedNetworks)
9
+ return supportedNetworksOptions.map(toLowerCase);
10
+ if (merchantSupportedNetworks.length === 0)
11
+ return supportedNetworksOptions.map(toLowerCase);
12
+ var supportedNetworks = supportedNetworksOptions.filter(function (item) {
13
+ return merchantSupportedNetworks.find(function (network) { return network.toLowerCase() === item.toLowerCase(); });
14
+ });
15
+ if (supportedNetworks.length === 0) {
16
+ throw new Error("It seems that there is no supported networks available in based on your acceptance object");
17
+ }
18
+ return supportedNetworks.map(toLowerCase);
19
+ };
20
+ export var getApplePayRequest = function (_a) {
21
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
22
+ var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
23
+ return {
24
+ countryCode: countryCode,
25
+ currencyCode: order.currency,
26
+ merchantCapabilities: merchantCapabilities,
27
+ supportedNetworks: supportedNetworks,
28
+ billingContact: customer && {
29
+ phoneNumber: ((_c = (_b = customer.contact) === null || _b === void 0 ? void 0 : _b.phone) === null || _c === void 0 ? void 0 : _c.countryCode) || '' + ((_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.number),
30
+ emailAddress: (_f = customer.contact) === null || _f === void 0 ? void 0 : _f.email,
31
+ givenName: ((_g = customer.name) === null || _g === void 0 ? void 0 : _g.length) ? (_h = customer.name[0]) === null || _h === void 0 ? void 0 : _h.first : '',
32
+ familyName: ((_j = customer.name) === null || _j === void 0 ? void 0 : _j.length) ? (_k = customer.name[0]) === null || _k === void 0 ? void 0 : _k.last : ''
33
+ },
34
+ total: {
35
+ amount: Number(order.amount),
36
+ label: name
37
+ }
38
+ };
39
+ };
40
+ export var prepareApplePayRequest = function (_a) {
41
+ var payment_options = _a.payment_options, merchant = _a.merchant, order = _a.order, customer = _a.customer, acceptance = _a.acceptance;
42
+ var paymentMethod = getPaymentMethod(payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
43
+ var supportedNetworks = validateSupportedNetworks(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
44
+ var applypayMethod = getPaymentMethod(payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
45
+ var supportedCurrency = getSelectedCurrency(payment_options.supported_currencies || [], order, applypayMethod);
46
+ var request = getApplePayRequest({
47
+ countryCode: merchant.country_code,
48
+ order: supportedCurrency,
49
+ customer: customer,
50
+ supportedNetworks: supportedNetworks,
51
+ merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
52
+ name: merchant.name
53
+ });
54
+ return { applePaySessionRequest: request, paymentMethod: paymentMethod };
55
+ };
56
+ export var shallRenderApplePay = function () {
57
+ var https = window.location.protocol === 'https:';
58
+ return https;
59
+ };
@@ -1,2 +1,2 @@
1
- import { MerchantCapabilities } from '../@types/enums';
2
- export declare const getMerchantCapabilities: (supportedCards?: Array<string>) => MerchantCapabilities[];
1
+ import { MerchantCapabilities } from '../@types/enums';
2
+ export declare const getMerchantCapabilities: (supportedCards?: Array<string>) => MerchantCapabilities[];