public RedirectResult Form_POST() { if (!_cart.CanPlaceOrder) { _cart.CannotPlaceOrderReasons.ForEach(s => TempData.ErrorMessages().Add(s)); return(_uniquePageService.RedirectTo <PaymentDetails>()); } var response = _payPalExpressService.DoExpressCheckout(_cart); if (response.RedirectToPayPal) { return(Redirect(_payPalUrlService.GetExpressCheckoutRedirectUrl(_cart.PayPalExpressToken))); } if (response.Success) { var order = _orderPlacementService.PlaceOrder(_cart, response.UpdateOrder); return(_uniquePageService.RedirectTo <OrderPlaced>(new { id = order.Guid })); } TempData["error-details"] = new FailureDetails { Message = "An error occurred processing your PayPal Express order, please contact the merchant" }; return(_uniquePageService.RedirectTo <PaymentDetails>()); }
public string ProcessSubmitButton(IList <ShoppingCartItem> cart, TempDataDictionary tempData) { using (var payPalApiaaInterface = _payPalInterfaceService.GetAAService()) { var customSecurityHeaderType = _payPalSecurityService.GetRequesterCredentials(); var setExpressCheckoutResponse = payPalApiaaInterface.SetExpressCheckout( ref customSecurityHeaderType, _payPalRequestService.GetSetExpressCheckoutRequest(cart)); var result = new ProcessPaymentResult(); var redirectUrl = string.Empty; setExpressCheckoutResponse.HandleResponse(result, (paymentResult, type) => { var token = setExpressCheckoutResponse.Token; redirectUrl = _payPalUrlService.GetExpressCheckoutRedirectUrl(token); }, (paymentResult, type) => { _logger.InsertLog(LogLevel.Error, "Error passing cart to PayPal", string.Join(", ", setExpressCheckoutResponse.Errors.Select( errorType => errorType.ErrorCode + ": " + errorType.LongMessage))); tempData["paypal-ec-error"] = "An error occurred setting up your cart for PayPal."; redirectUrl = _webHelper.GetUrlReferrer(); }, Guid.Empty); return(redirectUrl); } }
public SetExpressCheckoutResponse GetSetExpressCheckoutRedirectUrl(CartModel cart) { SetExpressCheckoutResponseType setExpressCheckoutResponseType = _payPalInterfaceService.SetExpressCheckout(cart); return(setExpressCheckoutResponseType .HandleResponse <SetExpressCheckoutResponseType, SetExpressCheckoutResponse>( (type, response) => { response.Url = _payPalUrlService.GetExpressCheckoutRedirectUrl(type.Token); _cartManager.SetPayPalExpressToken(type.Token); }, (type, response) => { response.Errors.Add("An error occurred"); type.RaiseErrors(); })); }