tf-checkout-react-native 1.0.24 → 1.0.26

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 (110) hide show
  1. package/README.md +340 -32
  2. package/lib/api/ApiClient.d.ts +2 -5
  3. package/lib/api/ApiClient.js +70 -23
  4. package/lib/api/ApiClient.js.map +1 -1
  5. package/lib/api/types.d.ts +38 -26
  6. package/lib/api/types.js +1 -0
  7. package/lib/api/types.js.map +1 -1
  8. package/lib/components/login/Login.js +7 -4
  9. package/lib/components/login/Login.js.map +1 -1
  10. package/lib/components/login/types.d.ts +6 -1
  11. package/lib/components/stripePayment/StripePayment.js +2 -1
  12. package/lib/components/stripePayment/StripePayment.js.map +1 -1
  13. package/lib/components/stripePayment/styles.d.ts +6 -0
  14. package/lib/components/stripePayment/styles.js +7 -0
  15. package/lib/components/stripePayment/styles.js.map +1 -0
  16. package/lib/components/waitingList/WaitingList.d.ts +3 -2
  17. package/lib/components/waitingList/WaitingList.js +23 -3
  18. package/lib/components/waitingList/WaitingList.js.map +1 -1
  19. package/lib/containers/billingInfo/Billing.d.ts +3 -2
  20. package/lib/containers/billingInfo/Billing.js +238 -118
  21. package/lib/containers/billingInfo/Billing.js.map +1 -1
  22. package/lib/containers/billingInfo/types.d.ts +6 -5
  23. package/lib/containers/checkout/Checkout.d.ts +3 -2
  24. package/lib/containers/checkout/Checkout.js +147 -106
  25. package/lib/containers/checkout/Checkout.js.map +1 -1
  26. package/lib/containers/myOrderDetails/MyOrderDetails.d.ts +3 -2
  27. package/lib/containers/myOrderDetails/MyOrderDetails.js +34 -9
  28. package/lib/containers/myOrderDetails/MyOrderDetails.js.map +1 -1
  29. package/lib/containers/myOrders/MyOrders.d.ts +3 -2
  30. package/lib/containers/myOrders/MyOrders.js +40 -11
  31. package/lib/containers/myOrders/MyOrders.js.map +1 -1
  32. package/lib/containers/purchaseConfirmation/PurchaseConfirmation.d.ts +3 -2
  33. package/lib/containers/purchaseConfirmation/PurchaseConfirmation.js +54 -18
  34. package/lib/containers/purchaseConfirmation/PurchaseConfirmation.js.map +1 -1
  35. package/lib/containers/resaleTickets/ResaleTickets.d.ts +3 -2
  36. package/lib/containers/resaleTickets/ResaleTickets.js +32 -11
  37. package/lib/containers/resaleTickets/ResaleTickets.js.map +1 -1
  38. package/lib/containers/tickets/Tickets.d.ts +3 -2
  39. package/lib/containers/tickets/Tickets.js +41 -11
  40. package/lib/containers/tickets/Tickets.js.map +1 -1
  41. package/lib/containers/tickets/TicketsView.js +0 -1
  42. package/lib/containers/tickets/TicketsView.js.map +1 -1
  43. package/lib/core/BillingCore/BillingCore.js +4 -0
  44. package/lib/core/BillingCore/BillingCore.js.map +1 -1
  45. package/lib/core/BillingCore/BillingCoreTypes.d.ts +3 -1
  46. package/lib/core/CheckoutCore/CheckoutCore.js +4 -0
  47. package/lib/core/CheckoutCore/CheckoutCore.js.map +1 -1
  48. package/lib/core/CheckoutCore/CheckoutCoreTypes.d.ts +3 -1
  49. package/lib/core/LoginCore/LoginCore.js +10 -18
  50. package/lib/core/LoginCore/LoginCore.js.map +1 -1
  51. package/lib/core/LoginCore/LoginCoreHelper.d.ts +2 -0
  52. package/lib/core/LoginCore/LoginCoreHelper.js +19 -0
  53. package/lib/core/LoginCore/LoginCoreHelper.js.map +1 -0
  54. package/lib/core/LoginCore/LoginCoreTypes.d.ts +3 -2
  55. package/lib/core/MyOrdersCore/MyOrdersCore.d.ts +3 -1
  56. package/lib/core/MyOrdersCore/MyOrdersCore.js +4 -0
  57. package/lib/core/MyOrdersCore/MyOrdersCore.js.map +1 -1
  58. package/lib/core/MyOrdersCore/MyOrdersCoreTypes.d.ts +3 -1
  59. package/lib/core/OrderDetailsCore/OrderDetailsCore.d.ts +2 -2
  60. package/lib/core/OrderDetailsCore/OrderDetailsCore.js +4 -0
  61. package/lib/core/OrderDetailsCore/OrderDetailsCore.js.map +1 -1
  62. package/lib/core/OrderDetailsCore/OrderDetailsCoreTypes.d.ts +4 -2
  63. package/lib/core/PurchaseConfirmationCore/PurchaseConfirmationCore.js +4 -0
  64. package/lib/core/PurchaseConfirmationCore/PurchaseConfirmationCore.js.map +1 -1
  65. package/lib/core/PurchaseConfirmationCore/PurchaseConfirmationCoreTypes.d.ts +3 -1
  66. package/lib/core/Session/SessionCoreTypes.d.ts +8 -0
  67. package/lib/core/Session/SessionCoreTypes.js +2 -0
  68. package/lib/core/Session/SessionCoreTypes.js.map +1 -0
  69. package/lib/core/Session/SessionHandle.d.ts +5 -0
  70. package/lib/core/Session/SessionHandle.js +16 -0
  71. package/lib/core/Session/SessionHandle.js.map +1 -0
  72. package/lib/core/TicketsCore/TicketsCore.js +4 -0
  73. package/lib/core/TicketsCore/TicketsCore.js.map +1 -1
  74. package/lib/core/TicketsCore/TicketsCoreTypes.d.ts +3 -1
  75. package/lib/core/WaitingListCore/WaitingListCore.js +4 -0
  76. package/lib/core/WaitingListCore/WaitingListCore.js.map +1 -1
  77. package/lib/core/WaitingListCore/WaitingListCoreTypes.d.ts +3 -1
  78. package/lib/core/index.d.ts +3 -1
  79. package/lib/core/index.js +1 -0
  80. package/lib/core/index.js.map +1 -1
  81. package/lib/helpers/LocalStorage.d.ts +2 -0
  82. package/lib/helpers/LocalStorage.js +6 -0
  83. package/lib/helpers/LocalStorage.js.map +1 -1
  84. package/lib/helpers/RefreshAccessToken.d.ts +2 -0
  85. package/lib/helpers/RefreshAccessToken.js +20 -0
  86. package/lib/helpers/RefreshAccessToken.js.map +1 -0
  87. package/lib/helpers/StringsHelper.d.ts +1 -0
  88. package/lib/helpers/StringsHelper.js +1 -0
  89. package/lib/helpers/StringsHelper.js.map +1 -1
  90. package/lib/helpers/Validators.js.map +1 -1
  91. package/lib/index.d.ts +9 -3
  92. package/lib/index.js +2 -1
  93. package/lib/index.js.map +1 -1
  94. package/lib/types/IEvent.d.ts +5 -0
  95. package/lib/types/ITicket.d.ts +2 -0
  96. package/package.json +1 -1
  97. package/android/.gradle/7.4.2/checksums/checksums.lock +0 -0
  98. package/android/.gradle/7.4.2/checksums/md5-checksums.bin +0 -0
  99. package/android/.gradle/7.4.2/checksums/sha1-checksums.bin +0 -0
  100. package/android/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  101. package/android/.gradle/7.4.2/dependencies-accessors/gc.properties +0 -0
  102. package/android/.gradle/7.4.2/executionHistory/executionHistory.lock +0 -0
  103. package/android/.gradle/7.4.2/fileChanges/last-build.bin +0 -0
  104. package/android/.gradle/7.4.2/fileHashes/fileHashes.lock +0 -0
  105. package/android/.gradle/7.4.2/gc.properties +0 -0
  106. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  107. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  108. package/android/.gradle/vcs-1/gc.properties +0 -0
  109. package/ios/TFCheckoutRNModule.xcodeproj/project.xcworkspace/xcuserdata/jorgegutierrez.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  110. package/ios/TFCheckoutRNModule.xcodeproj/xcshareddata/xcschemes/TFCheckoutRNModule.xcscheme +0 -67
@@ -1,27 +1,39 @@
1
+ /* eslint-disable no-unreachable */
1
2
  import _every from 'lodash/every';
2
3
  import _find from 'lodash/find';
3
4
  import _forEach from 'lodash/forEach';
4
5
  import _map from 'lodash/map';
5
- import React, { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
6
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
6
7
  import { ActivityIndicator, Alert, Image, Linking, Text, View, } from 'react-native';
7
8
  import DeviceCountry, { TYPE_ANY } from 'react-native-device-country';
8
9
  import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
9
10
  import Constants from '../../api/Constants';
10
11
  import { Button, CartTimer, Checkbox, DatePicker, DropdownMaterial, Input, Loading, Login, PhoneInput, } from '../../components';
11
- import { BillingCore } from '../../core';
12
+ import { BillingCore, SessionHandle } from '../../core';
12
13
  import { Config } from '../../helpers/Config';
13
14
  import { getCountryDialCode } from '../../helpers/CountryCodes';
14
15
  import { useDebounced } from '../../helpers/Debounced';
15
16
  import { getData, LocalStorageKeys } from '../../helpers/LocalStorage';
17
+ import { emptyPhone } from '../../helpers/StringsHelper';
16
18
  import { validateAge, validateEmail, validateEmpty, validatePasswords, validatePhoneNumber, } from '../../helpers/Validators';
17
19
  import R from '../../res';
18
20
  import s from './styles';
19
- const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, isPhoneRequired, minimumAge, isBillingRequired, }, loginBrandImages, skipBillingConfig, areAlertsEnabled = true, areLoadingIndicatorsEnabled = true, onLoadingChange, onLoginError, onLoginSuccess, onRegisterError, onRegisterSuccess, onCheckoutSuccess, onCheckoutError, onFetchUserProfileSuccess, onFetchUserProfileError, onFetchCartError, onFetchCartSuccess, onFetchCountriesError, onFetchCountriesSuccess, onFetchStatesError, onFetchStatesSuccess, onSkippingStatusChange, onLogoutSuccess, onLogoutError, onCartExpired, shouldCartTimerNotMinimizeOnTap, }) => {
21
+ /*
22
+ Fields to hide when ticket is free
23
+ - Billing Street Address
24
+ - City
25
+ - State/County
26
+ - Post Code/Zip
27
+ - Country
28
+ */
29
+ const Billing = forwardRef(({ styles, texts, cartProps: { isAgeRequired, isNameRequired, isPhoneRequired, minimumAge, isBillingRequired, isTicketFree, isPhoneHidden, }, loginBrandImages, skipBillingConfig, areAlertsEnabled = true, areLoadingIndicatorsEnabled = true, onLoadingChange, onLoginError, onLoginSuccess, onRegisterError, onRegisterSuccess, onCheckoutSuccess, onCheckoutError, onFetchUserProfileSuccess, onFetchUserProfileError, onFetchCartError, onFetchCartSuccess, onFetchCountriesError, onFetchCountriesSuccess, onFetchStatesError, onFetchStatesSuccess, onSkippingStatusChange, onLogoutSuccess, onLogoutError, onCartExpired, shouldCartTimerNotMinimizeOnTap, }, ref) => {
20
30
  var _a, _b;
21
31
  //#region Labels
22
32
  const holderLabels = useMemo(() => {
23
33
  var _a, _b, _c, _d, _e, _f, _g;
24
- const optional = isNameRequired ? '' : ((_a = texts === null || texts === void 0 ? void 0 : texts.form) === null || _a === void 0 ? void 0 : _a.optional) || '(optional)';
34
+ const optional = isNameRequired
35
+ ? ''
36
+ : ((_a = texts === null || texts === void 0 ? void 0 : texts.form) === null || _a === void 0 ? void 0 : _a.optional) || '(optional)';
25
37
  return {
26
38
  firstName: ((_b = texts === null || texts === void 0 ? void 0 : texts.form) === null || _b === void 0 ? void 0 : _b.holderFirstName)
27
39
  ? `${texts.form.holderFirstName} ${optional}`
@@ -120,7 +132,32 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
120
132
  const storedProfileData = useRef({});
121
133
  const phoneErrorCounter = useRef(0);
122
134
  const billingCoreRef = useRef(null);
135
+ const sessionHandleRef = useRef(null);
123
136
  //#endregion
137
+ //#region Imperative Handler
138
+ useImperativeHandle(ref, () => ({
139
+ async refreshAccessToken(refreshToken) {
140
+ if (!sessionHandleRef.current) {
141
+ return {
142
+ accessTokenError: {
143
+ message: 'Session Handle ref is not initialized',
144
+ },
145
+ };
146
+ }
147
+ const { accessTokenError, accessTokenData } = await sessionHandleRef.current.refreshAccessToken(refreshToken);
148
+ if (!accessTokenError && (accessTokenData === null || accessTokenData === void 0 ? void 0 : accessTokenData.accessToken)) {
149
+ await fetchData();
150
+ }
151
+ return {
152
+ accessTokenData,
153
+ accessTokenError,
154
+ };
155
+ },
156
+ async reloadData() {
157
+ await fetchData();
158
+ },
159
+ }));
160
+ //#endregion Imperative Handler
124
161
  //#region Handlers
125
162
  const handleSetPhoneError = useCallback((error) => {
126
163
  if (isPhoneRequired && phone.length > 0) {
@@ -188,12 +225,15 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
188
225
  storedToken.current = accessToken;
189
226
  }
190
227
  };
191
- const handleOnLoginSuccess = async (userProfile) => {
228
+ const handleOnLoginSuccess = async ({ userProfile, accessTokenData, }) => {
192
229
  var _a, _b, _c;
193
230
  let phoneCountry = 'US';
194
231
  const accessToken = await getData(LocalStorageKeys.ACCESS_TOKEN);
195
232
  const usrProfile = { ...userProfile };
196
- onLoginSuccess === null || onLoginSuccess === void 0 ? void 0 : onLoginSuccess(usrProfile);
233
+ onLoginSuccess === null || onLoginSuccess === void 0 ? void 0 : onLoginSuccess({
234
+ userProfile,
235
+ accessTokenData,
236
+ });
197
237
  try {
198
238
  const deviceCountry = await DeviceCountry.getCountryCode(TYPE_ANY);
199
239
  phoneCountry = deviceCountry.code.toUpperCase();
@@ -212,8 +252,10 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
212
252
  });
213
253
  if (phoneValidError) {
214
254
  setIsLoading(false);
215
- showAlert((texts === null || texts === void 0 ? void 0 : texts.invalidPhoneNumberError) || 'Please enter a valid phone number');
216
- return handleSetPhoneError((texts === null || texts === void 0 ? void 0 : texts.invalidPhoneNumberError) || 'Please enter a valid phone number');
255
+ showAlert((texts === null || texts === void 0 ? void 0 : texts.invalidPhoneNumberError) ||
256
+ 'Please enter a valid phone number');
257
+ return handleSetPhoneError((texts === null || texts === void 0 ? void 0 : texts.invalidPhoneNumberError) ||
258
+ 'Please enter a valid phone number');
217
259
  }
218
260
  await performCheckout(getCheckoutBodyWhenSkipping({
219
261
  userProfile: usrProfile,
@@ -282,17 +324,29 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
282
324
  if (secondsLeft === 0) {
283
325
  return false;
284
326
  }
285
- if (!firstName ||
286
- !lastName ||
287
- !email ||
288
- !emailConfirmation ||
289
- !city ||
290
- !postalCode ||
291
- (selectedState === null || selectedState === void 0 ? void 0 : selectedState.value) === '-1' ||
292
- (selectedCountry === null || selectedCountry === void 0 ? void 0 : selectedCountry.value) === '-1') {
293
- return false;
327
+ if (isTicketFree) {
328
+ if (!firstName || !lastName || !email || !emailConfirmation) {
329
+ return false;
330
+ }
331
+ }
332
+ else {
333
+ if (!firstName ||
334
+ !lastName ||
335
+ !email ||
336
+ !emailConfirmation ||
337
+ !city ||
338
+ !postalCode ||
339
+ (selectedState === null || selectedState === void 0 ? void 0 : selectedState.value) === '-1' ||
340
+ (selectedCountry === null || selectedCountry === void 0 ? void 0 : selectedCountry.value) === '-1') {
341
+ return false;
342
+ }
343
+ if (Config.IS_BILLING_STREET_NAME_REQUIRED && !street) {
344
+ setIsLoading(false);
345
+ return false;
346
+ }
294
347
  }
295
348
  if (isPhoneRequired &&
349
+ !isPhoneHidden &&
296
350
  validatePhoneNumber({
297
351
  phoneNumber: phone,
298
352
  customError: (_b = (_a = texts === null || texts === void 0 ? void 0 : texts.form) === null || _a === void 0 ? void 0 : _a.phoneInput) === null || _b === void 0 ? void 0 : _b.customError,
@@ -300,10 +354,6 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
300
354
  setIsLoading(false);
301
355
  return false;
302
356
  }
303
- if (Config.IS_BILLING_STREET_NAME_REQUIRED && !street) {
304
- setIsLoading(false);
305
- return false;
306
- }
307
357
  return true;
308
358
  };
309
359
  const fillAllRequiredFieldsAlert = ((_b = texts === null || texts === void 0 ? void 0 : texts.form) === null || _b === void 0 ? void 0 : _b.fillAllRequiredFieldsAlert) ||
@@ -369,52 +419,64 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
369
419
  setIsSubmittingData(true);
370
420
  const registerUserBody = getRegisterNewUserBody();
371
421
  const registerForm = getRegisterFormData(registerUserBody);
372
- const { data: registerResponseData, error: registerResponseError } = await billingCoreRef.current.registerNewUser(registerForm);
373
- if (registerResponseError) {
422
+ const { registerNewUserResponseData, registerNewUserResponseError } = await billingCoreRef.current.registerNewUser(registerForm);
423
+ if (registerNewUserResponseError) {
374
424
  setIsSubmittingData(false);
375
- if (registerResponseError.isAlreadyRegistered) {
376
- setLoginMessage(registerResponseError.message);
425
+ if (registerNewUserResponseError.isAlreadyRegistered) {
426
+ setLoginMessage(registerNewUserResponseError.message);
377
427
  showLoginDialog();
378
- return handleOnRegisterFail(registerResponseError.raw);
428
+ return handleOnRegisterFail(registerNewUserResponseError.raw);
379
429
  }
380
- handleOnRegisterFail(registerResponseError.raw);
381
- return showAlert(registerResponseError.message);
430
+ handleOnRegisterFail(registerNewUserResponseError.raw);
431
+ return showAlert(registerNewUserResponseError.message);
382
432
  }
383
- if (!registerResponseData) {
433
+ if (!registerNewUserResponseData) {
384
434
  setIsSubmittingData(false);
385
435
  handleOnRegisterFail('Register returned no data');
386
436
  return showAlert('Register returned no data');
387
437
  }
388
- const accessToken = await getData(LocalStorageKeys.ACCESS_TOKEN);
389
- const refreshToken = await getData(LocalStorageKeys.REFRESH_TOKEN);
390
- const tokens = {
391
- accessToken: accessToken,
392
- refreshToken: refreshToken,
393
- };
394
- storedToken.current = tokens.accessToken;
395
- onRegisterSuccess === null || onRegisterSuccess === void 0 ? void 0 : onRegisterSuccess();
438
+ storedToken.current =
439
+ registerNewUserResponseData.accessTokenData.accessToken;
440
+ onRegisterSuccess === null || onRegisterSuccess === void 0 ? void 0 : onRegisterSuccess(registerNewUserResponseData);
396
441
  await performCheckout();
397
442
  };
398
443
  const getRegisterNewUserBody = () => {
399
- const phoneNumber = phone.length < 5 ? '' : phone;
400
- const body = {
401
- attributes: {
402
- city: city,
403
- country: parseInt(selectedCountry.value, 10),
404
- email: email,
405
- first_name: firstName,
406
- last_name: lastName,
407
- password: password,
408
- phone: phoneNumber,
409
- state: parseInt(selectedState.value, 10),
410
- street_address: street,
411
- zip: postalCode,
412
- password_confirmation: passwordConfirmation,
413
- client_id: Config.CLIENT_ID,
414
- client_secret: Config.CLIENT_SECRET,
415
- check_cart_expiration: true,
416
- },
417
- };
444
+ const phoneNumber = isPhoneRequired ? phone : emptyPhone(phone);
445
+ const body = isTicketFree
446
+ ? {
447
+ attributes: {
448
+ email: email,
449
+ first_name: firstName,
450
+ last_name: lastName,
451
+ password: password,
452
+ phone: phoneNumber,
453
+ password_confirmation: passwordConfirmation,
454
+ client_id: Config.CLIENT_ID,
455
+ client_secret: Config.CLIENT_SECRET,
456
+ check_cart_expiration: true,
457
+ },
458
+ }
459
+ : {
460
+ attributes: {
461
+ city: city,
462
+ country: parseInt(selectedCountry.value, 10),
463
+ email: email,
464
+ first_name: firstName,
465
+ last_name: lastName,
466
+ password: password,
467
+ phone: phoneNumber,
468
+ state: parseInt(selectedState.value, 10),
469
+ street_address: street,
470
+ zip: postalCode,
471
+ password_confirmation: passwordConfirmation,
472
+ client_id: Config.CLIENT_ID,
473
+ client_secret: Config.CLIENT_SECRET,
474
+ check_cart_expiration: true,
475
+ },
476
+ };
477
+ if (body.attributes.phone === undefined) {
478
+ delete body.attributes.phone;
479
+ }
418
480
  return body;
419
481
  };
420
482
  const getCheckoutBody = () => {
@@ -428,29 +490,47 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
428
490
  };
429
491
  parsedTicketHolders.push(individualHolder);
430
492
  }
431
- const checkoutBody = {
432
- attributes: {
433
- city: city,
434
- confirm_email: emailConfirmation,
435
- country: parseInt(selectedCountry.value, 10),
436
- email: email,
437
- first_name: firstName,
438
- last_name: lastName,
439
- password: password,
440
- phone: phone,
441
- state: parseInt(selectedState.value, 10),
442
- street_address: street,
443
- zip: postalCode,
444
- ticket_holders: parsedTicketHolders,
445
- ttf_opt_in: isSubToTicketFairy,
446
- brand_opt_in: isSubToBrand,
447
- },
448
- };
493
+ const formattedPhone = isPhoneRequired ? phone : emptyPhone(phone);
494
+ const checkoutBody = isTicketFree
495
+ ? {
496
+ attributes: {
497
+ confirm_email: emailConfirmation,
498
+ email: email,
499
+ first_name: firstName,
500
+ last_name: lastName,
501
+ password: password,
502
+ phone: formattedPhone,
503
+ ticket_holders: parsedTicketHolders,
504
+ ttf_opt_in: isSubToTicketFairy,
505
+ brand_opt_in: isSubToBrand,
506
+ },
507
+ }
508
+ : {
509
+ attributes: {
510
+ city: city,
511
+ confirm_email: emailConfirmation,
512
+ country: parseInt(selectedCountry.value, 10),
513
+ email: email,
514
+ first_name: firstName,
515
+ last_name: lastName,
516
+ password: password,
517
+ phone: formattedPhone,
518
+ state: parseInt(selectedState.value, 10),
519
+ street_address: street,
520
+ zip: postalCode,
521
+ ticket_holders: parsedTicketHolders,
522
+ ttf_opt_in: isSubToTicketFairy,
523
+ brand_opt_in: isSubToBrand,
524
+ },
525
+ };
449
526
  if (isAgeRequired) {
450
527
  checkoutBody.attributes.dob_day = dateOfBirth.getDate();
451
528
  checkoutBody.attributes.dob_month = dateOfBirth.getMonth() + 1;
452
529
  checkoutBody.attributes.dob_year = dateOfBirth.getFullYear();
453
530
  }
531
+ if (checkoutBody.attributes.phone === undefined) {
532
+ delete checkoutBody.attributes.phone;
533
+ }
454
534
  return checkoutBody;
455
535
  };
456
536
  const getCheckoutBodyWhenSkipping = ({ userProfile, ticketsQuantity, }) => {
@@ -475,24 +555,41 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
475
555
  };
476
556
  parsedTicketHolders.push(individualHolder);
477
557
  }
478
- const checkoutBody = {
479
- attributes: {
480
- city: userProfile.city,
481
- confirm_email: userProfile.email,
482
- country: parseInt(userProfile.countryId, 10),
483
- email: userProfile.email,
484
- first_name: userProfile.firstName,
485
- last_name: userProfile.lastName,
486
- phone: userProfile.phone,
487
- state: parseInt(userProfile.stateId, 10),
488
- street_address: userProfile.streetAddress,
489
- zip: userProfile.zipCode,
490
- ticket_holders: parsedTicketHolders,
491
- ttf_opt_in: isSubToTicketFairy,
492
- brand_opt_in: isSubToBrand,
493
- password: password,
494
- },
495
- };
558
+ const checkoutBody = isTicketFree
559
+ ? {
560
+ attributes: {
561
+ confirm_email: userProfile.email,
562
+ email: userProfile.email,
563
+ first_name: userProfile.firstName,
564
+ last_name: userProfile.lastName,
565
+ phone: userProfile.phone,
566
+ ticket_holders: parsedTicketHolders,
567
+ ttf_opt_in: isSubToTicketFairy,
568
+ brand_opt_in: isSubToBrand,
569
+ password: password,
570
+ },
571
+ }
572
+ : {
573
+ attributes: {
574
+ city: userProfile.city,
575
+ confirm_email: userProfile.email,
576
+ country: parseInt(userProfile.countryId, 10),
577
+ email: userProfile.email,
578
+ first_name: userProfile.firstName,
579
+ last_name: userProfile.lastName,
580
+ phone: userProfile.phone,
581
+ state: parseInt(userProfile.stateId, 10),
582
+ street_address: userProfile.streetAddress,
583
+ zip: userProfile.zipCode,
584
+ ticket_holders: parsedTicketHolders,
585
+ ttf_opt_in: isSubToTicketFairy,
586
+ brand_opt_in: isSubToBrand,
587
+ password: password,
588
+ },
589
+ };
590
+ if (checkoutBody.attributes.phone === undefined) {
591
+ delete checkoutBody.attributes.phone;
592
+ }
496
593
  return checkoutBody;
497
594
  };
498
595
  const onSubmit = async () => {
@@ -508,6 +605,7 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
508
605
  }
509
606
  };
510
607
  //#endregion
608
+ //#region Fetch Initial Data
511
609
  const fetchData = async () => {
512
610
  var _a, _b;
513
611
  if (!billingCoreRef.current) {
@@ -527,7 +625,7 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
527
625
  phoneCountry = 'US';
528
626
  }
529
627
  const usrTkn = await getData(LocalStorageKeys.ACCESS_TOKEN);
530
- let skippingStatus;
628
+ let skippingStatusInner;
531
629
  const { countriesData, countriesError } = await billingCoreRef.current.getCountries();
532
630
  if (countriesError) {
533
631
  setSkippingStatus('fail');
@@ -555,7 +653,7 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
555
653
  usrPrfl = userProfileData;
556
654
  }
557
655
  else {
558
- skippingStatus = 'fail';
656
+ skippingStatusInner = 'fail';
559
657
  parsedCountries.unshift({
560
658
  value: '-1',
561
659
  label: ((_a = texts === null || texts === void 0 ? void 0 : texts.form) === null || _a === void 0 ? void 0 : _a.country) || 'Country',
@@ -573,7 +671,7 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
573
671
  return showAlert((cartError === null || cartError === void 0 ? void 0 : cartError.message) || 'Error fetching cart');
574
672
  }
575
673
  onFetchCartSuccess === null || onFetchCartSuccess === void 0 ? void 0 : onFetchCartSuccess();
576
- if (skippingStatus === 'fail') {
674
+ if (skippingStatusInner === 'fail') {
577
675
  setSkippingStatus('fail');
578
676
  }
579
677
  else {
@@ -596,11 +694,29 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
596
694
  });
597
695
  }
598
696
  if (usrPrfl) {
599
- if (!checkIsStoredPhoneNumberFormat(usrPrfl.phone)) {
600
- showAlert((texts === null || texts === void 0 ? void 0 : texts.invalidPhoneNumberError) || 'Please enter a valid phone number');
601
- skippingStatus = 'fail';
602
- setSkippingStatus('fail');
603
- setIsLoading(false);
697
+ if (!isPhoneHidden && isPhoneRequired) {
698
+ if (!checkIsStoredPhoneNumberFormat(usrPrfl.phone)) {
699
+ showAlert((texts === null || texts === void 0 ? void 0 : texts.invalidPhoneNumberError) ||
700
+ 'Please enter a valid phone number');
701
+ skippingStatusInner = 'fail';
702
+ setSkippingStatus('fail');
703
+ setIsLoading(false);
704
+ }
705
+ else {
706
+ // We can perfom Checkout process since phone is valid
707
+ if (!isBillingRequired && usrTkn && cartData) {
708
+ const checkoutBody = getCheckoutBodyWhenSkipping({
709
+ userProfile: usrPrfl,
710
+ ticketsQuantity: cartData.quantity,
711
+ });
712
+ return await performCheckout(checkoutBody);
713
+ }
714
+ else {
715
+ if (skippingStatusInner === 'skipping') {
716
+ setSkippingStatus('fail');
717
+ }
718
+ }
719
+ }
604
720
  }
605
721
  else {
606
722
  // We can perfom Checkout process since phone is valid
@@ -612,14 +728,15 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
612
728
  return await performCheckout(checkoutBody);
613
729
  }
614
730
  else {
615
- if (skippingStatus === 'skipping') {
731
+ if (skippingStatusInner === 'skipping') {
616
732
  setSkippingStatus('fail');
617
733
  }
618
734
  }
619
735
  }
736
+ const userPhone = usrPrfl.phone === null ? '' : usrPrfl.phone;
620
737
  handleSetFormDataFromUserProfile({
621
738
  ...usrPrfl,
622
- phone: `${phoneCountryDialCode}${usrPrfl.phone}`,
739
+ phone: `${phoneCountryDialCode}${userPhone}`,
623
740
  });
624
741
  }
625
742
  else {
@@ -630,6 +747,7 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
630
747
  setTicketHoldersData(tHolders);
631
748
  setIsLoading(false);
632
749
  };
750
+ //#endregion Fetch Initial Data
633
751
  //#region Effects
634
752
  useEffect(() => {
635
753
  handleOnLoadingChange(isLoading);
@@ -718,7 +836,7 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
718
836
  // eslint-disable-next-line react-hooks/exhaustive-deps
719
837
  }, []);
720
838
  //#endregion
721
- //#region Render
839
+ //#region RENDER
722
840
  const renderTicketHolders = () => {
723
841
  var _a;
724
842
  if (!numberOfTicketHolders) {
@@ -783,19 +901,20 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
783
901
  'Choose a password for your new TICKETFAIRY account'),
784
902
  React.createElement(Input, { label: ((_j = texts === null || texts === void 0 ? void 0 : texts.form) === null || _j === void 0 ? void 0 : _j.password) || 'Password', isSecure: true, onChangeText: setPassword, error: passwordError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles, autoCapitalize: 'none', secureTextEntry: true, textContentType: 'oneTimeCode' }),
785
903
  React.createElement(Input, { label: ((_k = texts === null || texts === void 0 ? void 0 : texts.form) === null || _k === void 0 ? void 0 : _k.confirmPassword) || 'Confirm password', isSecure: true, onChangeText: setPasswordConfirmation, error: confirmPasswordError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles, autoCapitalize: 'none', secureTextEntry: true, textContentType: 'oneTimeCode' }))),
786
- React.createElement(PhoneInput, { phoneNumber: phone, onChangePhoneNumber: handleOnChangePhoneNumber, styles: styles === null || styles === void 0 ? void 0 : styles.phoneInput, error: phoneError, texts: {
904
+ !isPhoneHidden && (React.createElement(PhoneInput, { phoneNumber: phone, onChangePhoneNumber: handleOnChangePhoneNumber, styles: styles === null || styles === void 0 ? void 0 : styles.phoneInput, error: phoneError, texts: {
787
905
  label: phoneLabel,
788
906
  ...(_l = texts === null || texts === void 0 ? void 0 : texts.form) === null || _l === void 0 ? void 0 : _l.phoneInput,
789
- } }),
790
- React.createElement(Input, { label: addressLabel, value: street, onChangeText: setStreet, error: streetError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles }),
791
- React.createElement(Input, { label: ((_m = texts === null || texts === void 0 ? void 0 : texts.form) === null || _m === void 0 ? void 0 : _m.city) || 'City', value: city, onChangeText: setCity, error: cityError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles }),
792
- React.createElement(DropdownMaterial, { items: countries, onSelectItem: setSelectedCountry, selectedOption: selectedCountry, styles: styles === null || styles === void 0 ? void 0 : styles.dropdownMaterialStyles, materialInputProps: {
793
- label: ((_o = texts === null || texts === void 0 ? void 0 : texts.form) === null || _o === void 0 ? void 0 : _o.country) || 'Country',
794
- } }),
795
- React.createElement(Input, { label: ((_p = texts === null || texts === void 0 ? void 0 : texts.form) === null || _p === void 0 ? void 0 : _p.zipCode) || 'Postal Code / Zip Code', value: postalCode, onChangeText: setPostalCode, error: postalCodeError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles }),
796
- React.createElement(DropdownMaterial, { items: states, onSelectItem: setSelectedState, selectedOption: selectedState, styles: styles === null || styles === void 0 ? void 0 : styles.dropdownMaterialStyles, materialInputProps: {
797
- label: ((_q = texts === null || texts === void 0 ? void 0 : texts.form) === null || _q === void 0 ? void 0 : _q.state) || 'State',
798
- } }),
907
+ } })),
908
+ !isTicketFree && (React.createElement(React.Fragment, null,
909
+ React.createElement(Input, { label: addressLabel, value: street, onChangeText: setStreet, error: streetError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles }),
910
+ React.createElement(Input, { label: ((_m = texts === null || texts === void 0 ? void 0 : texts.form) === null || _m === void 0 ? void 0 : _m.city) || 'City', value: city, onChangeText: setCity, error: cityError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles }),
911
+ React.createElement(DropdownMaterial, { items: countries, onSelectItem: setSelectedCountry, selectedOption: selectedCountry, styles: styles === null || styles === void 0 ? void 0 : styles.dropdownMaterialStyles, materialInputProps: {
912
+ label: ((_o = texts === null || texts === void 0 ? void 0 : texts.form) === null || _o === void 0 ? void 0 : _o.country) || 'Country',
913
+ } }),
914
+ React.createElement(Input, { label: ((_p = texts === null || texts === void 0 ? void 0 : texts.form) === null || _p === void 0 ? void 0 : _p.zipCode) || 'Postal Code / Zip Code', value: postalCode, onChangeText: setPostalCode, error: postalCodeError, styles: styles === null || styles === void 0 ? void 0 : styles.inputStyles }),
915
+ React.createElement(DropdownMaterial, { items: states, onSelectItem: setSelectedState, selectedOption: selectedState, styles: styles === null || styles === void 0 ? void 0 : styles.dropdownMaterialStyles, materialInputProps: {
916
+ label: ((_q = texts === null || texts === void 0 ? void 0 : texts.form) === null || _q === void 0 ? void 0 : _q.state) || 'State',
917
+ } }))),
799
918
  React.createElement(Checkbox, { onPress: handleIsSubToBrandToggle, text: brandCheckBoxText, isActive: isSubToBrand, styles: styles === null || styles === void 0 ? void 0 : styles.checkboxStyles }),
800
919
  !isTtfCheckboxHidden && (React.createElement(Checkbox, { onPress: handleIsSubToTicketFairyToggle, isActive: isSubToTicketFairy, customTextComp: React.createElement(Text, { style: (_r = styles === null || styles === void 0 ? void 0 : styles.customCheckbox) === null || _r === void 0 ? void 0 : _r.text },
801
920
  ((_s = texts === null || texts === void 0 ? void 0 : texts.form) === null || _s === void 0 ? void 0 : _s.isSubToTicketFairy) ||
@@ -822,10 +941,11 @@ const Billing = ({ styles, texts, cartProps: { isAgeRequired, isNameRequired, is
822
941
  React.createElement(CartTimer, { secondsLeft: secondsLeft, styles: styles === null || styles === void 0 ? void 0 : styles.cartTimer, texts: texts === null || texts === void 0 ? void 0 : texts.cartTimer, shouldNotMinimize: shouldCartTimerNotMinimizeOnTap })));
823
942
  };
824
943
  const isDataValid = checkBasicDataValid();
825
- return (React.createElement(BillingCore, { ref: billingCoreRef, onSecondsLeftChange: setSecondsLeft, onCartExpired: onCartExpired }, skippingStatus === 'skipping' && areLoadingIndicatorsEnabled
826
- ? renderCheckingOut()
827
- : renderContent()));
944
+ return (React.createElement(BillingCore, { ref: billingCoreRef, onSecondsLeftChange: setSecondsLeft, onCartExpired: onCartExpired },
945
+ React.createElement(SessionHandle, { ref: sessionHandleRef }, skippingStatus === 'skipping' && areLoadingIndicatorsEnabled
946
+ ? renderCheckingOut()
947
+ : renderContent())));
828
948
  //#endregion
829
- };
949
+ });
830
950
  export default Billing;
831
951
  //# sourceMappingURL=Billing.js.map