private PayFlowRequest SetReq(CartShipPayInfo csp, CreditCardInfo card)
        {
            PayFlowRequest req = new PayFlowRequest
            {
                Pwd     = "1812war347813",
                Vendor  = "stesha",
                User    = "******",
                Partner = "VSA",//id of the gateway provider
                //live endpoint
                // Endpoint = "https://payflowpro.paypal.com",
                //test endpoint
                Endpoint  = "https://pilot-payflowpro.paypal.com",
                Amt       = Convert.ToString(csp.ShoppingCart.ComputeCartValue()), // amount of sale with two decimal places
                Currency  = "AUD",
                Trxtype   = "S",                                                   // type of transaction S-for sale
                Tender    = "C",                                                   // method of payment C - for credit card
                Timeout   = "300",
                Verbosity = "HIGH",
                Hostport  = "443",

                // temp values
                SecCode = card.Verification,
                Acct    = card.Account, // creit card number
                ExpDate = "0719"        //card.months + card.years

                                        ///additional possible settings
                                        ///SILENTTRAN=TRUE // for silent redirect
            };

            return(req);
        }
        private Order CopyDirectPaymentToOrder(string resp)
        {
            CartShipPayInfo csp        = (CartShipPayInfo)Session["CartShipPayInfo"];
            string          customerId = (Session["Profile"] == null) ? csp.ShippingDetails.Email :
                                         Convert.ToString(((ApplicationUser)Session["Profile"]).Id);

            Order order = new Order
            {
                CspPayerEmail      = csp.ShippingDetails.Email,
                CspShippingAddress = csp.ShippingDetails.GetAddress(),
                RequestCurrency    = GetValue(resp, "CURRENCY"),
                RequestFirstName   = csp.ShippingDetails.Name,
                RequestLastName    = csp.ShippingDetails.Surname,
                Total                 = csp.ShoppingCart.ComputeCartValue().ToString("c"),
                RequestPayerId        = customerId,
                RequestTxnType        = "Sale",
                RequestReceiverId     = "Stesha Pty Ltd",
                RequestListOfProducts = csp.ShoppingCart.GetProductsList(),
                RequestPaymentDate    = GetValue(resp, "TRANSTIME") == null?DateTime.Now.ToString() : GetValue(resp, "TRANSTIME"),
                                            CspContactNumber     = ((csp.ShippingDetails.Phone == null) ? "not provided" : csp.ShippingDetails.Phone),
                                            CartNumberOfItems    = Convert.ToString(csp.ShoppingCart.ProductLines.Sum(p => p.Quantity)),
                                            RequestPaymentStatus = GetValue(resp, "RESPMSG"),
                                            RequestTxnId         = GetValue(resp, "PNREF"),
            };


            return(order);
        }
        // use following test details for FDMS Nashvillle processor 4111111111111111 (a 4 and fifteen 1’s), expiration date 12/15, card security code 123.



        public ActionResult Set(CreditCardInfo card)
        {
            CartShipPayInfo csp = (CartShipPayInfo)Session["CartShipPayInfo"];
            PayFlowRequest  req = SetReq(csp, card);

            string payLoad  = req.BuildPayload();
            string response = SendReq(req.Endpoint, payLoad, BuildHeaders());
            string result   = GetValue(response, "RESULT");
            Order  order    = CopyDirectPaymentToOrder(response);

            if (result.Equals("0") && GetValue(response, "CVV2MATCH") == "Y")
            {
                TempData["Confirm"] = "The payment has been successfully processed";

                repo.SaveAllToDatabase(order);
                csp.ShoppingCart.ClearCart();

                return(View("ConfirmPayment", order));
            }
            else
            {
                TempData["Fail"] = "Payment failed";
                repo.SaveIncompleteOrder(order);
                return(View("_ErrorDisplay"));
            }
        }
        private Order CopyExpressCheckoutReqToOrder(ExprPayPalRequest req)
        {
            CartShipPayInfo csp = (CartShipPayInfo)Session["CartShipPayInfo"];

            Order order = new Order
            {
                CspPayerEmail         = req.PayerEmail,
                CspShippingAddress    = req.ShipAddress,
                RequestCurrency       = req.currency,
                RequestFirstName      = req.PayerName,
                RequestLastName       = req.PayerLastName,
                RequestPayerId        = req.PayerId,
                RequestListOfProducts = req.Products,
                PayPalPayerId         = req.PayPalPayerId,
                RequestPaymentDate    = req.TransTime,
                CspContactNumber      = csp.ShippingDetails.Phone,
                CartNumberOfItems     = Convert.ToString(csp.ShoppingCart.ProductLines.Sum(p => p.Quantity)),
                RequestPaymentStatus  = req.PaymentStatus,
                RequestTxnId          = req.TransId,
                RequestTxnType        = req.TransType,
                RequestReceiverId     = req.PayPalMerchantUsername,
                Total        = req.Total,
                ShiptoName   = req.ShiptoName,
                ShippingCost = req.ShippingCost,
                SubTotal     = req.SubTotal
            };

            order.OrderedProducts = GetOrderedProducts(req.ProductsList, order.Id);

            return(order);
        }
        public ViewResult DoExpressCheckoutPayment()
        {
            try
            {
                ExprPayPalRequest req = (ExprPayPalRequest)Session[reqKey];
                req.Method = "DoExpressCheckoutPayment";

                string resp = SendRequest(req.Endpoint, req.ToString());

                string ack = ParseToken(resp, "ACK");
                req.TransId       = ParseToken(resp, "PAYMENTINFO_0_TRANSACTIONID");
                req.TransType     = ParseToken(resp, "PAYMENTINFO_0_TRANSACTIONTYPE");
                req.PaymentStatus = ParseToken(resp, "PAYMENTINFO_0_PAYMENTSTATUS");

                // send mail to customer
                if (ack.Equals("Success") && (req.Token.Equals(ParseToken(resp, "TOKEN"))))
                {
                    Order order = CopyExpressCheckoutReqToOrder(req);
                    repo.SaveAllToDatabase(order);

                    sendCustomerEmail(order);
                    sendAdminEmail(order);

                    CartShipPayInfo csp = (CartShipPayInfo)Session["CartShipPayInfo"];
                    csp.ShoppingCart.ClearCart();
                    TempData["Confirm"] = "Payment Successful";
                    return(View("ConfirmPayment", order));
                }
            }
            catch (Exception)
            {
            }
            TempData["Fail"] = failMessage;
            return(View("_ErrorDisplay"));
        }
示例#6
0
        public ViewResult ProceedToPay(ShoppingCart cart, ShippingDetails ShipDet, string updateUser)
        {
            if (ModelState.IsValid)
            {
                CartShipPayInfo cspInfo = new CartShipPayInfo();
                // prepare for credit card payment
                PrepareCreditCardFields();

                if (updateUser == null ? false : updateUser.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                {
                    // updates the current user details and stores it in the session state
                    Session["Profile"] = repo.UpdateUserDetails(ShipDet, User.Identity.Name);
                }
                cspInfo.ShoppingCart       = cart;
                cspInfo.ShippingDetails    = ShipDet;
                Session["CartShipPayInfo"] = cspInfo; // save the whole order data class into session state
                ViewData["cartValue"]      = cart.ComputeCartValue().ToString("c");

                return(View(new CreditCardInfo()));
            }
            else
            {
                return(View("Checkout", new ShippingInfo(repo)
                {
                    ShipDet = ShipDet
                }));
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        // following code is used for PayPal's Eexpress Checkout functionality
        // detailed tutorial on express checkout is at https://developer.paypal.com/webapps/developer/docs/classic/express-checkout/ht_ec-singleItemPayment-curl-etc/
        ////////////////////////////////////////////////////////////////////////////////////////////////////



        public RedirectResult SetExpressCheckout()
        {
            CartShipPayInfo   csp = (CartShipPayInfo)Session["CartShipPayInfo"];
            ExprPayPalRequest req = new ExprPayPalRequest()
            {
                // live credentials
                Password = "******",
                PayPalMerchantUsername = "******",
                Signature = "AcQ.7s0YrYjFbaBoVNy6bGaoP-VpAkRQHqL0If7cnR.3iZZFIjV8BG6h",

                Endpoint = "https://api-3t.paypal.com/nvp/", //nvp production
                //req.Endpoint = "https://api-3t.sandbox.paypal.com/nvp/"; // nvp     sandbox
                Method = "SetExpressCheckout",               // METHOD
                // set all costs and products details from cart info
                ProductsList = csp.ShoppingCart.ProductLines,
                Total        = Convert.ToString(csp.ShoppingCart.ComputeCartValue() + csp.ShoppingCart.ShippingCosts),
                SubTotal     = Convert.ToString(csp.ShoppingCart.ComputeCartValue()),//
                ShippingCost = Convert.ToString(csp.ShoppingCart.ShippingCosts),
                currency     = "AUD",
                //  set urls
                //ReturnUrl = "http://localhost:33966/ExpressCheckout/GetExpressCheckoutDetails",
                CancelUrl = "http://localhost:33966/Cart/RedirectAfterCancel",
                ReturnUrl = "https://stesha.com.au/ExpressCheckout/GetExpressCheckoutDetails",
                //CancelUrl = "https://stesha.com.au/Cart/RedirectAfterCancel",
                Version       = 93,
                PaymentAction = "SALE"
            };



            try
            {
                // make a call to PayPal and read answer
                string resp = SendRequest(req.Endpoint, req.ToString());
                req.Token = ParseToken(resp, "TOKEN");
            }
            catch (Exception)
            {
                TempData["Fail"] = failMessage;
                return(Redirect("_ErrorDisplay"));
            }

            // string url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + req.Token;
            string url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + req.Token;

            Session[reqKey] = req;

            return(Redirect(url));
        }
        public ActionResult GetExpressCheckoutDetails()
        {
            CartShipPayInfo csp = (CartShipPayInfo)Session["CartShipPayInfo"];
            // after the payment is confirmed get the payer's details
            ExprPayPalRequest req = (ExprPayPalRequest)Session[reqKey];

            req.Method = "GetExpressCheckoutDetails";

            try
            {
                //send data to pay pal server  and read response
                string resp = SendRequest(req.Endpoint, req.ToString());
                string ack  = ParseToken(resp, "ACK");

                // verify success and token
                if (ack.Equals("Success") && (req.Token.Equals(ParseToken(resp, "TOKEN"))))
                {
                    req.PayerId = (Session["Profile"] == null) ? csp.ShippingDetails.Email :
                                  Convert.ToString(((ApplicationUser)Session["Profile"]).Id);
                    req.PayPalPayerId = ParseToken(resp, "PAYERID");
                    req.Total         = ParseToken(resp, "PAYMENTREQUEST_0_AMT");
                    req.PayerEmail    = csp.ShippingDetails.Email;
                    req.PayerName     = ParseToken(resp, "FIRSTNAME");
                    req.PayerLastName = ParseToken(resp, "LASTNAME");
                    req.ShiptoName    = csp.ShippingDetails.Name + " " + csp.ShippingDetails.Surname;
                    req.ShipAddress   = csp.ShippingDetails.GetAddress();
                    req.TransTime     = Convert.ToString(DateTime.Parse(ParseToken(resp, "TIMESTAMP")));
                    Session[reqKey]   = req;

                    return(new RedirectResult("/ExpressCheckout/DoExpressCheckoutPayment"));
                }
                else
                {
                    TempData["Fail"] = failMessage;
                    return(View("_ErrorDisplay"));
                }
            }
            catch (Exception)
            {
                TempData["Fail"] = failMessage;
                return(View("_ErrorDisplay"));
            }
        }
示例#9
0
 public void ProcessPaymentConfirmation(CartShipPayInfo csp)
 {
 }