コード例 #1
0
        public ActionResult Form(PaypointPaymentDetailsModel model)
        {
            _paypointPaymentService.SetModel(model);

            if (!_cartModel.CanPlaceOrder)
            {
                _cartModel.CannotPlaceOrderReasons.ForEach(s => TempData.ErrorMessages().Add(s));
                return(_uniquePageService.RedirectTo <PaymentDetails>());
            }

            var response = _paypointPaymentService.ProcessDetails(model, Url.Action("Response3DSecure", "Paypoint", null, Request.Url.Scheme));

            if (response.Requires3DSecure)
            {
                TempData["redirect-details"] = response.RedirectDetails;
                return(RedirectToAction("Redirect3DSecure", "Paypoint"));
            }

            if (response.PaymentSucceeded)
            {
                var order = _orderPlacementService.PlaceOrder(_cartModel, o =>
                {
                    o.PaymentStatus      = PaymentStatus.Paid;
                    o.PaidDate           = CurrentRequestData.Now;
                    o.AuthorisationToken = response.PaypointPaymentDetails.AuthCode;
                    o.ShippingStatus     = ShippingStatus.Unshipped;
                });
                return(_uniquePageService.RedirectTo <OrderPlaced>(new { id = order.Guid }));
            }

            TempData["error-details"]  = response.FailureDetails;
            TempData["paypoint-model"] = model;
            return(_uniquePageService.RedirectTo <PaymentDetails>());
        }
        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>());
        }
コード例 #3
0
        public ActionResult Index(CheckoutViewModel model)
        {
            var cart = cartProvider.GetCart();
            var contactDataCollection = contactDataProvider.GetContactData();

            if (cart.IsEmpty())
            {
                ModelState.AddModelError("cart", "Cart is empty");
            }
            else if (contactDataCollection == null)
            {
                ModelState.AddModelError("contactData", "Contact data is empty");
            }

            if (ModelState.IsValid)
            {
                // Recalculate cart one last time, to make sure e.g. setup fees are still there.
                cartPricingService.CalculatePricing(cart);

                var paymentData = new PaymentData
                {
                    Id          = model.SelectedPaymentMethod.Id,
                    PaymentForm = model.SelectedPaymentMethod.Form,
                    SaveCcInfo  = model.SelectedPaymentMethod.SupportsPaymentProfile && model.SaveCcInfo,
                    AutoPay     = model.SelectedPaymentMethod.SupportsPaymentProfile && model.AutoPay
                };

                var orderContext = new OrderContext(cart, contactDataCollection, paymentData, new object[] { Request });
                var result       = orderPlacementService.PlaceOrder(orderContext);

                return(Redirect(result.RedirectUrl));
            }

            return(View(model));
        }
コード例 #4
0
        public ActionResult Index(CheckoutViewModel model)
        {
            var cart = cartProvider.GetCart();
            var contactDataCollection = contactDataProvider.GetContactData();

            ViewBag.CheckVAT = !String.IsNullOrEmpty(vatDataProvider.VatNumber);

            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                if (!RecaptchaHelper.IsResponseValid(Request.Form["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("recaptcha", this.GlobalCommonResource("RecaptchaVerificationFaild"));
                }
            }

            if (cart.IsEmpty())
            {
                ModelState.AddModelError("cart", "Cart is empty");
            }
            else if (contactDataCollection == null)
            {
                ModelState.AddModelError("contactData", "Contact data is empty");
            }

            if (ModelState.IsValid)
            {
                // Recalculate cart one last time, to make sure e.g. setup fees are still there.
                cartPricingService.CalculatePricing(cart);

                var paymentData = new PaymentData
                {
                    Id          = model.SelectedPaymentMethod.Id,
                    PaymentForm = model.SelectedPaymentMethod.Form,
                    SaveCcInfo  = model.SelectedPaymentMethod.SupportsPaymentProfile && model.SaveCcInfo,
                    AutoPay     = model.SelectedPaymentMethod.SupportsPaymentProfile && model.AutoPay
                };

                var orderContext = new OrderContext(cart, contactDataCollection, paymentData, new object[] { Request });
                var result       = orderPlacementService.PlaceOrder(orderContext);

                if (result.RedirectUrl == urlProvider.SuccessUrl)
                {
                    contactDataProvider.ClearContactData();
                    cartProvider.ClearCart();
                }

                return(Redirect(result.RedirectUrl));
            }

            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                ViewBag.RecaptchaEnabled = true;
                ViewBag.RecaptchaSiteKey = RecaptchaHelper.GetSiteKey();
            }

            ViewData["formHasErrors"] = true;
            return(View(model));
        }
コード例 #5
0
        public ActionResult Notification(SagePayResponse response)
        {
            var vendorTxCode = response.VendorTxCode;

            if (string.IsNullOrEmpty(vendorTxCode))
            {
                return(new ErrorResult());
            }
            var cart = _sagePayCartLoader.GetCart(vendorTxCode);

            if (cart == null || cart.CartGuid.ToString() != vendorTxCode ||
                _sagePayService.GetCartTotal(cart.UserGuid) != cart.TotalToPay)
            {
                ResetSessionInfo(cart,
                                 new FailureDetails
                {
                    Message =
                        "There was an error communicating with SagePay. No funds have been transferred. Please try again, and if you continue to have errors please contact support"
                });
                return(new TransactionNotFoundResult(vendorTxCode));
            }

            if (!response.IsSignatureValid(_sagePayService.GetSecurityKey(cart.UserGuid), _sagePaySettings.VendorName))
            {
                ResetSessionInfo(cart,
                                 new FailureDetails
                {
                    Message =
                        "There was an error communicating with SagePay. No funds have been transferred. Please try again, and if you continue to have errors please contact support"
                });
                return(new InvalidSignatureResult(vendorTxCode));
            }

            if (!response.WasTransactionSuccessful)
            {
                ResetSessionInfo(cart, new FailureDetails
                {
                    Message =
                        "SagePay was unable to authorise payment with the provided details. Please confirm they are correct, or try another means of payment"
                });
            }
            else
            {
                _sagePayService.SetResponse(cart.UserGuid, response);
                _orderPlacementService.PlaceOrder(cart, o =>
                {
                    o.PaymentStatus      = PaymentStatus.Paid;
                    o.ShippingStatus     = ShippingStatus.Unshipped;
                    o.AuthorisationToken = response.BankAuthCode;
                });
            }
            return(new ValidOrderResult(vendorTxCode, response));
        }
コード例 #6
0
        public BraintreeResponse MakePaymentPaypal(string nonce)
        {
            BraintreeGateway   braintreeGateway = GetGateway();
            TransactionRequest request          = new TransactionRequest
            {
                Amount             = _cartModel.TotalToPay,
                PaymentMethodNonce = nonce,
                BillingAddress     = GetBillingAddress(),
                Options            = new TransactionOptionsRequest
                {
                    SubmitForSettlement = true
                }
            };

            Result <Transaction> result = braintreeGateway.Transaction.Sale(request);

            if (result.IsSuccess())
            {
                Order order = _orderPlacementService.PlaceOrder(_cartModel,
                                                                o =>
                {
                    o.PaymentStatus        = PaymentStatus.Paid;
                    o.CaptureTransactionId = result.Target.Id;
                });
                return(new BraintreeResponse {
                    Success = true, Order = order
                });
            }
            return(new BraintreeResponse
            {
                Success = false,
                Errors = new List <string> {
                    result.Message
                }
            });
        }
コード例 #7
0
        public CashOnDeliveryPlaceOrderResult TryPlaceOrder()
        {
            if (!_cart.CanPlaceOrder)
            {
                return(new CashOnDeliveryPlaceOrderResult
                {
                    CannotPlaceOrderReasons = new List <string>(_cart.CannotPlaceOrderReasons),
                    RedirectResult = _uniquePageService.RedirectTo <PaymentDetails>()
                });
            }
            var order = _orderPlacementService.PlaceOrder(_cart, o => { o.PaymentStatus = PaymentStatus.Pending; });

            return(new CashOnDeliveryPlaceOrderResult
            {
                RedirectResult = _uniquePageService.RedirectTo <OrderPlaced>(new { id = order.Guid })
            });
        }
コード例 #8
0
        public ActionResult Success(string vendorTxCode)
        {
            var sagePayResponse = _sagePayService.GetResponse(_cart.UserGuid);

            if (_cart.CartGuid.ToString() == vendorTxCode && sagePayResponse != null && sagePayResponse.WasTransactionSuccessful)
            {
                _orderPlacementService.PlaceOrder(_cart, o =>
                {
                    o.PaymentStatus      = PaymentStatus.Paid;
                    o.ShippingStatus     = ShippingStatus.Unshipped;
                    o.AuthorisationToken = sagePayResponse.BankAuthCode;
                });


                return(View((object)vendorTxCode));
            }
            return(View("Failed"));
        }
コード例 #9
0
        public PaymentNotRequiredResult TryPlaceOrder()
        {
            if (_cartModel.AnythingToPay())
            {
                return(new PaymentNotRequiredResult
                {
                    Success = false,
                    FailureDetails = new FailureDetails
                    {
                        Message =
                            _stringResourceProvider.GetValue("Payment Not Required Unavailable",
                                                             "The payment type is invalid for this cart, as there is something to pay"),
                    },
                    RedirectTo = _uniquePageService.RedirectTo <PaymentDetails>()
                });
            }

            if (_cartModel.CannotPlaceOrderReasons.Any())
            {
                return(new PaymentNotRequiredResult
                {
                    Success = false,
                    FailureDetails =
                        new FailureDetails
                    {
                        Message = string.Join(", ", _cartModel.CannotPlaceOrderReasons)
                    },
                    RedirectTo = _uniquePageService.RedirectTo <PaymentDetails>()
                });
            }

            var placeOrder = _orderPlacementService.PlaceOrder(_cartModel, order =>
            {
                order.PaymentStatus = PaymentStatus.Paid;
            });

            return(new PaymentNotRequiredResult
            {
                Success = true,
                RedirectTo = _uniquePageService.RedirectTo <OrderPlaced>(new { id = placeOrder.Guid })
            });
        }
コード例 #10
0
        public CharityClearResponse HandleNotification(FormCollection form)
        {
            _logService.Insert(new Log
            {
                Detail  = JsonConvert.SerializeObject(form),
                Message = "Callback from Charity Clear",
                Error   = new Error()
            });

            if (form["responseCode"] == "0")
            {
                Guid   cartGuid;
                string orderId = form["orderRef"];
                Guid.TryParse(orderId, out cartGuid);

                var existingOrder =
                    _session.QueryOver <Order>().Where(o => o.Guid == cartGuid).Take(1).SingleOrDefault();
                if (existingOrder != null)
                {
                    return(new CharityClearResponse
                    {
                        Order = existingOrder,
                        Success = true
                    });
                }

                string captureTransactionId = form["transactionID"];
                var    amountCharged        = form["amountReceived"];
                string hash = form["merchantData"];
                var    cart = GetCart(orderId);

                try
                {
                    if (!CheckHash(hash, orderId))
                    {
                        throw new Exception(string.Format("We could not validate this payment. Please contact us quoting reference {0}", captureTransactionId));
                    }
                    if (cart == null)
                    {
                        throw new Exception(string.Format("The order ID {0} doesn't exist", orderId));
                    }
                }
                catch (Exception exception)
                {
                    CurrentRequestData.ErrorSignal.Raise(exception);
                    return(new CharityClearResponse
                    {
                        ErrorMessages =
                            new List <string>
                        {
                            string.Format("Sorry, something went wrong. Please contact us quoting reference {0}", captureTransactionId)
                        }
                    });
                }

                if (amountCharged != ((int)(cart.TotalToPay * 100)).ToString())
                {
                    string message = string.Format("Something went wrong with the amount we charged you. Please contact us quoting transaction {0}", captureTransactionId);
                    _logService.Insert(new Log
                    {
                        Detail  = JsonConvert.SerializeObject(form),
                        Message = message,
                        Error   = new Error()
                    });
                    return(new CharityClearResponse
                    {
                        ErrorMessages =
                            new List <string>
                        {
                            message
                        }
                    });
                }

                Order order = _orderPlacementService.PlaceOrder(cart, o =>
                {
                    o.PaymentStatus        = PaymentStatus.Paid;
                    o.ShippingStatus       = ShippingStatus.Unshipped;
                    o.CaptureTransactionId = captureTransactionId;
                });

                return(new CharityClearResponse
                {
                    Order = order,
                    Success = true
                });
            }

            return(new CharityClearResponse
            {
                ErrorMessages =
                    new List <string>
                {
                    "Your transaction was not authorised. Please check your details and try again.", form["responseMessage"]
                }
            });
        }
コード例 #11
0
        public ActionResult HandleNotification(HttpRequestBase request)
        {
            NameValueCollection form        = request.Form;
            NameValueCollection queryString = request.QueryString;
            string  transStatus             = form["transStatus"] ?? string.Empty;
            string  returnedcallbackPw      = form["callbackPW"] ?? string.Empty;
            string  orderId            = form["cartId"] ?? string.Empty;
            string  returnedInstanceId = form["instId"] ?? string.Empty;
            string  callbackPassword   = _worldPaySettings.CallbackPassword;
            string  transId            = form["transId"] ?? string.Empty;
            string  transResult        = queryString["msg"] ?? string.Empty;
            string  authCode           = queryString["rawAuthMessage"] ?? string.Empty;
            decimal amount;

            decimal.TryParse(queryString["authAmount"], out amount);
            string instanceId = _worldPaySettings.InstanceId;

            CartModel cart = GetCart(orderId);

            try
            {
                if (cart == null)
                {
                    throw new Exception(string.Format("The order ID {0} doesn't exist", orderId));
                }

                if (string.IsNullOrEmpty(instanceId))
                {
                    throw new Exception("Worldpay Instance ID is not set");
                }

                if (string.IsNullOrEmpty(returnedInstanceId))
                {
                    throw new Exception("Returned Worldpay Instance ID is not set");
                }

                if (instanceId.Trim() != returnedInstanceId.Trim())
                {
                    throw new Exception(
                              string.Format(
                                  "The Instance ID ({0}) received for order {1} does not match the WorldPay Instance ID stored in the database ({2})",
                                  returnedInstanceId, orderId, instanceId));
                }

                if (returnedcallbackPw.Trim() != callbackPassword.Trim())
                {
                    throw new Exception(
                              string.Format(
                                  "The callback password ({0}) received within the Worldpay Callback for the order {1} does not match that stored in your database.",
                                  returnedcallbackPw, orderId));
                }

                if (transStatus.ToLower() != "y")
                {
                    throw new Exception(
                              string.Format(
                                  "The transaction status received from WorldPay ({0}) for the order {1} was declined.",
                                  transStatus, orderId));
                }
                if (cart.TotalToPay != amount)
                {
                    throw new Exception(
                              string.Format("The paid amount {0} does not match the amount to pay {1}", amount,
                                            cart.TotalToPay));
                }
            }
            catch (Exception exception)
            {
                CurrentRequestData.ErrorSignal.Raise(exception);
                return(new ContentResult
                {
                    Content = exception.Message
                });
            }
            Order order = _orderPlacementService.PlaceOrder(cart, o =>
            {
                o.PaymentStatus        = PaymentStatus.Paid;
                o.ShippingStatus       = ShippingStatus.Unshipped;
                o.AuthorisationToken   = authCode;
                o.CaptureTransactionId = transId;
            });

            return(new ViewResult {
                ViewName = "RedirectToComplete", ViewData = new ViewDataDictionary(order)
            });
        }
コード例 #12
0
 public void Handle(OrderPaidEvent domainEvent)
 {
     System.Console.WriteLine("[Event] - PlaceOrderWhenPaidEventHandler.Handle(domainEvent)");
     _orderPlacement.PlaceOrder(domainEvent.Payment.OrderId);
 }