@tap-payments/apple-pay-button 0.0.88-development → 0.0.90-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.
@@ -10,7 +10,6 @@ export interface ChargeRequestBody {
10
10
  product: string;
11
11
  threeDSecure?: boolean;
12
12
  save_card: boolean;
13
- fee: number;
14
13
  customer: {
15
14
  id?: string;
16
15
  first_name?: string;
@@ -1,6 +1,7 @@
1
- import { ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData } from '../@types';
1
+ import { ApplePayButtonProps, ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData, IntegrationType } from '../@types';
2
+ import { Scope } from '@tap-payments/acceptance-sdk';
2
3
  interface UseApplePayParams {
3
- buttonProps: any;
4
+ buttonProps: ApplePayButtonProps;
4
5
  }
5
6
  export declare const useApplePay: ({ buttonProps }: UseApplePayParams) => {
6
7
  onClick: () => void;
@@ -10,12 +11,71 @@ export declare const useApplePay: ({ buttonProps }: UseApplePayParams) => {
10
11
  disabled: boolean;
11
12
  applePayRequestData: ApplePayRequestData | undefined;
12
13
  applePayRequestConfiguration: Omit<ApplePayDataToLunchSDKFromMerchantSide, "applePayRequestData"> | undefined;
13
- mappedProps: any;
14
+ mappedProps: {
15
+ interface: {
16
+ locale?: import("@tap-payments/acceptance-sdk").Locale | undefined;
17
+ theme?: import("@tap-payments/acceptance-sdk").ThemeMode | undefined;
18
+ edges?: import("@tap-payments/acceptance-sdk").Edges | undefined;
19
+ colorStyle?: import("@tap-payments/acceptance-sdk").ColorStyle | undefined;
20
+ loader?: boolean | undefined;
21
+ userExperience?: (string & {}) | "popup" | "page" | undefined;
22
+ powered?: boolean | undefined;
23
+ direction?: import("@tap-payments/acceptance-sdk").Direction | undefined;
24
+ cardDirection?: import("@tap-payments/acceptance-sdk").Direction | undefined;
25
+ } | undefined;
26
+ merchant: import("@tap-payments/acceptance-sdk/build/@types").Merchant & {
27
+ identifier?: string | undefined;
28
+ };
29
+ onClick?: ((data?: ApplePayDataToLunchSDKFromMerchantSide | undefined) => void) | undefined;
30
+ integration?: IntegrationType | undefined;
31
+ debug?: boolean | undefined;
32
+ scope: Scope;
33
+ order: import("@tap-payments/acceptance-sdk/build/@types").Order;
34
+ invoice?: import("@tap-payments/acceptance-sdk/build/@types").Invoice | undefined;
35
+ operator: import("@tap-payments/acceptance-sdk/build/@types").Operator;
36
+ customer: import("@tap-payments/acceptance-sdk").CustomerWithNameOnCard;
37
+ features?: import("@tap-payments/acceptance-sdk/build/@types").Features | undefined;
38
+ acceptance?: import("@tap-payments/acceptance-sdk/build/@types").Acceptance | undefined;
39
+ transaction?: import("@tap-payments/acceptance-sdk/build/@types").Transaction | undefined;
40
+ fieldVisibility?: import("@tap-payments/acceptance-sdk/build/@types").FieldVisibility | undefined;
41
+ post?: {
42
+ [key: string]: any;
43
+ url: string;
44
+ } | undefined;
45
+ redirect?: {
46
+ [key: string]: any;
47
+ url: string;
48
+ } | undefined;
49
+ metadata?: ({
50
+ headers?: ({
51
+ authorization: string;
52
+ mdn: string;
53
+ application: string;
54
+ ip?: string | undefined;
55
+ session?: string | undefined;
56
+ } & {
57
+ [x: string]: any;
58
+ }) | undefined;
59
+ profileData?: import("@tap-payments/acceptance-sdk").CheckoutProfileResponse | undefined;
60
+ } & {
61
+ [x: string]: any;
62
+ }) | undefined;
63
+ platform?: {
64
+ id: string;
65
+ } | undefined;
66
+ onReady?: (() => void) | undefined;
67
+ onError?: ((error: any) => void) | undefined;
68
+ onCancel?: (() => void) | undefined;
69
+ onSuccess?: ((data: any) => void) | undefined;
70
+ onBinIdentification?: ((data: any) => void) | undefined;
71
+ onChargeCreated?: ((charge: Record<string, any>) => void) | undefined;
72
+ onOrderCreated?: ((orderId: string) => void) | undefined;
73
+ };
14
74
  theme: import("@tap-payments/acceptance-sdk").ThemeMode;
15
75
  isRounded: boolean;
16
76
  success: boolean;
17
77
  error: boolean;
18
- applePayPaymentMethodOptions: import("@tap-payments/acceptance-sdk").PaymentMethod | null;
78
+ applePayPaymentMethodOptions: import("@tap-payments/acceptance-sdk").PaymentMethod | null | undefined;
19
79
  profileData: import("@tap-payments/acceptance-sdk").CheckoutProfileResponse | undefined;
20
80
  };
21
81
  export {};
@@ -47,12 +47,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  };
48
48
  import { useCallback, useEffect, useMemo, useState } from 'react';
49
49
  import { ApplePayVersion, MW_BASE_URL } from '../constants';
50
- import { prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
50
+ import { PAYMENT_METHOD_KEY, prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
51
51
  import { IntegrationType } from '../@types';
52
52
  import { useMerchantApplePay } from './useMerchantApplePay';
53
- import { getApplePayPaymentMethod, getDefaultThemeMode } from '../utils';
53
+ import { getDefaultThemeMode } from '../utils';
54
54
  import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
55
- import { areAllTheObjectStringValuesValid, ChargeCode, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
55
+ import { areAllTheObjectStringValuesValid, ChargeCode, getPaymentMethod, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
56
+ var FALLBACK_MERCHANT_IDENTIFIER = 'merchant.tap.gosell';
56
57
  export var useApplePay = function (_a) {
57
58
  var buttonProps = _a.buttonProps;
58
59
  var _b = useState(), applePayRequestData = _b[0], setApplePayRequestData = _b[1];
@@ -63,8 +64,8 @@ export var useApplePay = function (_a) {
63
64
  var _g = useState(false), loading = _g[0], setLoading = _g[1];
64
65
  var _h = useState(false), isRounded = _h[0], setIsRounded = _h[1];
65
66
  var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
66
- var _j = mappedProps, interfaceObj = _j.interface, merchant = _j.merchant, customer = _j.customer, acceptance = _j.acceptance, scope = _j.scope, debug = _j.debug, onError = _j.onError, onSuccess = _j.onSuccess, onCancel = _j.onCancel, onReady = _j.onReady, metadata = _j.metadata, operator = _j.operator, order = _j.order, onOrderCreated = _j.onOrderCreated, transaction = _j.transaction, post = _j.post, redirect = _j.redirect, integration = _j.integration;
67
- var _k = metadata || {}, profileData = _k.profileData, headers = _k.headers;
67
+ 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, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect, integration = mappedProps.integration, features = mappedProps.features;
68
+ var _j = metadata || {}, profileData = _j.profileData, headers = _j.headers;
68
69
  var isIframeIntegration = integration === IntegrationType.IFRAME;
69
70
  var isWebViewIntegration = integration === IntegrationType.WEBVIEW;
70
71
  useMerchantApplePay({
@@ -82,27 +83,24 @@ export var useApplePay = function (_a) {
82
83
  redirect: redirect,
83
84
  setError: setError,
84
85
  setSuccess: setSuccess,
85
- setLoading: setLoading
86
+ setLoading: setLoading,
87
+ features: features
86
88
  });
87
89
  var theme = useMemo(function () { return getDefaultThemeMode(interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme); }, [interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme]);
88
90
  var applePayPaymentMethodOptions = useMemo(function () {
89
91
  if (!profileData)
90
92
  return null;
91
- return getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
93
+ return getPaymentMethod(profileData.payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
92
94
  }, [profileData]);
93
95
  var merchantValidationRequestData = useMemo(function () {
94
96
  if (!profileData)
95
97
  return null;
96
- var merchantIdentifierByIntegration = isWebViewIntegration
97
- ? applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier
98
- : merchant.identifier || merchant.id;
99
- var merchantIdentifier = merchantIdentifierByIntegration || profileData.merchant.id;
100
98
  return {
101
99
  merchantId: merchant.id || (profileData === null || profileData === void 0 ? void 0 : profileData.merchant.id),
102
100
  merchantName: profileData.merchant.name,
103
101
  validationUrl: '',
104
102
  origin: window.location.hostname,
105
- merchantIdentifier: merchantIdentifier
103
+ merchantIdentifier: (applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier) || FALLBACK_MERCHANT_IDENTIFIER
106
104
  };
107
105
  }, [merchant, profileData === null || profileData === void 0 ? void 0 : profileData.merchant, isWebViewIntegration, applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier]);
108
106
  var initialize = function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -115,6 +113,9 @@ export var useApplePay = function (_a) {
115
113
  if (!shallRenderApplePay()) {
116
114
  throw new Error('The device/customer is not eligible to use ApplePay');
117
115
  }
116
+ if (!applePayPaymentMethodOptions) {
117
+ throw new Error("000::".concat(PAYMENT_METHOD_KEY.toUpperCase(), " is not configured in your payment options"));
118
+ }
118
119
  if (!profileData) {
119
120
  throw new Error('000::Profile data is not available');
120
121
  }
@@ -227,15 +228,15 @@ export var useApplePay = function (_a) {
227
228
  }); };
228
229
  session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
229
230
  var _a, paymentData, paymentMethod, transactionIdentifier, _b, data, tokenId, supportCurrency, transactionRequest, transactionResponse, _c, successState, error_2;
230
- var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
231
- return __generator(this, function (_1) {
232
- switch (_1.label) {
231
+ var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
232
+ return __generator(this, function (_4) {
233
+ switch (_4.label) {
233
234
  case 0:
234
235
  if (debug)
235
236
  console.info('onpaymentauthorized event', event);
236
- _1.label = 1;
237
+ _4.label = 1;
237
238
  case 1:
238
- _1.trys.push([1, 16, 17, 18]);
239
+ _4.trys.push([1, 16, 17, 18]);
239
240
  _a = (_d = event.payment.token) !== null && _d !== void 0 ? _d : {}, paymentData = _a.paymentData, paymentMethod = _a.paymentMethod, transactionIdentifier = _a.transactionIdentifier;
240
241
  _b = scope;
241
242
  switch (_b) {
@@ -247,25 +248,25 @@ export var useApplePay = function (_a) {
247
248
  return [3, 14];
248
249
  case 2: return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token))];
249
250
  case 3:
250
- _1.sent();
251
+ _4.sent();
251
252
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
252
253
  return [3, 15];
253
254
  case 4:
254
255
  setLoading(true);
255
256
  return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
256
257
  case 5:
257
- data = _1.sent();
258
+ data = _4.sent();
258
259
  setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
259
260
  return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
260
261
  case 6:
261
- _1.sent();
262
+ _4.sent();
262
263
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
263
264
  return [3, 15];
264
265
  case 7:
265
266
  setLoading(true);
266
267
  return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
267
268
  case 8:
268
- tokenId = (_1.sent()).id;
269
+ tokenId = (_4.sent()).id;
269
270
  supportCurrency = ((_f = (_e = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _e === void 0 ? void 0 : _e.supported_currencies) !== null && _f !== void 0 ? _f : [])[0];
270
271
  transactionRequest = {
271
272
  auto: (_g = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _g === void 0 ? void 0 : _g.auto,
@@ -284,15 +285,14 @@ export var useApplePay = function (_a) {
284
285
  number: (_x = (_w = (_v = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _v === void 0 ? void 0 : _v.phone) === null || _w === void 0 ? void 0 : _w.number) !== null && _x !== void 0 ? _x : ''
285
286
  }
286
287
  },
287
- fee: 0,
288
288
  merchant: {
289
289
  id: (_z = (_y = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _y === void 0 ? void 0 : _y.id) !== null && _z !== void 0 ? _z : ''
290
290
  },
291
291
  order: (_0 = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _0 === void 0 ? void 0 : _0.order,
292
292
  product: 'Apple-Pay-Button',
293
- save_card: false,
293
+ save_card: !!((_1 = features === null || features === void 0 ? void 0 : features.customerCards) === null || _1 === void 0 ? void 0 : _1.saveCard),
294
294
  source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
295
- threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
295
+ threeDSecure: (_3 = (_2 = transaction === null || transaction === void 0 ? void 0 : transaction.authenticate) === null || _2 === void 0 ? void 0 : _2.required) !== null && _3 !== void 0 ? _3 : true,
296
296
  hashstring: operator.hashstring,
297
297
  redirect: redirect,
298
298
  metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
@@ -307,12 +307,12 @@ export var useApplePay = function (_a) {
307
307
  if (!(scope === Scope.AUTHORIZE)) return [3, 10];
308
308
  return [4, appService.createAuthorize(transactionRequest)];
309
309
  case 9:
310
- _c = _1.sent();
310
+ _c = _4.sent();
311
311
  return [3, 12];
312
312
  case 10: return [4, appService.createCharge(transactionRequest)];
313
313
  case 11:
314
- _c = _1.sent();
315
- _1.label = 12;
314
+ _c = _4.sent();
315
+ _4.label = 12;
316
316
  case 12:
317
317
  transactionResponse = _c;
318
318
  successState = scope === Scope.AUTHORIZE ? ChargeCode.AUTHORIZED : ChargeCode.SUCCESS;
@@ -324,17 +324,17 @@ export var useApplePay = function (_a) {
324
324
  }
325
325
  return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse))];
326
326
  case 13:
327
- _1.sent();
327
+ _4.sent();
328
328
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
329
329
  return [3, 15];
330
330
  case 14:
331
331
  console.error('We only support AppleToken and TapToken for now');
332
332
  console.info('Completing payment with status: STATUS_FAILURE');
333
333
  session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
334
- _1.label = 15;
334
+ _4.label = 15;
335
335
  case 15: return [3, 18];
336
336
  case 16:
337
- error_2 = _1.sent();
337
+ error_2 = _4.sent();
338
338
  if (debug)
339
339
  console.error('error in onpaymentauthorized', error_2);
340
340
  setError(true);
@@ -16,6 +16,7 @@ interface ApplePayRequestData {
16
16
  operator: ApplePayButtonProps['operator'];
17
17
  redirect?: ApplePayButtonProps['redirect'];
18
18
  post?: ApplePayButtonProps['post'];
19
+ features?: ApplePayButtonProps['features'];
19
20
  }
20
- export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
21
+ export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post, features }: ApplePayRequestData) => void;
21
22
  export {};
@@ -48,25 +48,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  import * as React from 'react';
49
49
  import appService from '../api';
50
50
  import { CHARGE_CODE } from '../@types';
51
- import { Scope } from '@tap-payments/acceptance-sdk';
51
+ import { getPaymentMethod, Scope } from '@tap-payments/acceptance-sdk';
52
+ import { PAYMENT_METHOD_KEY } from '../utils';
52
53
  var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
53
54
  export var useMerchantApplePay = function (_a) {
54
- 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;
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;
55
56
  var onMessageReceived = React.useCallback(function (_a) {
56
57
  var message = _a.data;
57
58
  return __awaiter(void 0, void 0, void 0, function () {
58
- var _b, event, data, _c, paymentData, paymentMethod, transactionIdentifier, _d, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _e, successState, e_1;
59
- var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
60
- return __generator(this, function (_3) {
61
- switch (_3.label) {
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) {
62
63
  case 0:
63
64
  _b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
64
65
  if (!data || event !== EVENT_NAME)
65
66
  return [2];
66
67
  _c = data !== null && data !== void 0 ? data : {}, paymentData = _c.paymentData, paymentMethod = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
67
- _3.label = 1;
68
+ applyPayPaymentMethod = getPaymentMethod((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods) || [], PAYMENT_METHOD_KEY);
69
+ _6.label = 1;
68
70
  case 1:
69
- _3.trys.push([1, 13, 14, 15]);
71
+ _6.trys.push([1, 13, 14, 15]);
70
72
  _d = scope;
71
73
  switch (_d) {
72
74
  case Scope.APPLE_PAY_TOKEN: return [3, 2];
@@ -82,7 +84,7 @@ export var useMerchantApplePay = function (_a) {
82
84
  setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
83
85
  return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
84
86
  case 4:
85
- response = _3.sent();
87
+ response = _6.sent();
86
88
  setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
87
89
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
88
90
  return [3, 12];
@@ -90,7 +92,7 @@ export var useMerchantApplePay = function (_a) {
90
92
  setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
91
93
  return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
92
94
  case 6:
93
- tokenId = (_3.sent()).id;
95
+ tokenId = (_6.sent()).id;
94
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];
95
97
  transactionRequest = {
96
98
  auto: (_h = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _h === void 0 ? void 0 : _h.auto,
@@ -109,15 +111,14 @@ export var useMerchantApplePay = function (_a) {
109
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 : ''
110
112
  }
111
113
  },
112
- fee: 0,
113
114
  merchant: {
114
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 : ''
115
116
  },
116
117
  order: (_1 = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _1 === void 0 ? void 0 : _1.order,
117
118
  product: 'Apple-Pay-Button',
118
- save_card: false,
119
+ save_card: !!((_2 = features === null || features === void 0 ? void 0 : features.customerCards) === null || _2 === void 0 ? void 0 : _2.saveCard),
119
120
  source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
120
- threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
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,
121
122
  hashstring: operator.hashstring,
122
123
  redirect: redirect,
123
124
  metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
@@ -132,12 +133,12 @@ export var useMerchantApplePay = function (_a) {
132
133
  if (!(scope === Scope.AUTHORIZE)) return [3, 8];
133
134
  return [4, appService.createAuthorize(transactionRequest)];
134
135
  case 7:
135
- _e = _3.sent();
136
+ _e = _6.sent();
136
137
  return [3, 10];
137
138
  case 8: return [4, appService.createCharge(transactionRequest)];
138
139
  case 9:
139
- _e = _3.sent();
140
- _3.label = 10;
140
+ _e = _6.sent();
141
+ _6.label = 10;
141
142
  case 10:
142
143
  transactionResponse = _e;
143
144
  successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
@@ -155,14 +156,14 @@ export var useMerchantApplePay = function (_a) {
155
156
  return [3, 12];
156
157
  case 12: return [3, 15];
157
158
  case 13:
158
- e_1 = _3.sent();
159
+ e_1 = _6.sent();
159
160
  if (!onError)
160
161
  return [2];
161
162
  if (e_1.errors) {
162
163
  onError(e_1.errors);
163
164
  return [2];
164
165
  }
165
- if ((_2 = e_1.response) === null || _2 === void 0 ? void 0 : _2.data.errors) {
166
+ if ((_5 = e_1.response) === null || _5 === void 0 ? void 0 : _5.data.errors) {
166
167
  onError(e_1.response.data.errors);
167
168
  return [2];
168
169
  }
@@ -1,6 +1,6 @@
1
1
  import { Acceptance, ApplePayButtonProps, ApplePayRequestData, ProfileData } from '../@types';
2
+ export declare const PAYMENT_METHOD_KEY = "apple_pay";
2
3
  export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
3
- export declare const getApplePayPaymentMethod: (paymentMethods: ProfileData['payment_options']['payment_methods']) => import("@tap-payments/acceptance-sdk").PaymentMethod;
4
4
  export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
5
5
  supportedNetworks: Acceptance['supportedSchemes'];
6
6
  merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
@@ -9,6 +9,6 @@ export declare const getApplePayRequest: ({ order, customer, supportedNetworks,
9
9
  }) => ApplePayRequestData;
10
10
  export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: ProfileData & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
11
11
  applePaySessionRequest: ApplePayRequestData;
12
- paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod;
12
+ paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod | undefined;
13
13
  };
14
14
  export declare const shallRenderApplePay: () => boolean;
@@ -1,4 +1,6 @@
1
1
  import { getMerchantCapabilities } from './defaultValues';
2
+ import { getPaymentMethod } from '@tap-payments/acceptance-sdk';
3
+ export var PAYMENT_METHOD_KEY = 'apple_pay';
2
4
  export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
3
5
  var toLowerCase = function (item) { return item.toLowerCase(); };
4
6
  if (!supportedNetworksOptions)
@@ -15,16 +17,6 @@ export var validateSupportedNetworks = function (supportedNetworksOptions, merch
15
17
  }
16
18
  return supportedNetworks.map(toLowerCase);
17
19
  };
18
- export var getApplePayPaymentMethod = function (paymentMethods) {
19
- var paymentMethod = paymentMethods.find(function (_a) {
20
- var name = _a.name, payment_type = _a.payment_type;
21
- return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
22
- });
23
- if (!paymentMethod) {
24
- throw new Error('apple_pay is not configured in your payment options');
25
- }
26
- return paymentMethod;
27
- };
28
20
  export var getApplePayRequest = function (_a) {
29
21
  var _b, _c, _d, _e, _f, _g, _h, _j, _k;
30
22
  var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
@@ -47,8 +39,8 @@ export var getApplePayRequest = function (_a) {
47
39
  };
48
40
  export var prepareApplePayRequest = function (_a) {
49
41
  var payment_options = _a.payment_options, merchant = _a.merchant, order = _a.order, customer = _a.customer, acceptance = _a.acceptance;
50
- var paymentMethod = getApplePayPaymentMethod(payment_options.payment_methods || []);
51
- var supportedNetworks = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
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);
52
44
  var request = getApplePayRequest({
53
45
  countryCode: merchant.country_code,
54
46
  order: order,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.88-development",
3
+ "version": "0.0.90-development",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "license": "ISC",
31
31
  "dependencies": {
32
- "@tap-payments/acceptance-sdk": "0.0.58",
32
+ "@tap-payments/acceptance-sdk": "0.0.61",
33
33
  "@tap-payments/browser-info": "^1.0.2",
34
34
  "@tap-payments/web-error-handing": "^1.0.1",
35
35
  "axios": "^1.2.2",