public ActionResult RemoveQuoteBasket() { _b2bRepository.RemoveQuoteBasket(); return(JsonSuccess(true, JsonRequestBehavior.AllowGet)); }
public ActionResult ConvertToOrder(CheckoutModel checkout) { if (!string.IsNullOrEmpty(checkout.CompanyId) && _sessionContext.CurrentUser == null && checkout.CompanyId != Guid.Empty.ToString()) { //execute when company user tries to place order via guest checkout. return(JsonSuccess("", JsonRequestBehavior.DenyGet)); } if (checkout.CustomerId == Guid.Empty.ToString() || checkout.CustomerId == null) { var user = new CustomerModel { Email = Sanitizer.GetSafeHtmlFragment(checkout.Email), Password = Sanitizer.GetSafeHtmlFragment(checkout.Password) }; var responseTemp = _customerRepository.GetExistingUser(user.Email); if (responseTemp.Result.Count > 0) { checkout.CustomerId = responseTemp.Result[0].UserId.ToString(); } else { var result = _customerRepository.Register(user); if (result.Result.IsValid) { checkout.CustomerId = result.Result.RecordId; } } } checkout.Payment = new PaymentModel { PaymentGatewayId = checkout.SelectedPayment.Id, PaymentGateway = checkout.SelectedPayment.SystemName, OrderAmount = checkout.SelectedPayment.CardInfo.Amount, Status = PaymentStatus.Pending.GetHashCode() }; var response = _checkoutApi.ConvertToOrder(Sanitizer.GetSafeHtmlFragment(checkout.BasketId), checkout); if (response.Result == null) { return(JsonSuccess(response, JsonRequestBehavior.AllowGet)); } _b2bRepository.RemoveQuoteBasket(); var order = response.Result; var paymentRequest = new ProcessPaymentRequest { BasketId = checkout.BasketId, CurrencyCode = order.CurrencyCode, CustomerId = checkout.CustomerId, LanuguageCode = _sessionContext.CurrentSiteConfig.RegionalSettings.DefaultLanguageCulture, OrderId = order.Id, OrderNo = order.OrderNo, PaymentId = order.Payment.Id, UserEmail = checkout.Email, OrderTotal = order.Payment.OrderAmount, Order = order }; if (!string.IsNullOrEmpty(checkout.SelectedPayment.CardInfo?.CardNo) && !string.IsNullOrEmpty(checkout.SelectedPayment.CardInfo.SecurityCode) && checkout.SelectedPayment.CardInfo.Amount > 0) { paymentRequest.CardNo = checkout.SelectedPayment.CardInfo.CardNo; paymentRequest.Cvv = checkout.SelectedPayment.CardInfo.SecurityCode; paymentRequest.OrderTotal = checkout.SelectedPayment.CardInfo.Amount; } if (checkout.SelectedPayment.SystemName != Convert.ToString(PaymentMethodTypes.AccountCredit)) { var payResponse = _checkoutApi.PaymentSetting(checkout.SelectedPayment.SystemName); checkout.SelectedPayment = payResponse.Result; } var paymentResponse = checkout.SelectedPayment.ProcessPayment(paymentRequest); if (paymentResponse.Success && paymentResponse.AuthorizedAmount > 0) { order.Payment.IsValid = true; order.Payment.Status = order.Payment.IsValid.GetHashCode(); order.Payment.AuthCode = paymentResponse.AuthorizationTransactionCode; order.Payment.CardNo = paymentRequest.CardNo; order.Payment.OrderAmount = paymentResponse.AuthorizedAmount; var result = _checkoutApi.UpdatePayment(order.Id, order.Payment); paymentResponse.BalanceAmount = result.Result?.BalanceAmount; } return(JsonSuccess(paymentResponse, JsonRequestBehavior.AllowGet)); }