/// <summary> /// Integration event handler which starts the create order process /// </summary> /// <param name="event"> /// Integration event message which is sent by the /// basket.api once it has successfully process the /// order items. /// </param> /// <returns></returns> public async Task Handle(BasketCheckoutAcceptedIntegrationEvent @event) { var serviceModel = new CheckoutBasketServiceModel { ClientId = @event.ClientId, ClientName = @event.ClientName, SellerId = @event.SellerId, BasketId = @event.Basket?.Id, BillingAddressId = @event.BillingAddressId, BillingCity = @event.BillingCity, BillingCompany = @event.BillingCompany, BillingCountryCode = @event.BillingCountryCode, BillingFirstName = @event.BillingFirstName, BillingLastName = @event.BillingLastName, BillingPhone = @event.BillingPhone, BillingPhonePrefix = @event.BillingPhonePrefix, BillingPostCode = @event.BillingPostCode, BillingRegion = @event.BillingRegion, BillingStreet = @event.BillingStreet, ShippingAddressId = @event.ShippingAddressId, ShippingCity = @event.ShippingCity, ShippingCompany = @event.ShippingCompany, ShippingCountryCode = @event.ShippingCountryCode, ShippingFirstName = @event.ShippingFirstName, ShippingLastName = @event.ShippingLastName, ShippingPhone = @event.ShippingPhone, ShippingPhonePrefix = @event.ShippingPhonePrefix, ShippingPostCode = @event.ShippingPostCode, ShippingRegion = @event.ShippingRegion, ShippingStreet = @event.ShippingStreet, ExpectedDeliveryDate = @event.ExpectedDeliveryDate, ExternalReference = @event.ExternalReference, MoreInfo = @event.MoreInfo, IpAddress = @event.IpAddress, Items = @event.Basket?.Items?.Select(x => new CheckoutBasketItemServiceModel { ProductId = x.ProductId, ProductSku = x.ProductSku, ProductName = x.ProductName, PictureUrl = x.PictureUrl, Quantity = x.Quantity, ExternalReference = x.ExternalReference, ExpectedDeliveryFrom = x.DeliveryFrom, ExpectedDeliveryTo = x.DeliveryTo, MoreInfo = x.MoreInfo }) }; var validator = new CheckoutBasketServiceModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { await this.ordersService.CheckoutAsync(serviceModel); } }
public async Task <IActionResult> BasketCheckoutPost(BasketCheckoutRequestModel request) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var isSellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == JwtClaimTypes.Role && x.Value == AccountConstants.Roles.Seller); var serviceModel = new CheckoutBasketServiceModel { BasketId = request.BasketId, IsSeller = isSellerClaim != null, ClientId = request.ClientId, ClientName = request.ClientName, BillingAddressId = request.BillingAddressId, BillingCity = request.BillingCity, BillingCompany = request.BillingCompany, BillingCountryCode = request.BillingCountryCode, BillingFirstName = request.BillingFirstName, BillingLastName = request.BillingLastName, BillingPhone = request.BillingPhone, BillingPhonePrefix = request.BillingPhonePrefix, BillingPostCode = request.BillingPostCode, BillingRegion = request.BillingRegion, BillingStreet = request.BillingStreet, ShippingAddressId = request.ShippingAddressId, ShippingCity = request.ShippingCity, ShippingCompany = request.ShippingCompany, ShippingCountryCode = request.ShippingCountryCode, ShippingFirstName = request.ShippingFirstName, ShippingLastName = request.ShippingLastName, ShippingPhone = request.ShippingPhone, ShippingPhonePrefix = request.ShippingPhonePrefix, ShippingPostCode = request.ShippingPostCode, ShippingRegion = request.ShippingRegion, ShippingStreet = request.ShippingStreet, ExpectedDeliveryDate = request.ExpectedDeliveryDate, MoreInfo = request.MoreInfo, Language = CultureInfo.CurrentCulture.Name, Username = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new CheckoutBasketServiceModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { await this.basketService.CheckoutAsync(serviceModel); return(this.StatusCode((int)HttpStatusCode.Accepted)); } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }