// The user is redirected to paymentcallback/user/orderRef={guid}&orderNumber={string}&confirmationUrl={url} after having successfully supplied their payment information in PayEx public RedirectResult User(string orderRef, string orderNumber, string confirmationUrl) { UrlBuilder confirmationUrlBuilder = new UrlBuilder(confirmationUrl); // Get the cart for the current user Cart cart = new CartHelper(Cart.DefaultName).Cart; PayExPayment payExPayment = GetPayExPayment(cart); // If the cart doesn't contain a PayExPayment, something has gone wrong if (payExPayment == null) { return(ErrorResult(confirmationUrlBuilder, null)); } // If the PayExPayment doesn't contain an OrderNumber, something has gone wrong if (string.IsNullOrWhiteSpace(payExPayment.OrderNumber)) { return(ErrorResult(confirmationUrlBuilder, null)); } // If the PayExPayment OrderNumber doesn't equal the orderNumber from the queryString, something has gone wrong if (!payExPayment.OrderNumber.Equals(orderNumber)) { return(ErrorResult(confirmationUrlBuilder, null)); } PayExPaymentGateway gateway = new PayExPaymentGateway(); string transactionErrorCode; // Complete the PayEx payment bool processed = gateway.ProcessSuccessfulTransaction(payExPayment, orderNumber, orderRef, cart, out transactionErrorCode); bool created = false; if (processed) // If the payment was successfully completed, you can create a Purchase Order { created = CreatePurchaseOrder(cart, payExPayment, orderNumber); } if (!created) { return(ErrorResult(confirmationUrlBuilder, transactionErrorCode)); } // Redirect the user to an order confirmation page confirmationUrlBuilder.QueryCollection.Add(ParameterName.OrderNumber, orderNumber); return(new RedirectResult(confirmationUrlBuilder.ToString())); }
// This action is used for transactional callbacks: http://www.payexpim.com/quick-guide/9-transaction-callback/ public HttpStatusCodeResult Index(string orderRef, [Bind(Prefix = ParameterName.PayExTransactionNumber)] string transactionNumber, [Bind(Prefix = ParameterName.PayExTransactionRef)] string transactionRef) { // Check that the request comes from a valid PayEx IP: http://www.payexpim.com/quick-guide/9-transaction-callback/ // The IP should not be hardcoded, this is only an example! if (Request.ServerVariables["REMOTE_ADDR"] != "82.115.146.170") { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (string.IsNullOrEmpty(orderRef)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } string orderNumber; Cart cart = GetCartByOrderRef(orderRef, out orderNumber); if (cart == null || string.IsNullOrEmpty(orderNumber)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PayExPayment payExPayment = GetPayExPayment(cart); PayExPaymentGateway gateway = new PayExPaymentGateway(); string transactionErrorCode; // Complete the PayEx payment bool success = gateway.ProcessSuccessfulTransaction(payExPayment, orderNumber, orderRef, cart, out transactionErrorCode); if (success) { return(new HttpStatusCodeResult(HttpStatusCode.OK)); } else { // If an order has already been created, maybe you'd want to cancel it if the callback wasn't successful? } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }