Exemplo n.º 1
0
        public async Task <string> GetCustomerToken(CdkCustomer cdkCustomer, string roofTopId)
        {
            if (cdkCustomer == null)
            {
                throw new ArgumentNullException(nameof(cdkCustomer));
            }
            if (roofTopId == null)
            {
                throw new ArgumentNullException(nameof(roofTopId));
            }
            var dealerCDKConfig = _dealerCDKConfigurationDAL.GetDealerCDKConfigurations(roofTopId, cdkCustomer.CommunityId);

            if (dealerCDKConfig == null)
            {
                throw new DealerCDKConfigurationException(ExceptionMessages.InvalidDealerCDKConfiguration);
            }

            var customerToken = await RequestAndActivateCustomerToken(cdkCustomer, dealerCDKConfig, roofTopId, cdkCustomer.Token) ??
                                await RequestAndActivateCustomerToken(cdkCustomer, dealerCDKConfig, roofTopId, null);

            cdkCustomer.Token = new Guid(customerToken);

            await _cdkCustomerService.SaveCdkCustomer(cdkCustomer);

            return(customerToken);
        }
Exemplo n.º 2
0
        public async Task <int> AddCustomer(CdkCustomer cdkCustomer)
        {
            if (cdkCustomer == null)
            {
                throw new ArgumentNullException(nameof(cdkCustomer));
            }
            if (cdkCustomer.CommunityId == null)
            {
                throw new ArgumentNullException(nameof(cdkCustomer.CommunityId));
            }
            if (cdkCustomer.CustomerNo < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(cdkCustomer.CustomerNo));
            }

            _context.CdkCustomers.Add(cdkCustomer);
            return(await _context.SaveChangesAsync());
        }
Exemplo n.º 3
0
        public async Task SaveCdkCustomer(CdkCustomer cdkCustomer)
        {
            if (cdkCustomer == null)
            {
                throw new ArgumentNullException(nameof(cdkCustomer));
            }

            var existingCdkCustomer = _cdkCustomerDal.GetCdkCustomer(cdkCustomer.CommunityId, cdkCustomer.CustomerNo);

            if (existingCdkCustomer != null)
            {
                await _cdkCustomerDal.UpdateCustomerToken(existingCdkCustomer.Id, cdkCustomer.Token);
            }
            else
            {
                cdkCustomer.Password = _encryptionService.EncryptString(cdkCustomer.Password);
                await _cdkCustomerDal.AddCustomer(cdkCustomer);
            }
        }
Exemplo n.º 4
0
        internal async Task <string> RequestAndActivateCustomerToken(CdkCustomer cdkCustomer, DealerCDKConfiguration dealerCDKConfig, string roofTopId, Guid?existingToken)
        {
            if (existingToken == null)
            {
                var requestApiResponse = await RequestToken(dealerCDKConfig, cdkCustomer.CommunityId, cdkCustomer.CustomerLoginId);

                if (requestApiResponse.Result == null || !requestApiResponse.Success ||
                    !(requestApiResponse.Result is TokenResponse objRequestToken) ||
                    string.IsNullOrWhiteSpace(objRequestToken.Token))
                {
                    var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(requestApiResponse.Errors));
                    _telemetryClient?.TrackException(cdkAutolineException);
                    throw cdkAutolineException;
                }

                cdkCustomer.Token = new Guid(objRequestToken.Token);
            }

            //Activate Token from generated token.
            var checkPasswordApiResponse = await _customerService.CheckPassword(new CustomerVerifyRequest
            {
                CommunityId = cdkCustomer.CommunityId,
                CustomerNo  = cdkCustomer.CustomerNo,
                RoofTopId   = roofTopId
            }, cdkCustomer, dealerCDKConfig.PartnerKey);

            if (checkPasswordApiResponse == null || !checkPasswordApiResponse.Success)
            {
                if (existingToken != null)
                {
                    return(null);
                }
                throw new CDKAutolineException(UtilityHelper.SerializeObject(checkPasswordApiResponse?.Errors));
            }

            await _cdkCustomerService.SaveCdkCustomer(cdkCustomer);

            return(cdkCustomer.Token.ToString());
        }
Exemplo n.º 5
0
        public string GetEncryptedTokenCode(string token, CdkCustomer cdkCustomer, string partnerKey, bool addPassword = false)
        {
            //Partner key.
            byte[] partnerKeyInBytes = Encoding.UTF8.GetBytes(partnerKey);

            //Convert token into bytes.
            byte[] tokenInBytes = Encoding.UTF8.GetBytes(token);

            // Calculate Hash value using via defined HMAC- algorithm using previously get token from
            // services (/RequestToken) API.
            HMACSHA384 objHmacsha384 = new HMACSHA384(partnerKeyInBytes);

            var hashMessage = objHmacsha384.ComputeHash(tokenInBytes);

            //var hashCodeObj = Convert.ToBase64String(hashMessage);
            var hashCodeObj = UtilityHelper.ByteToString(hashMessage);

            var base64Format = addPassword
                ? cdkCustomer.CustomerLoginId + ":" + hashCodeObj + ":" + _encryptionService.DecryptString(cdkCustomer.Password)
                : _unregisteredGuid + ":" + hashCodeObj + ":";

            //Convert Hash value into Base64 string in format<{candidateId}:{hash}:>
            return(Convert.ToBase64String(Encoding.UTF8.GetBytes(base64Format)));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Registered customer in CDK Autoline services.
        /// </summary>
        /// <param name="customerVehicleRegisterRequest"></param>
        /// <param name="cdkCustomer"></param>
        /// <returns></returns>
        public async Task <ApiResponse> RegisterCustomer(CustomerVehicleRegisterRequest customerVehicleRegisterRequest, CdkCustomer cdkCustomer)
        {
            if (customerVehicleRegisterRequest == null)
            {
                throw new ArgumentNullException(nameof(customerVehicleRegisterRequest));
            }
            if (cdkCustomer == null)
            {
                throw new ArgumentNullException(nameof(cdkCustomer));
            }

            var requestBody = UtilityHelper.SerializeObject(new
            {
                customerVehicleRegisterRequest.CommunityId,
                customerVehicleRegisterRequest.RoofTopId,
                CustomerId     = cdkCustomer.CustomerLoginId,
                CustomerIdType = CustomerIdType.Other,
                cdkCustomer.Password,
                customerVehicleRegisterRequest.FirstName,
                SurName = customerVehicleRegisterRequest.Surname,
                customerVehicleRegisterRequest.EmailAddress,
                MobileTelNo = customerVehicleRegisterRequest.PhoneNumber
            });

            var request = new ApiRequest
            {
                Body   = requestBody,
                Method = HttpVerbs.POST.ToString(),
                Url    = CombineUrl(GetCdkAutolineUrl(_cdkAutolineUrl,
                                                      customerVehicleRegisterRequest.CommunityId), RegisterCustomerUrl),
                ContentType = Constants.ContentTypeJson
            };

            AddRequestHeader(request,
                             $"{Constants.DataHubAppTokenHeaderValuePrefix}{customerVehicleRegisterRequest.AppToken}");
            return(await _restApiClient.Invoke <CustomerResponse>(request));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Check password from SOL api.
        /// </summary>
        /// <param name="customerVerifyRequest"></param>
        /// <param name="cdkCustomer"></param>
        /// <returns></returns>
        public async Task <ApiResponse> CheckPassword(CustomerVerifyRequest customerVerifyRequest, CdkCustomer cdkCustomer, string partnerKey)
        {
            if (customerVerifyRequest == null)
            {
                throw new ArgumentNullException(nameof(customerVerifyRequest));
            }
            if (cdkCustomer == null)
            {
                throw new ArgumentNullException(nameof(cdkCustomer));
            }
            var requestBody = UtilityHelper.SerializeObject(new
            {
                RooftopId = customerVerifyRequest.RoofTopId
            });
            var request = new ApiRequest
            {
                Body        = requestBody,
                Method      = HttpVerbs.POST.ToString(),
                Url         = CombineUrl(GetCdkAutolineUrl(_cdkAutolineUrl, customerVerifyRequest.CommunityId), CheckPasswordUrl),
                ContentType = Constants.ContentTypeJson
            };

            var hashCode =
                _encryptedTokenCodeService.GetEncryptedTokenCode(cdkCustomer.Token.ToString(), cdkCustomer, partnerKey, true);

            AddRequestHeader(request, $"{Constants.DataHubHashHeaderValuePrefix}{hashCode}");
            return(await _restApiClient.Invoke <CustomerResponse>(request));
        }
        internal CdkCreateServiceBookingRequest MapToCdkCreateServiceBookingRequest(CreateServiceBookingRequest createServiceBookingRequest, CdkCustomer cdkCustomer)
        {
            var cdkCreateServiceBookingRequest =
                new CdkCreateServiceBookingRequest
            {
                RooftopId             = createServiceBookingRequest.RooftopId,
                CustomerId            = cdkCustomer.CustomerLoginId,
                EmailAddress          = createServiceBookingRequest.EmailAddress,
                MobileTelNo           = createServiceBookingRequest.MobileTelNo,
                FirstName             = createServiceBookingRequest.FirstName,
                SurName               = createServiceBookingRequest.SurName,
                VehicleRegistrationNo = createServiceBookingRequest.VehicleRegistrationNo,
                VehMakeCode           = createServiceBookingRequest.VehMakeCode,
                VehModelCode          = createServiceBookingRequest.VehModelCode,
                VehVariantCode        = createServiceBookingRequest.VehVariantCode,
                Jobs                   = createServiceBookingRequest.Jobs,
                JobDate                = createServiceBookingRequest.JobDate,
                TransportMethod        = createServiceBookingRequest.TransportMethod,
                AdvisorID              = createServiceBookingRequest.AdvisorId,
                AdvisorDropOffTimeCode = createServiceBookingRequest.AdvisorDropOffTimeCode,
                SendConfirmationMail   = true
            };

            return(cdkCreateServiceBookingRequest);
        }