示例#1
0
        public NVPCodec GetNVPFromOrder(Order order)
        {
            NVPCodec encoder      = new NVPCodec();
            int      count        = 0;
            var      orderDetails = market.OrderDetails.Where(o => o.OrderId == order.OrderId).ToList();

            encoder["METHOD"]    = "SetExpressCheckout";
            encoder["RETURNURL"] = returnURL;
            encoder["CANCELURL"] = cancelURL;
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "CAD";
            encoder["NOSHIPPING"] = "1";
            //encoder["AMT"] = order.Total.ToString();
            encoder["PAYMENTREQUEST_0_ITEMAMT"] = order.Total.ToString();
            encoder["PAYMENTREQUEST_0_AMT"]     = order.Total.ToString();

            foreach (OrderDetailModel o in orderDetails)
            {
                encoder[PAYMENT + "NAME" + count] = o.Item.Name;
                encoder[PAYMENT + "DESC" + count] = "Test Description";

                /*
                 * encoder[PAYMENT + "DESC" + count] = "Pickup:" + o.PickupDate.ToLongDateString() +
                 *  " Return:" + o.DrofoffDate.ToLongDateString();
                 */
                encoder[PAYMENT + "QTY" + count] = o.NumberOfDays.ToString();
                encoder[PAYMENT + "AMT" + count] = o.UnitPrice.ToString();
                count++;
                if (o.SecurityDeposit > 0)
                {
                    encoder[PAYMENT + "NAME" + count] = "Security Deposit - " + o.Item.Name;
                    encoder[PAYMENT + "DESC" + count] = "Security Deposit";

                    /*
                     * encoder[PAYMENT + "DESC" + count] = "Pickup:" + o.PickupDate.ToLongDateString() +
                     *  " Return:" + o.DrofoffDate.ToLongDateString();
                     */
                    encoder[PAYMENT + "QTY" + count] = "1";
                    encoder[PAYMENT + "AMT" + count] = o.SecurityDeposit.ToString();
                    count++;
                }
            }


            return(encoder);
        }
示例#2
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["SHIPTONAME"] + "</td></tr>";
                ShippingAddress += "<td> Street1 </td><td>" + decoder["SHIPTOSTREET"] + "</td></tr>";
                ShippingAddress += "<td> Street2 </td><td>" + decoder["SHIPTOSTREET2"] + "</td></tr>";
                ShippingAddress += "<td> City </td><td>" + decoder["SHIPTOCITY"] + "</td></tr>";
                ShippingAddress += "<td> State </td><td>" + decoder["SHIPTOSTATE"] + "</td></tr>";
                ShippingAddress += "<td> Zip </td><td>" + decoder["SHIPTOZIP"] + "</td>";
                ShippingAddress += "</tr>";

                return(true);
            }
            else
            {
                retMsg = "?" +
                         "ErrorCode=" + ErrorCode.PAYPAL_ERROR + "&" + //decoder["L_ERRORCODE0"]
                         "Description=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }
示例#3
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, 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"]         = this.PayPalToken;
            encoder["PAYMENTACTION"] = "Sale";
            encoder["PAYERID"]       = this.PayerID;
            encoder["AMT"]           = finalPaymentAmount;
            encoder["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=" + ErrorCode.PAYPAL_ERROR + "&" + //decoder["L_ERRORCODE0"]
                         "Description=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }
示例#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, NVPCodec encoder, 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 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" + "&useraction=commit" + "&token=" + token;

                retMsg = ECURL;
                return(true);
            }
            else
            {
                retMsg = "?" +
                         "ErrorCode=" + ErrorCode.PAYPAL_ERROR + "&" + //decoder["L_ERRORCODE0"]
                         "Description=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }
示例#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://test";
            string cancelURL = "http://test";

            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"]        = "SetExpressCheckout";
            encoder["RETURNURL"]     = returnURL;
            encoder["CANCELURL"]     = cancelURL;
            encoder["AMT"]           = amt;
            encoder["PAYMENTACTION"] = "Sale";
            encoder["CURRENCYCODE"]  = "CAD";

            //Optional Shipping Address entered on the merchant site
            encoder["SHIPTONAME"]        = shipToName;
            encoder["SHIPTOSTREET"]      = shipToStreet;
            encoder["SHIPTOSTREET2"]     = shipToStreet2;
            encoder["SHIPTOCITY"]        = shipToCity;
            encoder["SHIPTOSTATE"]       = shipToState;
            encoder["SHIPTOZIP"]         = shipToZip;
            encoder["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=" + ErrorCode.PAYPAL_ERROR + "&" + //decoder["L_ERRORCODE0"]
                         "Description=" + decoder["L_LONGMESSAGE0"];

                return(false);
            }
        }