Ejemplo n.º 1
0
        /// <summary>
        /// GetShippingDetails: The method that calls SetExpressCheckout API, invoked from the
        /// Billing Page EC placement
        /// </summary>
        /// <param name="token"></param>
        /// <param ref name="retMsg"></param>
        /// <returns></returns>
        public bool GetShippingDetails(string token, ref string PayerId, ref string ShippingAddress, ref string retMsg)
        {
            if (bSandbox)
            {
                pendpointurl = "https://api-3t.sandbox.paypal.com/nvp";
            }

            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"] = "GetExpressCheckoutDetails";
            encoder["TOKEN"]  = token;

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = HttpCall(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);

            string strAck = decoder["ACK"].ToLower();

            if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
            {
                ShippingAddress  = "<table><tr>";
                ShippingAddress += "<td> First Name </td><td>" + ":" + decoder["FIRSTNAME"] + "." + "</td></tr>";
                ShippingAddress += "<td> Last Name </td><td>" + ":" + decoder["LASTNAME"] + "." + "</td></tr>";
                ShippingAddress += "<td colspan='2'> Shipping Address</td></tr>";
                ShippingAddress += "<td> Name </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTONAME"] + "." + "</td></tr>";
                ShippingAddress += "<td> Street1 </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOSTREET"] + "." + "</td></tr>";
                ShippingAddress += "<td> Street2 </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOSTREET2"] + "." + "</td></tr>";
                ShippingAddress += "<td> City </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOCITY"] + "." + "</td></tr>";
                ShippingAddress += "<td> State </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOSTATE"] + "." + "</td></tr>";
                ShippingAddress += "<td> Zip </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOZIP"] + "." + "</td>";
                ShippingAddress += "</tr></table>";

                return(true);
            }
            else
            {
                retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                         "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                         "Desc2=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// ConfirmPayment: The method that calls SetExpressCheckout API, invoked from the
        /// Billing Page EC placement
        /// </summary>
        /// <param name="token"></param>
        /// <param ref name="retMsg"></param>
        /// <returns></returns>
        public bool ConfirmPayment(string finalPaymentAmount, string token, string PayerId, ref NVPCodec decoder, ref string retMsg)
        {
            if (bSandbox)
            {
                pendpointurl = "https://api-3t.sandbox.paypal.com/nvp";
            }

            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"] = "DoExpressCheckoutPayment";
            encoder["TOKEN"]  = token;
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
            encoder["PAYERID"] = PayerId;
            encoder["PAYMENTREQUEST_0_AMT"]          = finalPaymentAmount;
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD";

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = HttpCall(pStrrequestforNvp);

            decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);

            string strAck = decoder["ACK"].ToLower();

            if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
            {
                return(true);
            }
            else
            {
                retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                         "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                         "Desc2=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }
Ejemplo n.º 3
0
        public ActionResult ConfirmerTransaction(string shipping)
        {
            PaypalNVPAPICaller test = new PaypalNVPAPICaller();

            string   retMsg             = "";
            string   token              = "";
            string   finalPaymentAmount = "";
            string   payerId            = "";
            NVPCodec decoder            = null;

            token              = Session["token"].ToString();
            payerId            = Session["payerId"].ToString();
            finalPaymentAmount = Session["payment_amt"].ToString();

            bool ret = test.ConfirmPayment(finalPaymentAmount, token, payerId, ref decoder, ref retMsg);

            if (ret)
            {
                // Unique transaction ID of the payment. Note:  If the PaymentAction of the request was Authorization or Order, this value is your AuthorizationID for use with the Authorization & Capture APIs.
                string transactionId = decoder["PAYMENTINFO_0_TRANSACTIONID"];

                // The type of transaction Possible values: l  cart l  express-checkout
                string transactionType = decoder["PAYMENTINFO_0_TRANSACTIONTYPE"];

                // Indicates whether the payment is instant or delayed. Possible values: l  none l  echeck l  instant
                string paymentType = decoder["PAYMENTINFO_0_PAYMENTTYPE"];

                // Time/date stamp of payment
                string orderTime = decoder["PAYMENTINFO_0_ORDERTIME"];

                // The final amount charged, including any shipping and taxes from your Merchant Profile.
                string amt = decoder["PAYMENTINFO_0_AMT"];

                // A three-character currency code for one of the currencies listed in PayPay-Supported Transactional Currencies. Default: USD.
                string currencyCode = decoder["PAYMENTINFO_0_CURRENCYCODE"];

                // PayPal fee amount charged for the transaction
                string feeAmt = decoder["PAYMENTINFO_0_FEEAMT"];

                // Amount deposited in your PayPal account after a currency conversion.
                string settleAmt = decoder["PAYMENTINFO_0_SETTLEAMT"];

                // Tax charged on the transaction.
                string taxAmt = decoder["PAYMENTINFO_0_TAXAMT"];

                //' Exchange rate if a currency conversion occurred. Relevant only if your are billing in their non-primary currency. If
                string exchangeRate = decoder["PAYMENTINFO_0_EXCHANGERATE"];
                var    cart         = ShoppingCart.GetCart(this.HttpContext);


                //If it gets here, the order went all succesful, and it will now create the order in the database, in order to keep a history
                Order      order = new Order();
                AspNetUser aUser = storeDB.AspNetUsers.First(c => c.Email == User.Identity.Name);
                order.AspNetUsers = aUser;
                string[] addr = Session["shipping"].ToString().Split(':', '.');
                order.FirstName  = aUser.FirstName;
                order.LastName   = aUser.Lastname;
                order.City       = aUser.City;
                order.Address    = aUser.Address;
                order.State      = aUser.State;
                order.PostalCode = aUser.PostalCode;
                order.OrderDate  = DateTime.Now;
                order.Country    = aUser.Country;
                order.Phone      = aUser.PhoneNumber;
                string stotal = Session["payment_amt"].ToString();
                stotal = stotal.Replace('.', ',');
                float itotal = float.Parse(stotal);
                order.Total = (decimal)itotal;

                var lstitem = cart.GetCartItems();
                foreach (var i in lstitem)
                {
                    OrderDetail detail = new OrderDetail();
                    detail.ProductId = i.ProductID;
                    detail.Quantity  = i.Count;
                    detail.UnitPrice = i.TotalPerItem;
                    detail.Order     = order;
                    order.OrderDetail.Add(detail);
                }


                storeDB.Orders.Add(order);
                cart.EmptyCart();
                storeDB.SaveChanges();



                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(Redirect("APIError?" + retMsg));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ShortcutExpressCheckout: The method that calls SetExpressCheckout API
        /// </summary>
        /// <param name="amt"></param>
        /// <param ref name="token"></param>
        /// <param ref name="retMsg"></param>
        /// <returns></returns>
        public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg, List <Cart> cartItems, decimal dshipping)
        {
            string host = "www.paypal.com";

            if (bSandbox)
            {
                pendpointurl = "https://api-3t.sandbox.paypal.com/nvp";
                host         = "www.sandbox.paypal.com";
            }

            string returnURL = "http://localhost:5032/CheckOutPaypal/ConfirmPaiement";
            string cancelURL = "http://localhost:5032/CheckOutPaypal/CancelPaiement";

            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"]                         = "SetExpressCheckout";
            encoder["RETURNURL"]                      = returnURL;
            encoder["CANCELURL"]                      = cancelURL;
            encoder["PAYMENTREQUEST_0_AMT"]           = amt;
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "CAD";

            int i = 0;

            foreach (var items in cartItems)
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + i] = items.Product.Name;

                string TotaltwoDec = items.TotalPerItem.ToString("0.00");   // Important de mettre 2 chiffres après la virgule sinon ça f**k paypal.
                TotaltwoDec = TotaltwoDec.Replace(",", ".");                // On remplace les virgules française pour des points!
                encoder["L_PAYMENTREQUEST_0_AMT" + i] = TotaltwoDec;        // On envoie le string à PayPal, PayPal aime les string.

                encoder["L_PAYMENTREQUEST_0_QTY" + i] = items.Count.ToString();
                i++;
            }

            encoder["L_PAYMENTREQUEST_0_NAME" + i] = "Shipping";
            string sshipping = dshipping.ToString("0.00").Replace(',', '.');

            encoder["L_PAYMENTREQUEST_0_AMT" + i] = sshipping;
            encoder["L_PAYMENTREQUEST_0_QTY" + i] = "1";

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = HttpCall(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);

            string strAck = decoder["ACK"].ToLower();

            if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
            {
                token = decoder["TOKEN"];

                string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token;

                retMsg = ECURL;
                return(true);
            }
            else
            {
                retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                         "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                         "Desc2=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// MarkExpressCheckout: The method that calls SetExpressCheckout API, invoked from the
        /// Billing Page EC placement
        /// </summary>
        /// <param name="amt"></param>
        /// <param ref name="token"></param>
        /// <param ref name="retMsg"></param>
        /// <returns></returns>
        public bool MarkExpressCheckout(string amt,
                                        string shipToName, string shipToStreet, string shipToStreet2,
                                        string shipToCity, string shipToState, string shipToZip,
                                        string shipToCountryCode, ref string token, ref string retMsg)
        {
            string host = "www.paypal.com";

            if (bSandbox)
            {
                pendpointurl = "https://api-3t.sandbox.paypal.com/nvp";
                host         = "www.sandbox.paypal.com";
            }

            string returnURL = "http://localhost:5032/CheckOutPaypal/ConfirmPaiement";
            string cancelURL = "http://localhost:5032/CheckOutPaypal/CancelPaiement";

            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"]                         = "SetExpressCheckout";
            encoder["RETURNURL"]                      = returnURL;
            encoder["CANCELURL"]                      = cancelURL;
            encoder["PAYMENTREQUEST_0_AMT"]           = amt;
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "CAD";

            //Optional Shipping Address entered on the merchant site
            encoder["PAYMENTREQUEST_0_SHIPTONAME"]        = shipToName;
            encoder["PAYMENTREQUEST_0_SHIPTOSTREET"]      = shipToStreet;
            encoder["PAYMENTREQUEST_0_SHIPTOSTREET2"]     = shipToStreet2;
            encoder["PAYMENTREQUEST_0_SHIPTOCITY"]        = shipToCity;
            encoder["PAYMENTREQUEST_0_SHIPTOSTATE"]       = shipToState;
            encoder["PAYMENTREQUEST_0_SHIPTOZIP"]         = shipToZip;
            encoder["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = shipToCountryCode;


            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = HttpCall(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);

            string strAck = decoder["ACK"].ToLower();

            if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
            {
                token = decoder["TOKEN"];

                string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token;

                retMsg = ECURL;
                return(true);
            }
            else
            {
                retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                         "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                         "Desc2=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }