Ejemplo n.º 1
0
        public string GetBalanceCode()
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";
            encoder["METHOD"] =  "GetBalance";
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
Ejemplo n.º 2
0
        public string GetBalanceCode()
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */
            profile.APIUsername  = "******";
            profile.APIPassword  = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment  = "sandbox";
            caller.APIProfile    = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "51.0";
            encoder["METHOD"]  = "GetBalance";
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);
            return(decoder["ACK"]);
        }
Ejemplo n.º 3
0
        public string GetTransactionDetailsCode(string transactionID)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";
            encoder["METHOD"] =  "GetTransactionDetails";

            // Add request-specific fields to the request.
            encoder["TRANSACTIONID"] =  transactionID;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Call this method to complete payment.
    /// </summary>
    /// <param name="finalPaymentAmount"></param>
    /// <param name="token"></param>
    /// <param name="PayerID"></param>
    /// <param name="decoder"></param>
    /// <param name="retMsg"></param>
    /// <returns></returns>
    public bool DoCheckoutPayment(string finalPaymentAmount, string token, ref NVPCodec decoder)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }

        NVPCodec encoder = new NVPCodec();

        encoder[NVPProperties.Properties.METHOD]             = NVPProperties.Methods.ProcessPayment;
        encoder[NVPProperties.Properties.TOKEN]              = token;
        encoder[NVPProperties.Properties.PAYMENTREQUEST_AMT] = finalPaymentAmount;

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

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

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

        if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 5
0
    public bool GetCheckoutDetails(string token, ref string PayerID, ref NVPCodec decoder, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }

        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"))
        {
            PayerID = decoder["PAYERID"];
            return(true);
        }
        else
        {
            retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                     "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                     "Desc2=" + decoder["L_LONGMESSAGE0"];

            return(false);
        }
    }
Ejemplo n.º 6
0
        public PayPalResponse ECGetExpressCheckout(string token)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = getProfile();
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] = "84.0";
            encoder["METHOD"] = "GetExpressCheckoutDetails";

            // Add request-specific fields to the request.
            encoder["TOKEN"] = token; // Pass the token returned in SetExpressCheckout.

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            PayPalResponse response = new PayPalResponse {
                token = (decoder["TOKEN"] != null) ? decoder["TOKEN"] : "",
                acknowledgement = decoder["ACK"],
                first = decoder["FIRSTNAME"],
                last = decoder["LASTNAME"],
                email = decoder["EMAIL"],
                amount = decoder["PAYMENTREQUEST_0_AMT"],
                payerID = decoder["PAYERID"]
            };
            return response;
        }
Ejemplo n.º 7
0
    public bool DoCheckoutPayment(string finalPaymentAmount, string token, string PayerID, ref NVPCodec decoder, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }

        NVPCodec encoder = new NVPCodec();
        encoder["METHOD"] = "DoExpressCheckoutPayment";
        encoder["TOKEN"] = token;
        encoder["PAYERID"] = PayerID;
        encoder["PAYMENTREQUEST_0_AMT"] = finalPaymentAmount;
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";

        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;
        }
    }
        public string ECSetExpressCheckout_PayLaterCode(string returnURL,string cancelURL,string amount,string paymentType,string currencyCode)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";
            encoder["METHOD"] =  "SetExpressCheckout";
            encoder["RETURNURL"] =  returnURL;
            encoder["CANCELURL"] =  cancelURL;
            encoder["AMT"] =  amount;
            encoder["PAYMENTACTION"] =  paymentType;
            encoder["CURRENCYCODE"] =  currencyCode;
            encoder["L_PROMOCODE0"] = "101";
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
Ejemplo n.º 9
0
    public bool DoCheckoutPayment(string finalPaymentAmount, string token, string
                                  PayerID, ref NVPCodec decoder, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }
        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]  = "DoExpressCheckoutPayment";
        encoder["TOKEN"]   = token;
        encoder["PAYERID"] = PayerID;
        encoder["PAYMENTREQUEST_0_AMT"]           = finalPaymentAmount;
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "USD";
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        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.º 10
0
        /// <summary>
        /// Refunds the payment from the payment provider. This is often used when you need to call external services to handle the refund process.
        /// </summary>
        /// <remarks>
        /// Docs at https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/RefundTransaction_API_Operation_NVP/
        /// </remarks>
        /// <param name="payment">The payment.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        protected override bool RefundPaymentInternal(Payment payment, out string status)
        {
            var caller = GetPayPalNVPCaller(payment.PaymentMethod);

            var postCodec = new NVPCodec();

            postCodec["VERSION"]       = "51.0";
            postCodec["METHOD"]        = "RefundTransaction";
            postCodec["TRANSACTIONID"] = payment.TransactionId;
            postCodec["REFUNDTYPE"]    = "Full";

            // Execute the API operation and obtain the response.
            string postString     = postCodec.Encode();
            string responseString = caller.Call(postString);

            var responseCodec = new NVPCodec();

            responseCodec.Decode(responseString);

            status = GetCodecStatus(responseCodec);
            bool callStatus = GetCallStatus(responseCodec);

            if (callStatus)
            {
                status = PaymentMessages.RefundSuccess + " >> " + status;
            }
            else
            {
                status = PaymentMessages.RefundFailed + " >> " + status;
            }

            return(callStatus);
        }
Ejemplo n.º 11
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 netamt, string vatamt, string grossamt, string currencycode, ref string token, ref string retMsg, ref NVPCodec retdecoder, ref string payerid)
    {
        string host = "www.paypal.com";

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

        string returnURL = ConfigurationManager.AppSettings["ReturnURL"].ToString();
        string cancelURL = ConfigurationManager.AppSettings["CancelURL"].ToString();

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]        = "SetExpressCheckout";
        encoder["RETURNURL"]     = returnURL;
        encoder["CANCELURL"]     = cancelURL;
        encoder["AMT"]           = grossamt;
        encoder["PAYMENTACTION"] = "Sale";
        encoder["CURRENCYCODE"]  = currencycode;
        encoder["L_NAME0"]       = "GSE-Mart.aero Advert Payment ";
        encoder["L_AMT0"]        = netamt;
        encoder["ITEMAMT"]       = netamt;
        encoder["TAXAMT"]        = vatamt;

        //// Jim. Try explicitly putting these in!
        //encoder["USER"] = APIUsername;
        //encoder["PWD"] = APIPassword;
        //encoder["SIGNATURE"] = APISignature;

        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"];

            // useraction = commit makes the user commit to the transaction in PayPal
            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);
        }
    }
Ejemplo n.º 12
0
    public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host         = host_SB;
        }

        string returnURL = "http://localhost:2911/Checkout/CheckoutReview.aspx";
        string cancelURL = "http://localhost:2911/Checkout/CheckoutCancel.aspx";

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]                         = "SetExpressCheckout";
        encoder["RETURNURL"]                      = returnURL;
        encoder["CANCELURL"]                      = cancelURL;
        encoder["BRANDNAME"]                      = "BoozeSoothe Sample Application";
        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "USD";

        // Get the Shopping Cart Products
        using (BoozeSoothe.Logic.ShoppingCartActions myCartOrders = new BoozeSoothe.Logic.ShoppingCartActions())
        {
            List <CartItem> myOrderList = myCartOrders.GetCartItems();

            for (int i = 0; i < myOrderList.Count; i++)
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Product.ProductName.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + i]  = myOrderList[i].Product.UnitPrice.ToString();
                encoder["L_PAYMENTREQUEST_0_QTY" + i]  = myOrderList[i].Quantity.ToString();
            }
        }

        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.º 13
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, string itemName, string qty, string itemAmount, ref string token, ref string retMsg)
    {
        string host = "www.paypal.com";

        bool bSandbox = bool.Parse(ConfigurationManager.AppSettings["Sandbox"]);

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

        string returnURL = ConfigurationManager.AppSettings["returnURL"];
        string cancelURL = ConfigurationManager.AppSettings["cancelURL"];
        string currency  = ConfigurationManager.AppSettings["currency"];

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]    = "SetExpressCheckout";
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = currency;

        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";

        encoder["L_PAYMENTREQUEST_0_NAME0"] = itemName;
        encoder["L_PAYMENTREQUEST_0_QTY0"]  = qty;
        encoder["L_PAYMENTREQUEST_0_AMT0"]  = itemAmount;


        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.º 14
0
    /// <summary>
    /// ShortcutExpressCheckout: The shortcut implementation of SetExpressCheckout
    /// </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)
    {
        string host = "www.paypal.com";

        if (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
            host         = "www.sandbox.paypal.com";
        }

        string returnURL = "Shipping.aspx";
        string cancelURL = "Order.aspx";

        NVPCodec encoder = new NVPCodec();

        encoder["TENDER"] = "P";
        encoder["ACTION"] = "S";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else         /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["AMT"]       = amt;
        encoder["CURRENCY"]  = "USD";

        // unique request ID
        System.Guid uid = System.Guid.NewGuid();

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp    = HttpCall(pStrrequestforNvp, uid.ToString());

        NVPCodec decoder = new NVPCodec();

        decoder.Decode(pStresponsenvp);

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

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

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

            retMsg = ECURL;
            return(true);
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                     "Desc=" + decoder["RESPMSG"];

            return(false);
        }
    }
        public NVPCodec ECDoExpressCheckoutCode(string token, string payerID, string amount, string paymentType, string currencyCode)
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            if (System.Configuration.ConfigurationManager.AppSettings["ENVIRONMENT"].ToString() == "T")
            {
                profile.APIUsername  = "******";
                profile.APIPassword  = "******";
                profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
                profile.Environment  = "sandbox";
            }
            else if (System.Configuration.ConfigurationManager.AppSettings["ENVIRONMENT"].ToString() == "L")
            {
                profile.APIUsername  = "******";
                profile.APIPassword  = "******";
                profile.APISignature = "AFcWxV21C7fd0v3bYYYRCpSSRl31Ab5GxWPc-1XSb8rJctwNCFHIYb84";
                profile.Environment  = "live";
            }
            else
            {
                profile.APIUsername  = "******";
                profile.APIPassword  = "******";
                profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
                profile.Environment  = "sandbox";
            }
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "65.1";
            encoder["METHOD"]  = "DoExpressCheckoutPayment";

            // Add request-specific fields to the request.
            // Pass the token returned in SetExpressCheckout.
            encoder["TOKEN"]         = token;
            encoder["PAYERID"]       = payerID;
            encoder["AMT"]           = amount;
            encoder["PAYMENTACTION"] = paymentType;
            encoder["CURRENCYCODE"]  = currencyCode;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);
            return(decoder);
        }
Ejemplo n.º 16
0
    /// <summary>
    /// ConfirmPayment: The method that calls DoExpressCheckoutPayment, 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 (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
        }

        NVPCodec encoder = new NVPCodec();

        encoder["TOKEN"]  = token;
        encoder["TENDER"] = "P";
        encoder["ACTION"] = "D";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else         /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["PAYERID"]  = PayerId;
        encoder["AMT"]      = finalPaymentAmount;
        encoder["CURRENCY"] = "USD";

        // unique request ID
        string unique_id;

        if (HttpContext.Current.Session["unique_id"] == null)
        {
            System.Guid uid = System.Guid.NewGuid();
            unique_id = uid.ToString();
            HttpContext.Current.Session["unique_id"] = unique_id;
        }
        else
        {
            unique_id = (string)HttpContext.Current.Session["unique_id"];
        }

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

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

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

        if (strAck != null && strAck == "0")
        {
            return(true);
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                     "Desc=" + decoder["RESPMSG"];

            return(false);
        }
    }
Ejemplo n.º 17
0
        public string MassPayCode(string emailSubject, string receiverType, string currencyCode, string ReceiverEmail0, string amount0, string UniqueID0, string Note0, string ReceiverEmail1, string amount1, string UniqueID1, string Note1)
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername  = "******";
            profile.APIPassword  = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment  = "sandbox";
            caller.APIProfile    = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "51.0";
            encoder["METHOD"]  = "MassPay";

            // Add request-specific fields to the request.
            encoder["EMAILSUBJECT"] = emailSubject;
            encoder["RECEIVERTYPE"] = receiverType;
            encoder["CURRENCYCODE"] = currencyCode;

            if (ReceiverEmail0.Length > 0)
            {
                encoder["L_EMAIL0"]    = ReceiverEmail0;
                encoder["L_Amt0"]      = amount0;
                encoder["L_UNIQUEID0"] = UniqueID0;
                encoder["L_NOTE0"]     = Note0;
            }

            if (ReceiverEmail1.Length > 0)
            {
                encoder["L_EMAIL1"]    = ReceiverEmail1;
                encoder["L_Amt1"]      = amount1;
                encoder["L_UNIQUEID1"] = UniqueID1;
                encoder["L_NOTE1"]     = Note1;
            }



            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);
            return(decoder["ACK"]);
        }
Ejemplo n.º 18
0
    /// <summary>
    /// DirectPayment: The method for credit card payment
    /// </summary>
    /// Note:
    ///	There are other optional inputs for credit card processing that are not presented here.
    ///		For a complete list of inputs available, please see the documentation here for US and UK:
    ///		http://www.paypal.com/en_US/pdf/PayflowPro_Guide.pdf
    ///		https://www.paypal.com/en_GB/pdf/PP_WebsitePaymentsPro_IntegrationGuide.pdf
    /// <param name="amt"></param>
    /// <param ref name="token"></param>
    /// <param ref name="retMsg"></param>
    /// <returns></returns>
    public bool DirectPayment(string paymentType, string paymentAmount, string creditCardType, string creditCardNumber, string expDate, string cvv2, string firstName, string lastName, string street, string city, string state, string zip, string countryCode, string currencyCode, string orderdescription, ref NVPCodec decoder, ref string retMsg)
    {
        if (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
        }

        NVPCodec encoder = new NVPCodec();

        encoder["TENDER"] = "C";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else         /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["ACCT"]      = creditCardNumber;
        encoder["CVV2"]      = cvv2;
        encoder["EXPDATE"]   = expDate;
        encoder["ACCTTYPE"]  = creditCardType;
        encoder["AMT"]       = paymentAmount;
        encoder["CURRENCY"]  = currencyCode;
        encoder["FIRSTNAME"] = firstName;
        encoder["LASTNAME"]  = lastName;
        encoder["STREET"]    = street;
        encoder["CITY"]      = city;
        encoder["STATE"]     = state;
        encoder["ZIP"]       = zip;
        encoder["COUNTRY"]   = countryCode;
        // unique request ID
        System.Guid uid = System.Guid.NewGuid();
        encoder["INVNUM"]    = uid.ToString();
        encoder["ORDERDESC"] = orderdescription;
        encoder["VERBOSITY"] = "MEDIUM";

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp    = HttpCall(pStrrequestforNvp, uid.ToString());

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

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

        if (strAck != null && strAck == "0")
        {
            return(true);
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                     "Desc=" + decoder["RESPMSG"];

            return(false);
        }
    }
Ejemplo n.º 19
0
    public bool ShortcutExpressCheckout(string subTotal, string shippingIn, string amt, ref string token, ref string retMsg, Customer customerIn)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host         = host_SB;
        }

        string returnURL = "http://localhost:64352/Graded%20Unit1/CheckoutReview.aspx";
        string cancelURL = "http://localhost:64352/Graded%20Unit1/CheckoutCancel.aspx";

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]                         = "SetExpressCheckout";
        encoder["RETURNURL"]                      = returnURL;
        encoder["CANCELURL"]                      = cancelURL;
        encoder["BRANDNAME"]                      = "LidiFlu Ltd";
        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = subTotal;
        encoder["PAYMENTREQUEST_0_SHIPPINGAMT"]   = shippingIn;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "GBP";

        // Get the Shopping Cart Products


        for (int i = 0; i < customerIn.Orders[0].OrderLines.Count; i++)
        {
            encoder["L_PAYMENTREQUEST_0_NAME" + i] = customerIn.Orders[0].OrderLines[i].Product.ProdName.ToString();
            encoder["L_PAYMENTREQUEST_0_AMT" + i]  = customerIn.Orders[0].OrderLines[i].Product.ProdPrice.ToString();
            encoder["L_PAYMENTREQUEST_0_QTY" + i]  = customerIn.Orders[0].OrderLines[i].Quantity.ToString();
        }

        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.º 20
0
        public Hashtable DoDirectPaymentCode()
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername  = Constants.PayPal_Username;       //"sdk-three_api1.sdk.com";
            profile.APIPassword  = Constants.PayPal_Password;       //"QFZCWN5HZM8VBG7Q";
            profile.APISignature = Constants.PayPal_Signature;      //"AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment  = Constants.PayPal_PaymentAccount; //"live";// "sandbox";
            caller.APIProfile    = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "51.0";
            encoder["METHOD"]  = "DoDirectPayment";

            // Add request-specific fields to the request.
            encoder["PAYMENTACTION"]  = "Sale"; //paymentAction;
            encoder["AMT"]            = fPaymentOrderTotal.ToString();
            encoder["CREDITCARDTYPE"] = (sCCType.Equals(CreditCardType.AmericanExpress)) ? "Amex" : sCCType.ToString();
            encoder["ACCT"]           = CCNumber;
            encoder["EXPDATE"]        = sCCExpDate;
            encoder["CVV2"]           = sCCVerificationCode;
            encoder["FIRSTNAME"]      = sCCOwnerFirstName;
            encoder["LASTNAME"]       = sCCOwnerLastName;
            encoder["STREET"]         = (sCCOwnerStreet2.Trim().Length > 0) ? string.Concat(sCCOwnerStreet1, ", ", sCCOwnerStreet2) : sCCOwnerStreet1;
            encoder["CITY"]           = sCCOwnerCityName;
            encoder["STATE"]          = sCCOwnerStateOrProvince;
            encoder["ZIP"]            = sCCOwnerPostalCode;
            encoder["COUNTRYCODE"]    = sCCOwnerCountryCode;
            encoder["CURRENCYCODE"]   = "USD";

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);

            Hashtable htResult = new Hashtable();

            foreach (string st in decoder.AllKeys)
            {
                htResult.Add(st, decoder[st]);
            }
            return(htResult);
        }
Ejemplo n.º 21
0
    public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host         = host_SB;
        }

        string returnURL = "http://localhost:51341/Checkout/CheckoutReview.aspx";
        string cancelURL = "http://localhost:51341/Checkout/CheckoutCancel.aspx";

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]                         = "SetExpressCheckout";
        encoder["RETURNURL"]                      = returnURL;
        encoder["CANCELURL"]                      = cancelURL;
        encoder["BRANDNAME"]                      = "Go Events Ticket System";
        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "USD";

        List <CartItem> myOrderList = (List <CartItem>)Session["CartItems"];

        encoder["L_PAYMENTREQUEST_0_NAME"] = myOrderList[0].EventName.ToString();
        encoder["L_PAYMENTREQUEST_0_QTY"]  = myOrderList.Count.ToString();

        for (int i = 0; i < myOrderList.Count; i++)
        {
            encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Price.ToString();
        }

        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.º 22
0
    /// <summary>
    /// GetShippingDetails: The method that calls GetExpressCheckoutDetails
    /// </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 (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
        }

        NVPCodec encoder = new NVPCodec();

        encoder["TOKEN"]  = token;
        encoder["TENDER"] = "P";
        encoder["ACTION"] = "G";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else         /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }

        // unique request ID
        System.Guid uid = System.Guid.NewGuid();

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp    = HttpCall(pStrrequestforNvp, uid.ToString());

        NVPCodec decoder = new NVPCodec();

        decoder.Decode(pStresponsenvp);

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

        if (strAck != null && strAck == "0")
        {
            ShippingAddress  = "<table><tr>";
            ShippingAddress += "<td colspan='2'> Shipping Address</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=" + strAck + "&" +
                     "Desc=" + decoder["RESPMSG"];

            return(false);
        }
    }
Ejemplo n.º 23
0
        public async Task Validate_TestStartCalled_ISmokeTestProviderRegistered_Returns_NvpCodecValues()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/Start/";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();
            IServiceCollection   serviceCollection    = new ServiceCollection() as IServiceCollection;
            NVPCodec             codecValues          = new NVPCodec();

            codecValues.Add("username", "admin");
            MockSmokeTestProvider smokeTestProvider = new MockSmokeTestProvider(codecValues);

            serviceCollection.AddSingleton <ISmokeTestProvider>(smokeTestProvider);

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse,
                                                              serviceCollection.BuildServiceProvider());
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.IsFalse(nextDelegateCalled);
                Assert.AreEqual(200, httpResponse.StatusCode);
                Assert.IsNull(httpResponse.ContentType);
                Assert.IsTrue(smokeTestProvider.StartCalled);

                byte[] data = new byte[httpResponse.Body.Length];
                httpResponse.Body.Position = 0;
                httpResponse.Body.Read(data, 0, data.Length);
                string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey);

                Assert.IsFalse(String.IsNullOrEmpty(test));
                NVPCodec codec = new NVPCodec();
                codec.Decode(test);

                Assert.AreEqual(1, codec.AllKeys.Length);

                Assert.IsTrue(codec.AllKeys.Contains("username"));
                Assert.AreEqual("admin", codec["username"]);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <param name="nvp"></param>
        /// <returns></returns>
        private NVPCodec SendExpressCheckoutCommand(NVPCodec nvp)
        {
            NVPCallerServices service = InitializeServices();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            string   response    = service.Call(nvp.Encode());
            NVPCodec responsenvp = new NVPCodec();

            responsenvp.Decode(response);
            return(responsenvp);
        }
Ejemplo n.º 25
0
        public string MassPayCode(string emailSubject,string receiverType,string currencyCode,string ReceiverEmail0,string amount0,string UniqueID0,string Note0,string ReceiverEmail1,string amount1,string UniqueID1,string Note1)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";
            encoder["METHOD"] =  "MassPay";

            // Add request-specific fields to the request.
            encoder["EMAILSUBJECT"] =  emailSubject;
            encoder["RECEIVERTYPE"] =  receiverType;
            encoder["CURRENCYCODE"]=currencyCode;

            if(ReceiverEmail0.Length>0)
            {
                encoder["L_EMAIL0"] =  ReceiverEmail0;
                encoder["L_Amt0"] =  amount0;
                encoder["L_UNIQUEID0"] =  UniqueID0;
                encoder["L_NOTE0"] =  Note0;
            }

            if(ReceiverEmail1.Length>0)
            {
                encoder["L_EMAIL1"] =  ReceiverEmail1;
                encoder["L_Amt1"] =  amount1;
                encoder["L_UNIQUEID1"] =  UniqueID1;
                encoder["L_NOTE1"] =  Note1;
            }

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
        public NVPCodec ECGetExpressCheckoutCode(string token)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            if (System.Configuration.ConfigurationManager.AppSettings["ENVIRONMENT"].ToString() == "T")
            {
                profile.APIUsername = "******";
                profile.APIPassword = "******";
                profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
                profile.Environment = "sandbox";
            }
            else if (System.Configuration.ConfigurationManager.AppSettings["ENVIRONMENT"].ToString() == "L")
            {
                profile.APIUsername = "******";
                profile.APIPassword = "******";
                profile.APISignature = "AFcWxV21C7fd0v3bYYYRCpSSRl31Ab5GxWPc-1XSb8rJctwNCFHIYb84";
                profile.Environment = "live";
            }
            else
            {
                profile.APIUsername = "******";
                profile.APIPassword = "******";
                profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
                profile.Environment = "sandbox";
            }
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "65.1";
            encoder["METHOD"] =  "GetExpressCheckoutDetails";

            // Add request-specific fields to the request.
            encoder["TOKEN"] =  token; // Pass the token returned in SetExpressCheckout.

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder;
        }
Ejemplo n.º 27
0
    public bool ShortcutExpressCheckout(string amt, string currency_code, string brandname, string itemname, string email, ref string token, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host         = host_SB;
        }

        string returnURL = AppSettings.PayPalreturnURL;
        string cancelURL = AppSettings.PayPalcancelURL;

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]                         = "SetExpressCheckout";
        encoder["RETURNURL"]                      = returnURL;
        encoder["CANCELURL"]                      = cancelURL;
        encoder["BRANDNAME"]                      = brandname;
        encoder["EMAIL"]                          = email;
        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = currency_code;

        encoder["L_PAYMENTREQUEST_0_NAME0"] = itemname;
        encoder["L_PAYMENTREQUEST_0_AMT0"]  = amt;
        encoder["L_PAYMENTREQUEST_0_QTY0"]  = "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.º 28
0
        public string DoDirectPaymentCode(string paymentAction, string amount, string creditCardType, string creditCardNumber, string expdate_month, string cvv2Number, string firstName, string lastName, string address1, string city, string state, string zip, string countryCode, string currencyCode)
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername  = "******";                //"sdk-three_api1.sdk.com";
            profile.APIPassword  = "******";                                               //"QFZCWN5HZM8VBG7Q";
            profile.APISignature = "Aodyho-T1mAnue23UgKnw1JPD8E9AnPQgwCa26tyq818j5Kv.mh7AdxZ"; //"AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment  = "sandbox";
            caller.APIProfile    = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "51.0";
            encoder["METHOD"]  = "DoDirectPayment";

            // Add request-specific fields to the request.
            encoder["PAYMENTACTION"]  = paymentAction;
            encoder["AMT"]            = amount;
            encoder["CREDITCARDTYPE"] = creditCardType;
            encoder["ACCT"]           = creditCardNumber;
            encoder["EXPDATE"]        = expdate_month;
            encoder["CVV2"]           = cvv2Number;
            encoder["FIRSTNAME"]      = firstName;
            encoder["LASTNAME"]       = lastName;
            encoder["STREET"]         = address1;
            encoder["CITY"]           = city;
            encoder["STATE"]          = state;
            encoder["ZIP"]            = zip;
            encoder["COUNTRYCODE"]    = countryCode;
            encoder["CURRENCYCODE"]   = currencyCode;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);
            return(decoder["ACK"]);
        }
Ejemplo n.º 29
0
    public bool ShortcutExpressCheckout(string amt, string planName, ref string token, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host         = host_SB;
        }

        string returnURL = "https://localhost:44352/Checkout/Checkout-Review";
        string cancelURL = "https://localhost:44352/Checkout/Checkout-Cancel";

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]                         = "SetExpressCheckout";
        encoder["RETURNURL"]                      = returnURL;
        encoder["CANCELURL"]                      = cancelURL;
        encoder["BRANDNAME"]                      = "DIYPT";
        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "AUD";
        encoder["L_PAYMENTREQUEST_0_NAME" + 0]    = planName;
        encoder["L_PAYMENTREQUEST_0_AMT" + 0]     = amt;
        encoder["L_PAYMENTREQUEST_0_QTY" + 0]     = "" + 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.º 30
0
        public bool DoGroupPaymentSuccess(decimal vCreditTotal)
        {
            bool success = false;

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"]         = "DoDirectPayment";
            encoder["PAYMENTACTION"]  = "Sale";
            encoder["IPADDRESS"]      = Helper.CurrentUserIP;
            encoder["AMT"]            = Helper.FormatPriceToPayPalStringFormat(vCreditTotal);
            encoder["CREDITCARDTYPE"] = CreditCardTypeRepository.GetCreditCardTypeById(base.CurrentCreditCard.CreditCardTypeId).Title;
            encoder["ACCT"]           = base.CurrentCreditCard.CreditCardNumber;
            encoder["EXPDATE"]        = base.CurrentCreditCard.ExpirationMonth.ToString() + base.CurrentCreditCard.ExpirationYear.ToString();
            encoder["CVV2"]           = base.CurrentCreditCard.SecurityCode.ToString();
            encoder["FIRSTNAME"]      = base.CurrentCreditCard.FirstName;
            encoder["LASTNAME"]       = base.CurrentCreditCard.LastName;

            /*
             * encoder["STREET"] = base.CurrentCreditCard.AddressLine;
             * encoder["CITY"] = base.CurrentCreditCard.City;
             * encoder["STATE"] = base.CurrentCreditCard.State;
             * encoder["ZIP"] = base.CurrentCreditCard.ZipCode;
             * encoder["COUNTRYCODE"] = "US";
             */
            encoder["CURRENCYCODE"] = "USD";

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);

            string strAck = decoder["ACK"];

            if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning"))
            {
                Session["result"] = decoder;
                // string pStrResQue = "API=" + "DoDirect Payment ";
                success = true;
            }
            else
            {
                Session["errorresult"] = decoder;
            }
            return(success);
        }
Ejemplo n.º 31
0
        public string ECDoExpressCheckout(string token, string payerID, string amount, Cart cart)
        {
            Settings settings = new Settings();
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = getProfile();
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder.Add("VERSION","84.0");
            encoder.Add("METHOD","DoExpressCheckoutPayment");

            // Add request-specific fields to the request.
            encoder.Add("TOKEN",token);
            encoder.Add("PAYERID",payerID);
            encoder.Add("RETURNURL",getSiteURL() + "Payment/PayPalCheckout");
            encoder.Add("CANCELURL",getSiteURL() + "Payment");
            encoder.Add("PAYMENTREQUEST_0_AMT",amount);
            encoder.Add("PAYMENTREQUEST_0_PAYMENTACTION","Sale");
            encoder.Add("PAYMENTREQUEST_0_CURRENCYCODE","USD");
            encoder.Add("BRANDNAME",settings.Get("SiteName"));
            encoder.Add("LOGIN","Login");
            encoder.Add("HDRIMG",settings.Get("EmailLogo"));
            encoder.Add("CUSTOMERSERVICENUMBER",settings.Get("PhoneNumber"));
            encoder.Add("PAYMENTREQUEST_0_SHIPPINGAMT",cart.shipping_price.ToString());
            encoder.Add("PAYMENTREQUEST_0_DESC","Your " + settings.Get("SiteName") + " Order");
            encoder.Add("ALLOWNOTE","0");
            encoder.Add("NOSHIPPING","1");
            int count = 0;
            decimal total = 0;
            foreach (CartItem item in cart.CartItems) {
                encoder.Add("L_PAYMENTREQUEST_0_NUMBER" + count, item.partID.ToString());
                encoder.Add("L_PAYMENTREQUEST_0_NAME" + count, item.shortDesc);
                encoder.Add("L_PAYMENTREQUEST_0_AMT" + count, String.Format("{0:N2}", item.price));
                encoder.Add("L_PAYMENTREQUEST_0_QTY" + count, item.quantity.ToString());
                encoder.Add("L_PAYMENTREQUEST_0_ITEMCATEGORY" + count, "Physical");
                encoder.Add("L_PAYMENTREQUEST_0_ITEMURL" + count, settings.Get("SiteURL") + "part/" + item.partID);
                total += item.price * item.quantity;
                count++;
            }
            encoder.Add("PAYMENTREQUEST_0_TAXAMT", String.Format("{0:N2}", cart.tax));
            encoder.Add("PAYMENTREQUEST_0_ITEMAMT", String.Format("{0:N2}", total));
            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
Ejemplo n.º 32
0
        private string SetExpressCheckout(tbl_Orders order, string payPalReturnUrl, string payPalCancelUrl, string payPalUser, string payPalPassword, string payPalSignature, string payPalCurrencyCode, string payPalNvpSetExpressUrl, string payPalHost, string invoiceID, string languageCode)
        {
            string resultToLog;

            NVPCodec encoder = InitializeEncoder(order);

            encoder[PayPalConsts.Method]       = "SetExpressCheckout";
            encoder[PayPalConsts.NoShipping]   = "1";
            encoder[PayPalConsts.ReturnUrl]    = payPalReturnUrl;
            encoder[PayPalConsts.CancelUrl]    = payPalCancelUrl;
            encoder[PayPalConsts.User]         = payPalUser;
            encoder[PayPalConsts.Pwd]          = payPalPassword;
            encoder[PayPalConsts.Signature]    = payPalSignature;
            encoder[PayPalConsts.CurrencyCode] = payPalCurrencyCode;
            encoder[PayPalConsts.InvoiceID]    = invoiceID;

            if (!string.IsNullOrEmpty(languageCode))
            {
                encoder[PayPalConsts.LocaleCode] = languageCode;
            }

            string settings = encoder.GetSettings();

            Log.Info(settings);

            string encoded = encoder.Encode();
            string result  = resultToLog = HttpPost(payPalNvpSetExpressUrl, encoded, 30000);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(result);

            string token = decoder[PayPalConsts.Token];

            if (decoder[PayPalConsts.ACK].ToLower() == "success" || decoder[PayPalConsts.ACK].ToLower() == "successwithwarning")
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_SetExpressCheckout_Success);
                ECommerceService.UpdateOrderSecurityKey(token, order.OrderID);
                return(String.Format("{0}?cmd=_express-checkout&{1}={2}&{3}={4}", payPalHost, PayPalConsts.Token.ToLower(), token, PayPalConsts.Useraction, PayPalConsts.Commit));
            }
            else
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_SetExpressCheckout_Failure);
                resultToLog = Server.UrlDecode(resultToLog).Replace("&", Environment.NewLine);
                Log.Error(String.Format("PayPal payment - SetExpressCheckout failed: {0}", resultToLog));
            }

            return(String.Empty);
        }
Ejemplo n.º 33
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)
    {
        string host = "www.paypal.com";

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

        string returnURL = "http://localhost:50386/MICsGroup/donation_confirmation.aspx";
        string cancelURL = "http://localhost:50386/MICsGroup/donation.aspx";

        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";

        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.º 34
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)
    {
        bool bSandbox = bool.Parse(ConfigurationManager.AppSettings["Sandbox"]);

        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>";

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

            return(false);
        }
    }
Ejemplo n.º 35
0
        public string DoDirectPaymentCode(string paymentAction,string amount,string creditCardType,string creditCardNumber,string expdate_month,string cvv2Number,string firstName,string lastName,string address1,string city,string state,string zip,string countryCode,string currencyCode)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";
            encoder["METHOD"] =  "DoDirectPayment";

            // Add request-specific fields to the request.
            encoder["PAYMENTACTION"] =  paymentAction;
            encoder["AMT"] =  amount;
            encoder["CREDITCARDTYPE"] =  creditCardType;
            encoder["ACCT"] =  creditCardNumber;
            encoder["EXPDATE"] =  expdate_month;
            encoder["CVV2"] =  cvv2Number;
            encoder["FIRSTNAME"] =  firstName;
            encoder["LASTNAME"] =  lastName;
            encoder["STREET"] =  address1;
            encoder["CITY"] =  city;
            encoder["STATE"] =  state;
            encoder["ZIP"] =  zip;
            encoder["COUNTRYCODE"] = countryCode;
            encoder["CURRENCYCODE"] =  currencyCode;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
        public ICreditCardAuthorizationResponse VerifyCreditCardInfo(ICreditCardAuthorizationRequest request)
        {
            var caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AzbQABSL2jEPPHG.eDus2jfMT0xEAUITxvhhUWGmd3DHxaPXx6Zs1MPR";
            profile.Environment = "sandbox";
            caller.APIProfile = profile;

            var encoder = new NVPCodec();

            encoder["SIGNATURE"] = "AzbQABSL2jEPPHG.eDus2jfMT0xEAUITxvhhUWGmd3DHxaPXx6Zs1MPR";
            encoder["USER"] = "******";
            encoder["PWD"] = "1302977698";
            encoder["VERSION"] = "60.0";
            encoder["METHOD"] = "DoDirectPayment";

            // Add request-specific fields to the request.
            encoder["PAYMENTACTION"] = CreditCardPaymentActions.Authorization.ToString();
            encoder["AMT"] = "100";
            encoder["CREDITCARDTYPE"] = request.CreditCardInfo.Type.ToString();
            encoder["IPADDRESS"] = "192.168.0.1";
            encoder["ACCT"] = request.CreditCardInfo.CreditCardNumber;
            encoder["EXPDATE"] = request.CreditCardInfo.ExpirationDate.ToString("MMyyyy");
            encoder["CVV2"] = request.CreditCardInfo.Cvv2Number;
            encoder["FIRSTNAME"] = request.FirstName;
            encoder["LASTNAME"] = request.LastName;
            encoder["STREET"] = request.AddressInfo.Address1;
            encoder["CITY"] = request.AddressInfo.City;
            encoder["STATE"] = request.AddressInfo.State;
            encoder["ZIP"] = request.AddressInfo.ZipCode;
            encoder["COUNTRYCODE"] = request.AddressInfo.Country;
            encoder["CURRENCYCODE"] = "USD";

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp = caller.Call(pStrrequestforNvp);

            var decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return new CreditCardAuthorizationReponse(decoder["ACK"] == "Success");
        }
Ejemplo n.º 37
0
        public PayPalPaymentStatus DoExpressCheckoutPayment(tbl_Orders order, string token, string payerId, string payPalCurrencyCode, string payPalReturnUrl, string payPalCancelUrl, string payPalUser, string payPalPassword, string payPalSignature, string payPalNvpSetExpressUrl, string invoiceID)
        {
            string resultToLog;

            NVPCodec encoder = InitializeEncoder(order);

            encoder[PayPalConsts.Method]        = "DoExpressCheckoutPayment";
            encoder[PayPalConsts.Token]         = token;
            encoder[PayPalConsts.PaymentAction] = "Sale";
            encoder[PayPalConsts.PayerId]       = payerId;
            encoder[PayPalConsts.CurrencyCode]  = payPalCurrencyCode;
            encoder[PayPalConsts.ReturnUrl]     = payPalReturnUrl;
            encoder[PayPalConsts.CancelUrl]     = payPalCancelUrl;
            encoder[PayPalConsts.User]          = payPalUser;
            encoder[PayPalConsts.Pwd]           = payPalPassword;
            encoder[PayPalConsts.Signature]     = payPalSignature;
            encoder[PayPalConsts.InvoiceID]     = invoiceID;

            string encoded = encoder.Encode();
            string result  = resultToLog = HttpPost(payPalNvpSetExpressUrl, encoded, 30000);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(result);

            PayPalPaymentStatus payPalStatus = new PayPalPaymentStatus();

            payPalStatus.TransactionID = decoder[PayPalConsts.TransactionID];
            payPalStatus.Token         = decoder[PayPalConsts.Token];
            payPalStatus.ACK           = decoder[PayPalConsts.ACK];
            payPalStatus.PaymentStatus = decoder[PayPalConsts.PaymentStatus];
            payPalStatus.PendingReason = decoder[PayPalConsts.PendingReason];
            payPalStatus.ErrorCode     = decoder[PayPalConsts.ErrorCode];
            payPalStatus.ErrorMessage  = decoder[PayPalConsts.ErrorMessage];

            if (payPalStatus.ACK.ToLower() != "success")
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_DoExpressCheckout_Failure);
                resultToLog = Server.UrlDecode(resultToLog).Replace("&", Environment.NewLine);
                Log.Error(String.Format("PayPal payment - DoExpressCheckoutPayment failed: {0}", resultToLog));
            }

            return(payPalStatus);
        }
Ejemplo n.º 38
0
        public string RefundTransactionCode(String refundType, String transactionId, String amount, String note, String currencyCode)
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername  = "******";
            profile.APIPassword  = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment  = "sandbox";
            caller.APIProfile    = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "51.0";
            encoder["METHOD"]  = "RefundTransaction";

            // Add request-specific fields to the request.
            encoder["TRANSACTIONID"] = transactionId;
            if (refundType != "Full")
            {
                encoder["AMT"]  = amount;
                encoder["NOTE"] = note;
            }
            encoder["REFUNDTYPE"] = refundType;


            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);
            return(decoder["ACK"]);
        }
Ejemplo n.º 39
0
        public string ECDoExpressCheckoutCode(string token, string payerID, string amount, string paymentType, string currencyCode)
        {
            NVPCallerServices caller  = new NVPCallerServices();
            IAPIProfile       profile = ProfileFactory.createSignatureAPIProfile();

            /*
             * WARNING: Do not embed plaintext credentials in your application code.
             * Doing so is insecure and against best practices.
             * Your API credentials must be handled securely. Please consider
             * encrypting them for use in any production environment, and ensure
             * that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername  = "******";
            profile.APIPassword  = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment  = "sandbox";
            caller.APIProfile    = profile;

            NVPCodec encoder = new NVPCodec();

            encoder["VERSION"] = "51.0";
            encoder["METHOD"]  = "DoExpressCheckoutPayment";

            // Add request-specific fields to the request.
            // Pass the token returned in SetExpressCheckout.
            encoder["TOKEN"]         = token;
            encoder["PAYERID"]       = payerID;
            encoder["AMT"]           = amount;
            encoder["PAYMENTACTION"] = paymentType;
            encoder["CURRENCYCODE"]  = currencyCode;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);
            return(decoder["ACK"]);
        }
Ejemplo n.º 40
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)
    {
        bool bSandbox = bool.Parse(ConfigurationManager.AppSettings["Sandbox"]);

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

        string currency = ConfigurationManager.AppSettings["currency"];

        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"] = 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);
        }
    }
        public string CreateRecurringPaymentsProfileCode(string token,string amount,string profileDate, string billingPeriod, string billingFrequency)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */
            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";

            // Add request-specific fields to the request.
            encoder["METHOD"] =  "CreateRecurringPaymentsProfile";
            encoder["TOKEN"] =  token;
            encoder["AMT"] =  amount;
            encoder["PROFILESTARTDATE"] =  profileDate;	//Date format from server expects Ex: 2006-9-6T0:0:0
            encoder["BILLINGPERIOD"] =  billingPeriod;
            encoder["BILLINGFREQUENCY"] =  billingFrequency;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
        public string SetCustomerBillingAgreementCode(string returnURL,string cancelURL,string billingDesc)
        {
            NVPCallerServices caller = new NVPCallerServices();
            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
            /*
             WARNING: Do not embed plaintext credentials in your application code.
             Doing so is insecure and against best practices.
             Your API credentials must be handled securely. Please consider
             encrypting them for use in any production environment, and ensure
             that only authorized individuals may view or modify them.
             */

            // Set up your API credentials, PayPal end point, API operation and version.
            profile.APIUsername = "******";
            profile.APIPassword = "******";
            profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ";
            profile.Environment="sandbox";
            caller.APIProfile = profile;

            NVPCodec encoder = new NVPCodec();
            encoder["VERSION"] =  "51.0";
            encoder["METHOD"] =  "SetCustomerBillingAgreement";

            // Add request-specific fields to the request.
            encoder["RETURNURL"] =  returnURL;
            encoder["CANCELURL"] =  cancelURL;
            encoder["BILLINGTYPE"] =  "RecurringPayments";
            encoder["BILLINGAGREEMENTDESCRIPTION"] =  billingDesc;

            // Execute the API operation and obtain the response.
            string pStrrequestforNvp= encoder.Encode();
            string pStresponsenvp=caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);
            return decoder["ACK"];
        }
Ejemplo n.º 43
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Read The IPN POST
                string strFormValues = Encoding.ASCII.GetString(Request.BinaryRead(Request.ContentLength));
                string strNewRequest;

                //Create IPN verification request
                HttpWebRequest req = WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr") as HttpWebRequest;

                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                strNewRequest = strFormValues + "&cmd=_notify-validate";
                req.ContentLength = strNewRequest.Length;

                StreamWriter swOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
                swOut.Write(strNewRequest);
                swOut.Close();

                HttpWebResponse httwebresponseResponse = req.GetResponse() as HttpWebResponse;
                Stream stIPNResponseStream = httwebresponseResponse.GetResponseStream();
                Encoding encEncode = System.Text.Encoding.GetEncoding("utf-8");
                StreamReader srStream = new StreamReader(stIPNResponseStream, encEncode);

                NVPCodec nvpResponse = new NVPCodec();
                //Getting Name Value Pairs Collection
                nvpResponse.Decode(strFormValues);

                string strIPNResponse = srStream.ReadToEnd();
                Label lblMessage = new Label();
                lblMessage.Text = strIPNResponse;
                Page.Form.Controls.Add(lblMessage);

                //Creating new database object
                MyTestDBEntities MyTestDB = new MyTestDBEntities();

                IPN_Main ipn_main = new IPN_Main() { IPN_Status = strIPNResponse, DateTimeStamp = DateTime.Now, RawString = strFormValues };
                MyTestDB.IPN_Main.AddObject(ipn_main);
                MyTestDB.SaveChanges();

                for (int intCounter = 0; intCounter < nvpResponse.Count; ++intCounter)
                {
                    IPN_Variables ipn_variables = new IPN_Variables() { IPN_ID = ipn_main.IPN_ID, Name = nvpResponse.GetKey(intCounter), Variable = nvpResponse.Get(intCounter) };
                    MyTestDB.IPN_Variables.AddObject(ipn_variables);
                    //Writing to debug stream for debugging pupose
                    string strTemp = nvpResponse.GetKey(intCounter) + nvpResponse.Get(intCounter) + Environment.NewLine;
                    Debug.Write(strTemp);
                }

                MyTestDB.SaveChanges();
                srStream.Close();
            }
            catch (Exception exErrors)
            {
                //generic exception handling: adding label on page with exception details
                Label lblErrorMessage = new Label();
                lblErrorMessage.Text = "Exception: " + exErrors.Message + "<br/>" + exErrors.ToString();
                form1.Controls.Add(lblErrorMessage);

                Debug.WriteLine("Exception: " + exErrors.Message + "\n\t" + exErrors.ToString());
            }
        }
Ejemplo n.º 44
0
    /// <summary>
    /// ConfirmPayment: The method that calls DoExpressCheckoutPayment, 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 (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
        }

        NVPCodec encoder = new NVPCodec();

        encoder["TOKEN"] = token;
        encoder["TENDER"] = "P";
        encoder["ACTION"] = "D";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["PAYERID"] = PayerId;
        encoder["AMT"] = finalPaymentAmount;

        // unique request ID
        string unique_id;

        if (HttpContext.Current.Session["unique_id"] == null)
        {
            System.Guid uid = System.Guid.NewGuid();
            unique_id = uid.ToString();
            HttpContext.Current.Session["unique_id"] = unique_id;
        }
        else
        {
            unique_id = (string)HttpContext.Current.Session["unique_id"];
        }

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

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

        string strAck = decoder["RESULT"].ToLower();
        if (strAck != null && strAck == "0")
        {
            return true;
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                "Desc=" + decoder["RESPMSG"];

            return false;
        }
    }
Ejemplo n.º 45
0
    /// <summary>
    /// ShortcutExpressCheckout: The shortcut implementation of SetExpressCheckout
    /// </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)
    {
        string host = "www.paypal.com";
        if (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
            host = "www.sandbox.paypal.com";
        }

        string returnURL = "http://www.careerjudge.com/FJAHome.aspx";
        string cancelURL = "https://www.novasoftindia.com";

        NVPCodec encoder = new NVPCodec();

        encoder["TENDER"] = "P";
        encoder["ACTION"] = "S";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["AMT"] = amt;
        encoder["CURRENCY"] = "USD";

        // unique request ID
        System.Guid uid = System.Guid.NewGuid();

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp = HttpCall(pStrrequestforNvp,uid.ToString());

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

        string strAck = decoder["RESULT"].ToLower();
        if (strAck != null && strAck == "0")
        {
            token = decoder["TOKEN"];

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

            retMsg = ECURL;
            return true;
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                "Desc=" + decoder["RESPMSG"];

            return false;
        }
    }
Ejemplo n.º 46
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"))
        {
            payerID = decoder["PAYERID"];

            ShippingAddress = "<table><tr>";
            ShippingAddress += "<td style='font-weight: bold'>Shipping Address</td></tr>";
            ShippingAddress += "<td><span id=\"spanShippingName\">" + decoder["SHIPTONAME"] + "</span></td></tr>";
            ShippingAddress += "<td><span id=\"spanShippingStreet1\">" + decoder["SHIPTOSTREET"] + "</span></td></tr>";
            ShippingAddress += "<td><span id=\"spanShippingStreet2\">" + decoder["SHIPTOSTREET2"] + "</span></td></tr>";
            ShippingAddress += "<td><span id=\"spanShippingCity\">" + decoder["SHIPTOCITY"] + "</span>" +
                ",&nbsp;<span id=\"spanShippingState\">" + decoder["SHIPTOSTATE"] + "</span>" +
                "&nbsp;<span id=\"spanShippingZip\">" + decoder["SHIPTOZIP"] + "</span></td></tr>";
            ShippingAddress += "<td><span id=\"spanShippingCountry\">" + decoder["SHIPTOCOUNTRYCODE"] + "</span></td></tr>";
            ShippingAddress += "<td></td>";
            ShippingAddress += "</tr></table>";

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

            return false;
        }
    }
    public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host = host_SB;
        }

        string returnURL = "https://localhost:44300/Checkout/CheckoutReview.aspx";
        string cancelURL = "https://localhost:44300/Checkout/CheckoutCancel.aspx";

        NVPCodec encoder = new NVPCodec();
        encoder["METHOD"] = "SetExpressCheckout";
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["BRANDNAME"] = "Wingtip Toys Sample Application";
        encoder["PAYMENTREQUEST_0_AMT"] = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";

        // Get the Shopping Cart Products
        using (WingtipToys.Logic.ShoppingCartActions myCartOrders = new WingtipToys.Logic.ShoppingCartActions())
        {
            List<CartItem> myOrderList = myCartOrders.GetCartItems();

            for (int i = 0; i < myOrderList.Count; i++)
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Product.ProductName.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Product.UnitPrice.ToString();
                encoder["L_PAYMENTREQUEST_0_QTY" + i] = myOrderList[i].Quantity.ToString();
            }
        }

        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.º 48
0
    public bool ShortcutExpressCheckout(string subTotal, string shippingIn, string amt, ref string token, ref string retMsg, Customer customerIn)
    {
        if (bSandbox)
            {
                pEndPointURL = pEndPointURL_SB;
                host = host_SB;
            }

            string returnURL = "http://localhost:64352/Graded%20Unit1/CheckoutReview.aspx";
            string cancelURL = "http://localhost:64352/Graded%20Unit1/CheckoutCancel.aspx";

            NVPCodec encoder = new NVPCodec();
            encoder["METHOD"] = "SetExpressCheckout";
            encoder["RETURNURL"] = returnURL;
            encoder["CANCELURL"] = cancelURL;
            encoder["BRANDNAME"] = "LidiFlu Ltd";
            encoder["PAYMENTREQUEST_0_AMT"] = amt;
            encoder["PAYMENTREQUEST_0_ITEMAMT"] = subTotal;
            encoder["PAYMENTREQUEST_0_SHIPPINGAMT"] = shippingIn;
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "GBP";

            // Get the Shopping Cart Products

            for (int i = 0; i < customerIn.Orders[0].OrderLines.Count; i++)
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + i] = customerIn.Orders[0].OrderLines[i].Product.ProdName.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + i] = customerIn.Orders[0].OrderLines[i].Product.ProdPrice.ToString();
                encoder["L_PAYMENTREQUEST_0_QTY" + i] = customerIn.Orders[0].OrderLines[i].Quantity.ToString();
            }

            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;
            }
    }
    /// <summary>
    /// This method is called first in order to perform the initial authorization for payment.
    /// </summary>
    /// <param name="amt"></param>
    /// <param name="token"></param>
    /// <param name="retMsg"></param>
    /// <returns></returns>
    public bool DoCheckoutAuth(OrderViewModel order, ref string token, ref NVPCodec decoder)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }

        NVPCodec encoder = new NVPCodec();
        encoder[NVPProperties.Properties.METHOD] = NVPProperties.Methods.AuthorizePayment;
        encoder[NVPProperties.Properties.BRANDNAME] = "Contoso Sports League";
        encoder[NVPProperties.Properties.PAYMENTREQUEST_AMT] = order.Total.ToString();
        encoder[NVPProperties.Properties.FIRSTNAME] = order.FirstName;
        encoder[NVPProperties.Properties.LASTNAME] = order.LastName;
        encoder[NVPProperties.Properties.ADDRESS] = order.Address;
        encoder[NVPProperties.Properties.CITY] = order.City;
        encoder[NVPProperties.Properties.STATE] = order.State;
        encoder[NVPProperties.Properties.POSTALCODE] = order.PostalCode;
        encoder[NVPProperties.Properties.NAME_ON_CREDIT_CARD] = order.NameOnCard;
        encoder[NVPProperties.Properties.CREDIT_CARD_TYPE] = order.CreditCardType;
        encoder[NVPProperties.Properties.CREDIT_CARD_NUMBER] = order.CreditCardNumber;
        encoder[NVPProperties.Properties.CREDIT_CARD_EXPDATE] = order.ExpirationDate;
        encoder[NVPProperties.Properties.CCV2] = order.CCV;

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

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

        string strAck = decoder[NVPProperties.Properties.ACK].ToLower();
        if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /// <summary>
    /// Call this method to complete payment.
    /// </summary>
    /// <param name="finalPaymentAmount"></param>
    /// <param name="token"></param>
    /// <param name="PayerID"></param>
    /// <param name="decoder"></param>
    /// <param name="retMsg"></param>
    /// <returns></returns>
    public bool DoCheckoutPayment(string finalPaymentAmount, string token, ref NVPCodec decoder)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }

        NVPCodec encoder = new NVPCodec();
        encoder[NVPProperties.Properties.METHOD] = NVPProperties.Methods.ProcessPayment;
        encoder[NVPProperties.Properties.TOKEN] = token;
        encoder[NVPProperties.Properties.PAYMENTREQUEST_AMT] = finalPaymentAmount;

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

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

        string strAck = decoder[NVPProperties.Properties.ACK].ToLower();
        if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
Ejemplo n.º 51
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(List<Items> items, string amt, string baseUrl, 
                    ref string token, ref string retMsg, string shipping)
    {
		string host = "www.paypal.com";
		if (bSandbox)
		{
			pendpointurl = "https://api-3t.sandbox.paypal.com/nvp";
			host = "www.sandbox.paypal.com";
		}

        string returnURL = baseUrl + "OrderReview.aspx";
        string cancelURL = baseUrl + "View-Cart.aspx";

        NVPCodec encoder = new NVPCodec();
        encoder["METHOD"] = "SetExpressCheckout";
        encoder["LOCALECODE"] = "CA";
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["SOLUTIONTYPE"] = "Sole";
        encoder["LANDINGPAGE"] = "Billing";
        
        int count = 0;
        foreach (Items item in items)
        {
            if (item.GetType().ToString() == "Frames")
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + count] = ((Frames)item).name;
                encoder["L_PAYMENTREQUEST_0_QTY" + count] = ((Frames)item).qty.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + count] = ((Frames)item).price.ToString(); // Cost of an item
                count++;
            }

            else if (item.GetType().ToString() == "Contacts")
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + count] = ((Contacts)item).name;
                int totalQty = ((Contacts)item).leftQty + ((Contacts)item).rightQty;
                encoder["L_PAYMENTREQUEST_0_QTY" + count] = totalQty.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + count] = ((Contacts)item).price.ToString(); // Cost of an item
                count++;
            }
            else if (item.GetType().ToString().Contains("ReadyReaders"))
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + count] = item.name;
                encoder["L_PAYMENTREQUEST_0_QTY" + count] = item.qty.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + count] = item.price.ToString(); // Cost of an item
                count++;
            }
            else if (item.GetType().ToString().Contains("Sunglasses"))
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + count] = item.name;
                encoder["L_PAYMENTREQUEST_0_QTY" + count] = item.qty.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + count] = item.price.ToString(); // Cost of an item
                count++;
            }
            else if (item.GetType().ToString().Contains("Solutions"))
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + count] = item.name;
                encoder["L_PAYMENTREQUEST_0_QTY" + count] = item.qty.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + count] = item.price.ToString(); // Cost of an item
                count++;
            }
            else if (item.GetType().ToString().Contains("Accessories"))
            {
                encoder["L_PAYMENTREQUEST_0_NAME" + count] = item.name;
                encoder["L_PAYMENTREQUEST_0_QTY" + count] = item.qty.ToString();
                encoder["L_PAYMENTREQUEST_0_AMT" + count] = item.price.ToString(); // Cost of an item
                count++;
            }
        }

        double finalAmount = Convert.ToDouble(amt) + Convert.ToDouble(shipping);
        // encoder["PAYMENTREQUEST_0_TAXAMT"] = tax.ToString(); // Sum of tax for all items.
        encoder["PAYMENTREQUEST_0_SHIPPINGAMT"] = shipping.ToString(); // Sum of shipping for all items.
        encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt.ToString(); // Sum of cost of all items.
        encoder["PAYMENTREQUEST_0_AMT"] = String.Format("{0:0.00}", finalAmount); // The total cost of the transaction to the customer.
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD";

        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.º 52
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 itemAmt, string shipping, 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["PAYMENTACTION"] = "Sale";
        encoder["PAYERID"] = payerID;
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD";
        encoder["PAYMENTREQUEST_0_SHIPPINGAMT"] = shipping.ToString(); // Sum of shipping for all items.
        encoder["PAYMENTREQUEST_0_ITEMAMT"] = itemAmt.ToString(); // Sum of cost of all items.
        encoder["PAYMENTREQUEST_0_AMT"] = finalPaymentAmount.ToString();

        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.º 53
0
    public NVPCodec DoCaptureCode(string authorization_id, string amount, string invoice_Id, string note)
    {
        NVPCallerServices caller = new NVPCallerServices();
        IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
        /*
         WARNING: Do not embed plaintext credentials in your application code.
         Doing so is insecure and against best practices.
         Your API credentials must be handled securely. Please consider
         encrypting them for use in any production environment, and ensure
         that only authorized individuals may view or modify them.
         */

        // Set up your API credentials, PayPal end point, API operation and version.
        profile.APIUsername = apiUserName;
        profile.APIPassword = apiPassword;
        profile.APISignature = apiSignature;
        profile.Environment = apiEnvironment;
        caller.APIProfile = profile;

        NVPCodec encoder = new NVPCodec();
        encoder["VERSION"] = "51.0";
        encoder["METHOD"] = "DoCapture";

        // Add request-specific fields to the request.
        encoder["TRXTYPE"] = "D";
        encoder["AUTHORIZATIONID"] = authorization_id;
        encoder["COMPLETETYPE"] = "Complete";
        encoder["AMT"] = amount;
        encoder["INVNUM"] = invoice_Id;
        encoder["NOTE"] = note;

        // Execute the API operation and obtain the response.
        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp = caller.Call(pStrrequestforNvp);

        NVPCodec decoder = new NVPCodec();
        decoder.Decode(pStresponsenvp);
        return decoder;
    }
    public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
    {
        if (bSandbox)
            {
                pEndPointURL = pEndPointURL_SB;
                host = host_SB;
            }

            string returnURL = "http://ethiohilecomvctoysapp2017.apphb.com/Checkout/CheckoutReview";
            string cancelURL = "http://ethiohilecomvctoysapp2017.apphb.com/Checkout/CheckoutCancel";

            NVPCodec encoder = new NVPCodec();
            encoder["METHOD"] = "SetExpressCheckout";
            encoder["RETURNURL"] = returnURL;
            encoder["CANCELURL"] = cancelURL;
            encoder["BRANDNAME"] = "HiLEco MVC Toys Sample Application 2015";
            encoder["PAYMENTREQUEST_0_AMT"] = amt;
            encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt;
            encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
            encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";

            // Get the Shopping Cart Products
            CartApplicationService cartApplicationService = new CartApplicationService();

            var Cart = ShoppingCartActions.GetCart();
            // string CartID = Cart.GetCartId(this.HttpContext);
            string CartID = "";
            CartID = Cart.ShoppingCartId;

            CartViewModel cartViewModel = new CartViewModel();
            cartViewModel=cartApplicationService.GetCarts(CartID);
            int i = 0;
            foreach (var item in cartViewModel.Carts)
            {
                if (item.CartID != "")
                {

                    encoder["L_PAYMENTREQUEST_0_NAME" + i] = item.ProductName.ToString();
                    encoder["L_PAYMENTREQUEST_0_AMT" + i] = item.UnitPrice.ToString();
                    encoder["L_PAYMENTREQUEST_0_QTY" + i] = item.Quantity.ToString();

                }
                i++;
            }
            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.º 55
0
    /// <summary>
    /// DirectPayment: The method for credit card payment
    /// </summary>
    /// Note:
    ///	There are other optional inputs for credit card processing that are not presented here.
    ///		For a complete list of inputs available, please see the documentation here for US and UK:
    ///		https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_PayflowPro_Guide.pdf
    ///		https://cms.paypal.com/cms_content/GB/en_GB/files/developer/PP_WebsitePaymentsPro_IntegrationGuide_UK.pdf
    /// <param name="amt"></param>
    /// <param ref name="token"></param>
    /// <param ref name="retMsg"></param>
    /// <returns></returns>
    public bool DirectPayment(string paymentType, string paymentAmount, string creditCardType, string creditCardNumber, string expDate, string cvv2, string firstName, string lastName, string street, string city, string state, string zip, string countryCode, string currencyCode, string orderdescription, ref NVPCodec decoder, ref string retMsg)
    {
        if (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
        }

        NVPCodec encoder = new NVPCodec();
        encoder["TENDER"] = "C";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["ACCT"]				= creditCardNumber;
        encoder["CVV2"]				= cvv2;
        encoder["EXPDATE"]			= expDate;
        encoder["ACCTTYPE"]			= creditCardType;
        encoder["AMT"]				= paymentAmount;
        encoder["CURRENCY"]			= currencyCode;
        encoder["FIRSTNAME"]		= firstName;
        encoder["LASTNAME"]			= lastName;
        encoder["STREET"]			= street;
        encoder["CITY"]				= city;
        encoder["STATE"]			= state;
        encoder["ZIP"]				= zip;
        encoder["COUNTRY"]			= countryCode;
        // unique request ID
        System.Guid uid = System.Guid.NewGuid();
        encoder["INVNUM"]			= uid.ToString();
        encoder["ORDERDESC"]		= orderdescription;
        encoder["VERBOSITY"]		= "MEDIUM";

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp = HttpCall(pStrrequestforNvp,uid.ToString());

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

        string strAck = decoder["RESULT"].ToLower();
        if (strAck != null && strAck == "0")
        {
            return true;
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                "Desc=" + decoder["RESPMSG"];

            return false;
        }
    }
Ejemplo n.º 56
0
    /// <summary>
    /// GetShippingDetails: The method that calls GetExpressCheckoutDetails
    /// </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 (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
        }

        NVPCodec encoder = new NVPCodec();
        encoder["TOKEN"] = token;
        encoder["TENDER"] = "P";
        encoder["ACTION"] = "G";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }

        // unique request ID
        System.Guid uid = System.Guid.NewGuid();

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp = HttpCall( pStrrequestforNvp,uid.ToString() );

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

        string strAck = decoder["RESULT"].ToLower();
        if (strAck != null && strAck == "0")
        {
            ShippingAddress = "<table><tr>";
            ShippingAddress += "<td colspan='2'> Shipping Address</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=" + strAck + "&" +
                "Desc=" + decoder["RESPMSG"];

            return false;
        }
    }
    public bool GetCheckoutDetails(string token, ref string PayerID, ref NVPCodec decoder, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
        }

        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"))
        {
            PayerID = decoder["PAYERID"];
            return true;
        }
        else
        {
            retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                "Desc2=" + decoder["L_LONGMESSAGE0"];

            return false;
        }
    }
Ejemplo n.º 58
0
    /// <summary>
    /// MarkExpressCheckout: The method that calls SetExpressCheckout, 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 (Env == "pilot")
        {
            pendpointurl = "https://pilot-payflowpro.paypal.com";
            host = "www.sandbox.paypal.com";
        }

        string returnURL = "http://www.careerjudge.com/FJAHome.aspx";
        string cancelURL = "https://www.novasoftindia.com";

        NVPCodec encoder = new NVPCodec();
        encoder["TENDER"] = "P";
        encoder["ACTION"] = "S";
        if ("Authorization" == "Sale")
        {
            encoder["TRXTYPE"] = "A";
        }
        else /* sale */
        {
            encoder["TRXTYPE"] = "S";
        }
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["AMT"] = amt;
        encoder["CURRENCY"]  = "USD";

        //Optional Shipping Address entered on the merchant site
        encoder["SHIPTOSTREET"]     = shipToStreet;
        encoder["SHIPTOSTREET2"]    = shipToStreet2;
        encoder["SHIPTOCITY"]       = shipToCity;
        encoder["SHIPTOSTATE"]      = shipToState;
        encoder["SHIPTOZIP"]        = shipToZip;
        encoder["SHIPTOCOUNTRY"]	= shipToCountryCode;
        encoder["ADDROVERRIDE"]		= "1";

        // unique request ID
        System.Guid uid = System.Guid.NewGuid();

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp = HttpCall(pStrrequestforNvp,uid.ToString());

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

        string strAck = decoder["RESULT"].ToLower();
        if (strAck != null && strAck == "0")
        {
            token = decoder["TOKEN"];

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

            retMsg = ECURL;
            return true;
        }
        else
        {
            retMsg = "ErrorCode=" + strAck + "&" +
                "Desc=" + decoder["RESPMSG"];

            return false;
        }
    }
Ejemplo n.º 59
0
    public NVPCodec DoPayment(string paymentAction, string amount, string creditCardType, string creditCardNumber,
        string expdate_month, string expdate_year, string cvv2Number, string firstName, string lastName, string address1, string city, string state,
        string countryCode, string zip, string IPAddress)
    {
        NVPCallerServices caller = new NVPCallerServices();
        IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
        /*
         WARNING: Do not embed plaintext credentials in your application code.
         Doing so is insecure and against best practices.
         Your API credentials must be handled securely. Please consider
         encrypting them for use in any production environment, and ensure
         that only authorized individuals may view or modify them.
         */

        // Set up your API credentials, PayPal end point, API operation and version.
        profile.APIUsername = apiUserName;
        profile.APIPassword = apiPassword;
        profile.APISignature = apiSignature;
        profile.Environment = apiEnvironment;
        caller.APIProfile = profile;

        NVPCodec encoder = new NVPCodec();

        encoder["VERSION"] = "51.0";
        encoder["METHOD"] = "DoDirectPayment";

        // Add request-specific fields to the request.
        encoder["PAYMENTACTION"] = paymentAction;
        encoder["AMT"] = amount;
        encoder["CREDITCARDTYPE"] = creditCardType;
        encoder["ACCT"] = creditCardNumber;
        //encoder["EXPMONTH"] = "12";
        //encoder["EXPYEAR"] = "2012";
        if (expdate_month.Length == 1)
            expdate_month = "0" + expdate_month;
        encoder["EXPDATE"] = expdate_month + expdate_year;
        //encoder["ExpMonthSpecified"] = "True";
        //encoder["ExpYearSpecified"] = "True";
        encoder["CVV2"] = cvv2Number;
        encoder["FIRSTNAME"] = firstName;
        encoder["LASTNAME"] = lastName;
        encoder["STREET"] = address1;
        encoder["CITY"] = city;
        encoder["STATE"] = state;
        encoder["ZIP"] = zip;
        encoder["COUNTRYCODE"] = countryCode;
        encoder["CURRENCYCODE"] = "USD";
        encoder["IPADDRESS"] = IPAddress;

        // Execute the API operation and obtain the response.
        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp = caller.Call(pStrrequestforNvp);

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

        //string allResults = pStrrequestforNvp + "<br/><br/>" + pStresponsenvp + "<br/><br/>";

        //foreach (string key in decoder.Keys)
        //{
        //    allResults += "key: '" + key + "', value: '" + decoder[key] + "' <br/>";
        //}
        //allResults += "<br/>Encoder:<br/>";
        //foreach (string key in encoder)
        //{
        //    allResults += "key: '" + key + "', value: '" + encoder[key] + "' <br/>";
        //}

        return decoder;
    }
Ejemplo n.º 60
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, string baseUrl, 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 = baseUrl + "OrderReview.aspx";
        string cancelURL = baseUrl + "View-Cart.aspx";

        NVPCodec encoder = new NVPCodec();
        encoder["METHOD"] = "SetExpressCheckout";
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["PAYMENTREQUEST_0_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=" + decoder["L_ERRORCODE0"] + "&" +
                "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                "Desc2=" + decoder["L_LONGMESSAGE0"];

            return false;
        }
    }