Esempio n. 1
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, string currency, 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["PAYMENTACTION"] = "Sale";
            encoder["PAYERID"] = PayerId;
            encoder["AMT"] = finalPaymentAmount;
            encoder["CURRENCYCODE"] = currency;

            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;
            }
        }
Esempio 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, string currency, 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["PAYMENTACTION"] = "Sale";
            encoder["PAYERID"]       = PayerId;
            encoder["AMT"]           = finalPaymentAmount;
            encoder["CURRENCYCODE"]  = currency;

            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);
            }
        }
Esempio n. 3
0
        public bool ExpressCheckout(string name, string description, string price, string quantity, string currency, string email, 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";
            }

            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"]                    = "SetExpressCheckout";
            encoder["RETURNURL"]                 = returnURL;
            encoder["CANCELURL"]                 = cancelURL;
            encoder["NOTIFYURL"]                 = ipnURL;
            encoder["SOLUTIONTYPE"]              = "Sole";
            encoder["PAYMENTREQUEST_0_CUSTOM"]   = email;
            encoder["LANDINGPAGE"]               = "Billing";
            encoder["USERSELECTEDFUNDINGSOURCE"] = "CreditCard";


            double dblQuantity = Convert.ToDouble(quantity);
            double dblPrice    = Convert.ToDouble(price);
            double totalPrice  = dblQuantity * dblPrice;

            encoder["L_PAYMENTREQUEST_0_NAME0"] = name;
            encoder["L_PAYMENTREQUEST_0_DESC0"] = description;
            encoder["L_PAYMENTREQUEST_0_AMT0"]  = price;
            encoder["L_PAYMENTREQUEST_0_QTY0"]  = quantity;

            encoder["PAYMENTREQUEST_0_AMT"]           = totalPrice.ToString();
            encoder["PAYMENTREQUEST_0_ITEMAMT"]       = totalPrice.ToString();
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "SALE";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = currency;

            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 + "&useraction=COMMIT";

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

                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Credentials added to the NVP string
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        private string buildCredentialsNVPString()
        {
            NVPCodec codec = new NVPCodec();

            if (!IsEmpty(APIUsername))
                codec["USER"] = APIUsername;

            if (!IsEmpty(APIPassword))
                codec["PWD"] = APIPassword;

            if (!IsEmpty(APISignature))
                codec["SIGNATURE"] = APISignature;

            if (!IsEmpty(Subject))
                codec["SUBJECT"] = Subject;

            codec["VERSION"] = "84.0";

            return codec.Encode();
        }
Esempio n. 5
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 GetDetails(string token, ref NVPCodec decoder, 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);

            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;
            }
        }
Esempio n. 6
0
        public bool ExpressCheckout(string name, string description, string price, string quantity, string currency,string email, 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";
            }

            NVPCodec encoder = new NVPCodec();
            encoder["METHOD"] = "SetExpressCheckout";
            encoder["RETURNURL"] = returnURL;
            encoder["CANCELURL"] = cancelURL;
            encoder["NOTIFYURL"] = ipnURL;
            encoder["SOLUTIONTYPE"] = "Sole";
            encoder["PAYMENTREQUEST_0_CUSTOM"] = email;
            encoder["LANDINGPAGE"] = "Billing";
            encoder["USERSELECTEDFUNDINGSOURCE"] = "CreditCard";

            double dblQuantity = Convert.ToDouble(quantity);
            double dblPrice = Convert.ToDouble(price);
            double totalPrice = dblQuantity * dblPrice;

            encoder["L_PAYMENTREQUEST_0_NAME0"] = name;
            encoder["L_PAYMENTREQUEST_0_DESC0"] = description;
            encoder["L_PAYMENTREQUEST_0_AMT0"] = price;
            encoder["L_PAYMENTREQUEST_0_QTY0"] = quantity;

            encoder["PAYMENTREQUEST_0_AMT"] = totalPrice.ToString();
            encoder["PAYMENTREQUEST_0_ITEMAMT"] = totalPrice.ToString();
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "SALE";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = currency;

            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 + "&useraction=COMMIT";

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

                return false;
            }
        }
        public ActionResult ThankYou()
        {
            NVPAPICaller PPAPICaller = new NVPAPICaller();
            NVPCodec decoder = new NVPCodec();
            string token = string.Empty;
            string payerID = string.Empty;
            string finalPaymentAmount = string.Empty;
            string retMsg = string.Empty;
            string currency = string.Empty;
            string email = string.Empty;
            string transactionId = string.Empty;
            token = Session["token"].ToString();
            var payPalFee = string.Empty;
            AspNetUser userToUpdate = null;
            //use the PayPal token to get the details of payment - this could include shipping details
            bool ret = PPAPICaller.GetDetails(token, ref decoder, ref retMsg);
            if (ret)
            {
                payerID = decoder["PayerID"];
                token = decoder["token"];
                finalPaymentAmount = decoder["PAYMENTREQUEST_0_AMT"];
                currency = decoder["CURRENCYCODE"];
                email = decoder["PAYMENTREQUEST_0_CUSTOM"];
                transactionId = token;
                payPalFee = "0"; //decoder["PAYMENTINFO_n_FEEAMT"];
                // string Success= "Payment successful for - PayerID: " + payerID + "; Amount: " + finalPaymentAmount;
            }
            else
            {
                //error.LogError();
            }

            NVPCodec confirmdecoder = new NVPCodec();

            //confirm that payment was taken
            bool ret2 = PPAPICaller.ConfirmPayment(finalPaymentAmount, token, payerID, currency, ref confirmdecoder, ref retMsg);
            if (ret2)
            {
                //if payment was taken do some back end processing to mark order as paid
                //use token to work out which order to mark as paid
                token = confirmdecoder["token"];


                var txn = transactionId;
                var amount = finalPaymentAmount;
             
                userToUpdate = UserManager.FindByEmail(email);
                if (userToUpdate != null)
                {
                    userToUpdate.Package = 1;
                    userToUpdate.RegisterPayPalDate = DateTime.Now;
                    userToUpdate.RegisterPayPalTxnID = txn;
                    userToUpdate.PayPalAmount = double.Parse(amount);
                    userToUpdate.PayPalAmountAfterDeduct = double.Parse(amount) - double.Parse(payPalFee);
                    userToUpdate.PayPalMisc = "PayerID="+payerID;
                }
                var updateUserResult = UserManager.Update(userToUpdate);
           
            }
            else
            {
                //payment has not been successful - don't send goods!
            }

            PaypalPaymentModel oThankyouModel = new PaypalPaymentModel();
            oThankyouModel.AmountPaid = userToUpdate.PayPalAmount.ToString();
            oThankyouModel.TxnString = userToUpdate.RegisterPayPalTxnID;


            return View(oThankyouModel);
        }