예제 #1
0
        public async Task ProcessCustomerRegistrationAsync(CustomerRegistrationEvent message)
        {
            var emailAndDemoMode = await IsDemoMode(message.CustomerId);

            if (!emailAndDemoMode.Item2)
            {
                _log.Info("Customer email not in demo mode", new { message.CustomerId });
                return;
            }

            _log.Info("Starting to process customer registration event", new
            {
                message.CustomerId,
                message.ReferralCode,
                message.TimeStamp,
                emailAndDemoMode.Item1
            });

            var phoneNumber = string.Join("", Guid.NewGuid().ToString().ToCharArray().Where(char.IsDigit).Take(15));

            _log.Info("Setting customer's phone", new
            {
                message.CustomerId,
                phoneNumber
            });

            var setPhoneRequest = new SetCustomerPhoneInfoRequestModel
            {
                CustomerId         = message.CustomerId,
                CountryPhoneCodeId = 1,
                PhoneNumber        = phoneNumber
            };
            var phoneResult = await _customerProfileClient.CustomerPhones.SetCustomerPhoneInfoAsync(setPhoneRequest);

            if (phoneResult.ErrorCode != CustomerProfileErrorCodes.None)
            {
                _log.Error(message: $"Couldn't set customer phone - {phoneResult.ErrorCode}", context: setPhoneRequest);
                return;
            }

            _log.Info("Auto verifying customer phone", new
            {
                message.CustomerId,
            });
            var verifiedPhoneResult = await _customerProfileClient.CustomerPhones.SetCustomerPhoneAsVerifiedAsync(new SetPhoneAsVerifiedRequestModel
            {
                CustomerId = message.CustomerId
            });

            if (verifiedPhoneResult.ErrorCode != CustomerProfileErrorCodes.None)
            {
                _log.Error(message: $"Couldn't verify phone number - {verifiedPhoneResult.ErrorCode}", context: message.CustomerId);
                return;
            }

            _log.Info("Auto verifying customer email", new
            {
                message.CustomerId,
            });
            await _emailCodeVerifiedPublisher.PublishAsync(new EmailCodeVerifiedEvent
            {
                CustomerId = message.CustomerId, TimeStamp = DateTime.UtcNow
            });

            //This is actually expected to run later,
            //so we don't want to block the current thread and let the next message be processed
#pragma warning disable 4014
            Task.Run(async() => {
#pragma warning restore 4014
                await Task.Delay(_paymentRequestSettings.PaymentRequestDelayInMilliseconds);

                await CreatePartnerPaymentRequestAsync(message.CustomerId);
            });
        }
        public async Task <SetCustomerPhoneInfoResponseModel> SetCustomerPhoneInfoAsync([FromBody] SetCustomerPhoneInfoRequestModel request)
        {
            var result = await _customerProfileService.UpdatePhoneInfoAsync(request.CustomerId, request.PhoneNumber, request.CountryPhoneCodeId);

            return(new SetCustomerPhoneInfoResponseModel {
                ErrorCode = (CustomerProfileErrorCodes)result
            });
        }