public async Task <(bool isSuccessful, string errorMessage)> ConfirmAsync(string referralCode, Guid referredId) { Domain.Models.Referral referrer; try { referrer = await _referralService.GetReferralByReferralCodeAsync(referralCode); } catch (CustomerNotFoundException e) { _log.Warning(message: e.Message, exception: e); return(true, string.Empty); } var referred = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(referredId.ToString("D"), true); if (referred.ErrorCode == CustomerProfileErrorCodes.CustomerProfileDoesNotExist) { return(false, $"Connector with id '{referredId}' does not exist."); } var referredFiendProfile = await _customerProfileClient.ReferralFriendProfiles.GetByEmailAndReferrerAsync(new ReferralFriendByEmailAndReferrerProfileRequest { Email = referred.Profile.Email, ReferrerId = referrer.CustomerId }); var friendReferral = await _friendReferralHistoryRepository.GetByIdAsync(referredFiendProfile.Data.ReferralFriendId); if (friendReferral == null) { return(false, $"Referral not found for referred '{referredId}' and referrer '{referrer.CustomerId}'"); } // Generating a referral code for the new referral await _referralService.CreateReferralForCustomerIfNotExistAsync(referredId); friendReferral.State = ReferralFriendState.Accepted; friendReferral.ReferredId = referredId; await _friendReferralHistoryRepository.UpdateAsync(friendReferral); _log.Info("Referral friend confirmed", context: $"referralFriendId: {friendReferral.Id}"); return(true, string.Empty); }