Пример #1
0
    /// <summary>
    /// Process credit card
    /// </summary>
    /// <param name="payment"></param>
    /// <returns></returns>
    public static string ProcessCreditCard(PaymentInformation payment)
    {
        string response        = "";
        string mRequestId      = "";
        string transactionReqt = "";

        transactionReqt += "NAME=" + payment.NameOnCard + "&";
        transactionReqt += "ACCT=" + payment.CreditCardNumber + "&";
        transactionReqt += "EXPDATE=" + payment.CardExpirationMonth + payment.CardExpirationYear + "&";
        transactionReqt += "AMT=" + payment.TransactionAmount + "&";
        transactionReqt += "STREET=" + payment.Street + "&";
        transactionReqt += "CITY=" + payment.City + "&";
        transactionReqt += "STATE=" + payment.State + "&";
        transactionReqt += "ZIP=" + payment.Zip + "&";
        transactionReqt += "CVV2=" + payment.CreditCardVerificationCode + "&";

        transactionReqt += "TRXTYPE=S&TENDER=C&";
        transactionReqt += "USER="******"&";
        transactionReqt += "VENDOR=" + PayflowUtility.AppSettings(LACESConstant.PaymentInfo.VENDOR) + "&";
        transactionReqt += "PARTNER=" + PayflowUtility.AppSettings(LACESConstant.PaymentInfo.PARTNER) + "&";
        transactionReqt += "PWD=" + PayflowUtility.AppSettings(LACESConstant.PaymentInfo.PWD);


        mRequestId = PayflowUtility.RequestId;

        PayflowNETAPI PayflowNETAPI = new PayflowNETAPI();

        //TransactionReqt = "TRXTYPE=S&ACCT=5105105105105101&EXPDATE=0109&TENDER=C&INVNUM=INV12345&AMT=25.12&PONUM=PO12345&STREET=123 Main St.&ZIP=12345&CVV2=123&USER=zmiller636&VENDOR=zmiller636&PARTNER=paypal&PWD=luvspurple1";

        response = PayflowNETAPI.SubmitTransaction(transactionReqt, mRequestId);

        return(response);
    }
Пример #2
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: NVPCommandLine.cs");
            Console.WriteLine("------------------------------------------------------");

            String ResponseStr = null;

            if (Args.Length < 4)
            {
                Console.WriteLine(Environment.NewLine + "Incorrect number of arguments. Usage:" + Environment.NewLine
                                  + "SamplesCS <hostAddress> <hostPort> <parmList> <timeOut> <proxyAddress> <proxyPort> <proxyLogon> <proxyPassword>");
                Console.WriteLine(Environment.NewLine + "Example transaction:" + Environment.NewLine + "SamplesCS pilot-payflowpro.paypal.com 443 \"USER=<user>&TRXTYPE[1]=A&VENDOR=<vendor>&AMT[5]=25.00&PWD=<password>&PARTNER=<partner>&TENDER[1]=C&ACCT[16]=5100000000000008&EXPDATE[4]=0125\" 45");
                Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
                Console.ReadLine();
                System.Environment.Exit(-1);
            }

            PayflowNETAPI PayflowNETAPI;

            if (Args.Length == 4)
            {
                PayflowNETAPI = new PayflowNETAPI(Args[0],
                                                  System.Convert.ToInt32(Args[1]),
                                                  System.Convert.ToInt32(Args[3]));
            }
            else
            {
                PayflowNETAPI = new PayflowNETAPI(Args[0],
                                                  System.Convert.ToInt32(Args[1]),
                                                  System.Convert.ToInt32(Args[3]), Args[4],
                                                  System.Convert.ToInt32(Args[5]),
                                                  Args[6], Args[7]);
            }

            ResponseStr = PayflowNETAPI.SubmitTransaction(Args[2],
                                                          PayflowUtility.RequestId);

            // To write the Response on to the console.
            Console.WriteLine(Environment.NewLine + "Request = " + PayflowNETAPI.TransactionRequest);
            Console.WriteLine(Environment.NewLine + "Response = " + ResponseStr);

            // Following lines of code are optional.
            // Begin optional code for displaying SDK errors ...
            // It is used to read any errors that might have occurred in the SDK.
            // Get the transaction errors.
            String TransErrors = PayflowNETAPI.TransactionContext.ToString();

            if (TransErrors != null && TransErrors.Length > 0)
            {
                Console.WriteLine(Environment.NewLine + "Transaction Errors from SDK = " + TransErrors);
            }

            Console.WriteLine(Environment.NewLine + "Status: " + PayflowUtility.GetStatus(ResponseStr));
            Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
            Console.ReadLine();
        }
        /// <summary>
        /// Process a payment transaction
        /// </summary>
        /// <param name="request">A PayPalRequest object containing the information to process.</param>
        /// <returns>A PayPalResponse object with the payment gateway's response.</returns>
        public CreditCardCancelResponse ProcessTransaction(CreditCardCancelRequest request)
        {
            CreditCardCancelResponse response = new CreditCardCancelResponse();

            PayflowNETAPI payflowNetApi = new PayflowNETAPI(request.HostAddress, request.HostPort, request.TimeOut);
            string apiResponse = payflowNetApi.SubmitTransaction(request.ParmList.ToString(),PayflowUtility.RequestId);
            response = ParseApiResponse(apiResponse);

            return response;
        }
        /// <summary>
        /// Process a payment transaction
        /// </summary>
        /// <param name="request">A PayPalRequest object containing the information to process.</param>
        /// <returns>A PayPalResponse object with the payment gateway's response.</returns>
        public ACHRecurringSaleResponse ProcessTransaction(ACHRecurringSaleRequest request)
        {
            ACHRecurringSaleResponse response = new ACHRecurringSaleResponse();

            PayflowNETAPI payflowNetApi = new PayflowNETAPI(request.HostAddress, request.HostPort, request.TimeOut);
            string apiResponse = payflowNetApi.SubmitTransaction(request.ParmList.ToString(), PayflowUtility.RequestId);
            response = ParseApiResponse(apiResponse);

            return response;
        }
Пример #5
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: XMLPayCommandLine.cs");
            Console.WriteLine("------------------------------------------------------");

            if (Args.Length < 4)
            {
                Console.WriteLine(Environment.NewLine + "Incorrect number of arguments. Usage:" + Environment.NewLine
                                  + "SamplesCS <hostAddress> <hostPort> <xml-parmList> <timeout> <proxyAddress> <proxyPort> <proxyLogon> <proxyPassword>");
                Console.WriteLine(Environment.NewLine + "Example transaction:" + Environment.NewLine
                                  + "SamplesCS pilot-payflowpro.paypal.com 443 \"<?xml version='1.0'?><XMLPayRequest Timeout='45' version='2.0'><RequestData><Partner>[partner]</Partner><Vendor>[vendor]</Vendor><Transactions><Transaction><Sale><PayData><Invoice><TotalAmt Currency='USD'>25.12</TotalAmt><InvNum>INV12345</InvNum><BillTo><PONum>PO12345</PONum><Address><Street>123 Main St.</Street><Zip>12345</Zip></Address></BillTo></Invoice><Tender><Card><CardNum>5105105105105100</CardNum><ExpDate>201501</ExpDate></Card></Tender></PayData></Sale></Transaction></Transactions></RequestData><RequestAuth><UserPass><User>[user]</User><Password>[password]</Password></UserPass></RequestAuth></XMLPayRequest>\" 45");
                Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
                Console.ReadLine();
                System.Environment.Exit(-1);
            }

            PayflowNETAPI PayflowNETAPI;

            if (Args.Length == 3)
            {
                PayflowNETAPI = new PayflowNETAPI(Args[0],
                                                  System.Convert.ToInt32(Args[1]),
                                                  System.Convert.ToInt32(Args[3]));
            }
            else
            {
                PayflowNETAPI = new PayflowNETAPI(Args[0],
                                                  System.Convert.ToInt32(Args[1]),
                                                  System.Convert.ToInt32(Args[3]), Args[4],
                                                  System.Convert.ToInt32(Args[5]),
                                                  Args[6], Args[7]);
            }

            String ResponseStr = PayflowNETAPI.SubmitTransaction(Args[2], PayflowUtility.RequestId);

            // To write the Response on to the console.
            Console.WriteLine(Environment.NewLine + "Request = " + PayflowNETAPI.TransactionRequest);
            Console.WriteLine(Environment.NewLine + "Response = " + ResponseStr);

            // Following lines of code are optional.
            // Begin optional code for displaying SDK errors ...
            // It is used to read any errors that might have occurred in the SDK.
            // Get the transaction errors.
            String TransErrors = PayflowNETAPI.TransactionContext.ToString();

            if (TransErrors != null && TransErrors.Length > 0)
            {
                Console.WriteLine(Environment.NewLine + "Transaction Errors from SDK = " + TransErrors);
            }
            Console.WriteLine(Environment.NewLine + "Status: " + PayflowUtility.GetStatus(ResponseStr));
            Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
            Console.ReadLine();
        }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string PayPalRequest = "TRXTYPE=S"                     //S - sale transaction
                                   + "&TENDER=C"                   //C - Credit card
                                   + "&ACCT=" + txtCardNumber.Text //card number
                                   + "&EXPDATE=" + ddlMonth.SelectedValue + ddlYear.SelectedValue.Substring(2, 2)
                                   + "&CVV2=" + txtCvv.Text        //card validation value (card security code)
                                   + "&AMT=" + txtAmount.Text
                                   + "&COMMENT1=My Product Sale"
                                   + "&USER="******"USER"]
                                   + "&VENDOR=" + ConfigurationManager.AppSettings["VENDOR"]
                                   + "&PARTNER=" + ConfigurationManager.AppSettings["PARTNER"]
                                   + "&PWD=" + ConfigurationManager.AppSettings["PWD"];


            // Create an instantce of PayflowNETAPI.
            PayflowNETAPI PayflowNETAPI = new PayflowNETAPI();

            // RequestId is a unique string that is required for each & every transaction.
            // The merchant can use her/his own algorithm to generate this unique request id or
            // use the SDK provided API to generate this as shown below (PayflowUtility.RequestId).
            string PayPalResponse = PayflowNETAPI.SubmitTransaction(PayPalRequest, PayflowUtility.RequestId);

            //place data from PayPal into a namevaluecollection
            NameValueCollection RequestCollection  = GetPayPalCollection(PayflowNETAPI.TransactionRequest);
            NameValueCollection ResponseCollection = GetPayPalCollection(PayPalResponse);

            //show request
            lblResult.Text  = "<span class=\"heading\">PayPal Payflow Pro transaction request</span><br />";
            lblResult.Text += ShowPayPalInfo(RequestCollection);

            //show response
            lblResult.Text += "<br /><br /><span class=\"heading\">PayPal Payflow Pro transaction response</span><br />";
            lblResult.Text += ShowPayPalInfo(ResponseCollection);

            //show transaction errors if any
            string TransErrors = PayflowNETAPI.TransactionContext.ToString();
            if (TransErrors != null && TransErrors.Length > 0)
            {
                lblResult.Text += "<br /><br /><span class=\"bold-text\">Transaction Errors:</span> " + TransErrors;
            }

            //show transaction status
            lblResult.Text += "<br /><br /><span class=\"bold-text\">Status:</span> " + PayflowUtility.GetStatus(PayPalResponse);
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message.ToString();
        }
    }
Пример #7
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string PayPalRequest = "TRXTYPE=S" //S - sale transaction
                     + "&TENDER=C" //C - Credit card
                     + "&ACCT=" + txtCardNumber.Text //card number
                     + "&EXPDATE=" + ddlMonth.SelectedValue + ddlYear.SelectedValue.Substring(2, 2)
                     + "&CVV2=" + txtCvv.Text   //card validation value (card security code)
                     + "&AMT=" + txtAmount.Text
                     + "&COMMENT1=My Product Sale"
                     + "&USER="******"USER"]
                     + "&VENDOR=" + ConfigurationManager.AppSettings["VENDOR"]
                     + "&PARTNER=" + ConfigurationManager.AppSettings["PARTNER"]
                     + "&PWD=" + ConfigurationManager.AppSettings["PWD"];

                // Create an instantce of PayflowNETAPI.
                PayflowNETAPI PayflowNETAPI = new PayflowNETAPI();

                // RequestId is a unique string that is required for each & every transaction.
                // The merchant can use her/his own algorithm to generate this unique request id or
                // use the SDK provided API to generate this as shown below (PayflowUtility.RequestId).
                string PayPalResponse = PayflowNETAPI.SubmitTransaction(PayPalRequest, PayflowUtility.RequestId);

                //place data from PayPal into a namevaluecollection
                NameValueCollection RequestCollection = GetPayPalCollection(PayflowNETAPI.TransactionRequest);
                NameValueCollection ResponseCollection = GetPayPalCollection(PayPalResponse);

                //show request
                lblResult.Text = "<span class=\"heading\">PayPal Payflow Pro transaction request</span><br />";
                lblResult.Text += ShowPayPalInfo(RequestCollection);

                //show response
                lblResult.Text += "<br /><br /><span class=\"heading\">PayPal Payflow Pro transaction response</span><br />";
                lblResult.Text += ShowPayPalInfo(ResponseCollection);

                //show transaction errors if any
                string TransErrors = PayflowNETAPI.TransactionContext.ToString();
                if (TransErrors != null && TransErrors.Length > 0)
                {
                    lblResult.Text += "<br /><br /><span class=\"bold-text\">Transaction Errors:</span> " + TransErrors;
                }

                //show transaction status
                lblResult.Text += "<br /><br /><span class=\"bold-text\">Status:</span> " + PayflowUtility.GetStatus(PayPalResponse);
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Пример #8
0
        public static Dictionary<string, string> SubmitPaymentRequest(Dictionary<string, string> requestNvps, PayflowProSettingsDto settings, UserContext userContext, IEntityContext entityContext)
        {
            CheckSettings(settings);

            //Add Settings to Request String
            var nvpRequest = new StringBuilder();
            var accountNum = string.Empty;
            var securityCode = string.Empty;

            nvpRequest.AppendFormat(CultureInfo.InvariantCulture, "USER={0}&VENDOR={1}&PARTNER={2}&PWD={3}", settings.UserId, settings.VendorId, settings.Partner, settings.Password);

            foreach (var nvp in requestNvps)
            {
                nvpRequest.AppendFormat(CultureInfo.InvariantCulture, "&{0}={1}", nvp.Key, nvp.Value);

                if (nvp.Key == Constants.AccountNumber) accountNum = nvp.Value;
                if (nvp.Key == Constants.VerificationCode) securityCode = nvp.Value;
            }

            //Create API Request Object
            var payflowApi = new PayflowNETAPI();
            var hostAddress = settings.Environment.ToUpperInvariant() == "SANDBOX" ?
                "pilot-payflowpro.paypal.com" : "payflowpro.paypal.com";

            payflowApi.SetParameters(hostAddress, 443, 45, "", 0, "", "", "enabled", "1", "payflow.log", "10240000", false);

            //Send request and retrieve response
            var response = payflowApi.SubmitTransaction(nvpRequest.ToString(), PayflowUtility.RequestId);

            //Parse Response
            var responseNvp = new Dictionary<string, string>();
            foreach (var pair in response.Split('&'))
            {
                var values = pair.Split('=');

                if (values.Length == 2)
                    responseNvp.Add(values[0], values[1]);
            }

            //TODO: edit from original
            var pnref = responseNvp.ContainsKey("PNREF") ? responseNvp["PNREF"] : string.Empty;
            var result = responseNvp.ContainsKey("RESULT") ? responseNvp["RESULT"] : string.Empty;

            CreatePaymentOperationRecord(nvpRequest.ToString(), accountNum, securityCode, result, pnref, settings.Id, userContext, entityContext);

            return responseNvp;
        }
Пример #9
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: XMLPaySale.cs");
            Console.WriteLine("------------------------------------------------------");

            // Sample Request.
            // Please replace [user], [vendor], [password] & [partner] with your merchant information.
            String Request = "<?xml version=\"1.0\"?><XMLPayRequest Timeout=\"45\" version=\"2.0\"><RequestData><Partner>[partner]</Partner><Vendor>[vendor]</Vendor><Transactions><Transaction><Sale><PayData><Invoice><TotalAmt Currency=\"USD\">25.12</TotalAmt><InvNum>INV12345</InvNum><BillTo><PONum>PO12345</PONum><Address><Street>123 Main St.</Street><Zip>12345</Zip></Address></BillTo></Invoice><Tender><Card><CardNum>5105105105105100</CardNum><ExpDate>202501</ExpDate></Card></Tender></PayData></Sale></Transaction></Transactions></RequestData><RequestAuth><UserPass><User>[user]</User><Password>[password]</Password></UserPass></RequestAuth></XMLPayRequest>";

            // Create an instance of PayflowNETAPI.
            PayflowNETAPI PayflowNETAPI = new PayflowNETAPI();
            // Can also pass the values in the constructor itself instead of using .config file.
            //PayflowNETAPI.SetParameters("pilot-payflowpro.paypal.com", 443, 45, "", 0, "", "", "enabled", "1", "payflow.log", "10240000", false);

            // RequestId is a unique string that is required for each & every transaction.
            // The merchant can use her/his own algorithm to generate this unique request id or
            // use the SDK provided API to generate this as shown below (PayflowUtility.RequestId).
            //
            // NOTE: Review the comments in the DoSaleComplete example under BasicTransactions for
            // more information on the Request ID.
            String Response = PayflowNETAPI.SubmitTransaction(Request, PayflowUtility.RequestId);

            // To write the Response on to the console.
            Console.WriteLine(Environment.NewLine + "Request = " + PayflowNETAPI.TransactionRequest);
            Console.WriteLine(Environment.NewLine + "Response = " + Response);

            // Following lines of code are optional.
            // Begin optional code for displaying SDK errors ...
            // It is used to read any errors that might have occurred in the SDK.
            // Get the transaction errors.
            String TransErrors = PayflowNETAPI.TransactionContext.ToString();

            if (TransErrors != null && TransErrors.Length > 0)
            {
                Console.WriteLine(Environment.NewLine + "Transaction Errors from SDK = " + TransErrors);
            }

            Console.WriteLine(Environment.NewLine + "Status: " + PayflowUtility.GetStatus(Response));
            Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
            Console.ReadLine();
        }
Пример #10
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: NVPSale.cs");
            Console.WriteLine("------------------------------------------------------");

            // Sample Request.
            // Please replace <user>, <vendor>, <password> & <partner> with your merchant information.
            //String Request = "USER=<user>&VENDOR=<vendor>&PARTNER=<partner>&PWD=<password>&TRXTYPE=S&ACCT=5105105105105100&EXPDATE=0125&TENDER=C&INVNUM=INV12345&AMT=25.12&PONUM=PO12345&STREET=123 Main St.&ZIP=12345";
            String Request = "USER=toddprov4&VENDOR=toddprov4&PARTNER=VeriSign&PWD=password1&TRXTYPE=S&ORIGID=A50O0BE63815&EXPDATE=0125&TENDER=C&INVNUM=INV12345&AMT=25.12&PONUM=PO12345&STREET=123 Main St.&ZIP=12345";

            // Create an instance of PayflowNETAPI.
            PayflowNETAPI PayflowNETAPI = new PayflowNETAPI();

            // Can also pass the values in the constructor itself instead of using .config file.
            PayflowNETAPI.SetParameters("pilot-payflowpro.paypal.com", 443, 45, "", 0, "", "", "enabled", "1", "payflow.log", "10240000", false);

            // RequestId is a unique string that is required for each & every transaction.
            // The merchant can use her/his own algorithm to generate this unique request id or
            // use the SDK provided API to generate this as shown below (PayflowUtility.RequestId).
            //
            // NOTE: Review the comments in the DoSaleComplete example under BasicTransactions for
            // more information on the Request ID.
            String Response = PayflowNETAPI.SubmitTransaction(Request, PayflowUtility.RequestId);

            // To write the Response on to the console.
            Console.WriteLine(Environment.NewLine + "Request = " + PayflowNETAPI.TransactionRequest);
            Console.WriteLine(Environment.NewLine + "Response = " + Response);
            // Following lines of code are optional.
            // Begin optional code for displaying SDK errors ...
            // It is used to read any errors that might have occurred in the SDK.
            // Get the transaction errors.
            String TransErrors = PayflowNETAPI.TransactionContext.ToString();

            if (TransErrors != null && TransErrors.Length > 0)
            {
                Console.WriteLine(Environment.NewLine + "Transaction Errors from SDK = " + TransErrors);
            }
            Console.WriteLine(Environment.NewLine + "Status: " + PayflowUtility.GetStatus(Response));
            Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
            Console.ReadLine();
        }
        public PaymentResponse CreditCardPayment(CreditCardPaymentRequest req)
        {
            StringBuilder request = new StringBuilder();

            request.Append($"TRXTYPE=S");
            request.Append($"&ACCT={req.AccountNumber}");
            request.Append($"&EXPDATE={req.Expiration.Replace("/", "")}");
            request.Append($"&TENDER=C");
            if (string.IsNullOrWhiteSpace(req.InvoiceNumber))
            {
                req.InvoiceNumber = _confirmationNumberGenerator.GenerateConfirmationNumber();
            }
            request.Append($"&INVNUM={Uri.EscapeDataString(req.InvoiceNumber)}");
            request.Append($"&AMT={req.Amount:0.##}");
            request.Append($"&USER={User}");
            request.Append($"&VENDOR={Vendor}");
            request.Append($"&PARTNER={Partner}");
            request.Append($"&PWD={Password}");
            if (string.IsNullOrWhiteSpace(req.Comment))
            {
                request.Append($"&COMMENT1=");
            }
            else
            {
                request.Append($"&COMMENT1={Uri.EscapeDataString(req.Comment)}");
            }
            if (req.BillingInformation != null)
            {
                if (!string.IsNullOrWhiteSpace(req.BillingInformation.BillToFirstName))
                {
                    request.Append($"&BILLTOFIRSTNAME={req.BillingInformation.BillToFirstName}");
                }
                if (!string.IsNullOrWhiteSpace(req.BillingInformation.BillToLastName))
                {
                    request.Append($"&BILLTOLASTNAME={req.BillingInformation.BillToLastName}");
                }
                if (!string.IsNullOrWhiteSpace(req.BillingInformation.BilingZipcode))
                {
                    request.Append($"&BILLTOZIP={req.BillingInformation.BilingZipcode}");
                }
                if (!string.IsNullOrWhiteSpace(req.BillingInformation.BillingAddress))
                {
                    request.Append($"&BILLTOSTREET={req.BillingInformation.BillingAddress}");
                }
                if (!string.IsNullOrWhiteSpace(req.BillingInformation.BillingCity))
                {
                    request.Append($"&BILLTOCITY={req.BillingInformation.BillingCity}");
                }
                if (!string.IsNullOrWhiteSpace(req.BillingInformation.BillingState))
                {
                    request.Append($"&BILLTOSTATE={req.BillingInformation.BillingState}");
                }
            }
            request.Append("&VERBOSITY=HIGH");
            PayflowNETAPI PayflowNETAPI = new PayflowNETAPI(Host, Port, Timeout);

            string PayflowResponse = PayflowNETAPI.SubmitTransaction(request.ToString(), PayflowUtility.RequestId);
            var    results         = PayflowResponse.Split(new char[] { '&' }).Select(x => new { Name = x.Split('=')[0], Value = x.Split('=')[1] });
            var    RESPMSG         = results.Where(x => x.Name == "RESPMSG").DefaultIfEmpty(null).Single();

            if (RESPMSG != null)
            {
                if (RESPMSG.Value == "Approved")
                {
                    return(new PaymentResponse
                    {
                        Amount = req.Amount,
                        AuthCode = results.Where(x => x.Name == "AUTHCODE").DefaultIfEmpty(null).Single().Value,
                        Transaction = results.Where(x => x.Name == "PNREF").DefaultIfEmpty(null).Single().Value,
                        Success = true,
                        Message = RESPMSG.Value,
                        ProviderResponse = PayflowResponse
                    });
                }
            }
            return(new PaymentResponse
            {
                ProviderResponse = PayflowResponse,
                Amount = req.Amount,
                Message = RESPMSG == null ? "Payment Provider did not provide valid response" : RESPMSG.Value,
                ResponseText = RESPMSG == null ? "Payment Provider did not provide valid response" : RESPMSG.Value,
                Success = false,
            });
        }
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: XMLPayCommandLine_File.cs");
            Console.WriteLine("------------------------------------------------------");

            if (Args.Length < 4)
            {
                Console.WriteLine(Environment.NewLine + "Incorrect number of arguments. Usage:" + Environment.NewLine + "SamplesCS <hostAddress> <hostPort> <xml filename> <timeout> <proxyAddress> <proxyPort> <proxyLogon> <proxyPassword>");
                Console.WriteLine(Environment.NewLine + "Example transaction:" + Environment.NewLine + "SamplesCS pilot-payflowpro.paypal.com 443 \"C:" +
                                  System.IO.Path.DirectorySeparatorChar + "Sale.xml\" 45");
                Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
                Console.ReadLine();
                System.Environment.Exit(-1);
            }

            PayflowNETAPI PayflowNETAPI;

            if (Args.Length == 4)
            {
                PayflowNETAPI = new PayflowNETAPI(Args[0],
                                                  System.Convert.ToInt32(Args[1]),
                                                  System.Convert.ToInt32(Args[3]));
            }
            else
            {
                PayflowNETAPI = new PayflowNETAPI(Args[0],
                                                  System.Convert.ToInt32(Args[1]),
                                                  System.Convert.ToInt32(Args[3]), Args[4],
                                                  System.Convert.ToInt32(Args[5]),
                                                  Args[6], Args[7]);
            }

            String XmlFile = ReadFile(Args[2]);

            if (XmlFile != null)
            {
                String ResponseStr = PayflowNETAPI.SubmitTransaction(XmlFile, PayflowUtility.RequestId);

                // To write the Response on to the console.
                Console.WriteLine(Environment.NewLine + "Request = " + PayflowNETAPI.TransactionRequest);
                Console.WriteLine(Environment.NewLine + "Response = " + ResponseStr);

                // Following lines of code are optional.
                // Begin optional code for displaying SDK errors ...
                // It is used to read any errors that might have occurred in the SDK.
                // Get the transaction errors.
                String TransErrors = PayflowNETAPI.TransactionContext.ToString();
                if (TransErrors != null && TransErrors.Length > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors from SDK = " + TransErrors);
                }
                Console.WriteLine(Environment.NewLine + "Status: " + PayflowUtility.GetStatus(ResponseStr));
                Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
                Console.ReadLine();
            }
        }
Пример #13
0
        /// <summary>
        /// This method submits the transaction
        /// to the PayPal Payment Gateway.
        /// The response is obtained from the gateway
        /// and response object is populated with the
        /// response values along with the sdk specific
        /// errors in context, if any.
        /// </summary>
        /// <returns>Returns response object for Strong assembly transactions</returns>
        /// <example>
        /// <code lang="C#" escaped="false">
        ///		............
        ///		//Trans is the transaction object.
        ///		............
        ///
        ///		//Submit the transaction.
        ///		Trans.SubmitTransaction();
        ///
        ///		// Get the Response.
        ///		Response Resp = Trans.Response;
        ///		if (Resp != null)
        ///		{
        ///			// Get the Transaction Response parameters.
        ///			TransactionResponse TrxnResponse =  Resp.TransactionResponse;
        ///			if (TrxnResponse != null)
        ///			{
        ///				Console.WriteLine("RESULT = " + TrxnResponse.Result);
        ///				Console.WriteLine("PNREF = " + TrxnResponse.Pnref);
        ///				Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
        ///				Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode);
        ///				Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr);
        ///				Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip);
        ///				Console.WriteLine("IAVS = " + TrxnResponse.IAVS);
        ///			}
        ///			// Get the Fraud Response parameters.
        ///			FraudResponse FraudResp =  Resp.FraudResponse;
        ///			if (FraudResp != null)
        ///			{
        ///				Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg);
        ///				Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg);
        ///			}
        ///		}
        ///		// Get the Context and check for any contained SDK specific errors.
        ///		Context Ctx = Resp.TransactionContext;
        ///		if (Ctx != null &amp;&amp; Ctx.getErrorCount() > 0)
        ///		{
        ///			Console.WriteLine(Environment.NewLine + "Errors = " + Ctx.ToString());
        ///		}
        ///</code>
        /// <code lang="Visual Basic" escaped="false">
        ///		............
        ///		'Trans is the transaction object.
        ///		............
        ///		' Submit the transaction.
        ///		Trans.SubmitTransaction()
        ///
        ///		' Get the Response.
        ///		Dim Resp As Response = Trans.Response
        ///
        ///		If Not Resp Is Nothing Then
        ///		' Get the Transaction Response parameters.
        ///
        ///			Dim TrxnResponse As TransactionResponse = Resp.TransactionResponse
        ///
        ///			If Not TrxnResponse Is Nothing Then
        ///				Console.WriteLine("RESULT = " + TrxnResponse.Result)
        ///				Console.WriteLine("PNREF = " + TrxnResponse.Pnref)
        ///				Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg)
        ///				Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode)
        ///				Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr)
        ///				Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip)
        ///				Console.WriteLine("IAVS = " + TrxnResponse.IAVS)
        ///			End If
        ///
        ///			' Get the Fraud Response parameters.
        ///			Dim FraudResp As FraudResponse = Resp.FraudResponse
        ///			If Not FraudResp Is Nothing Then
        ///				Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg)
        ///				Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg)
        ///			End If
        ///		End If
        ///
        ///		' Get the Context and check for any contained SDK specific errors.
        ///		Dim Ctx As Context = Resp.TransactionContext
        ///
        ///		If Not Ctx Is Nothing AndAlso Ctx.getErrorCount() > 0 Then
        ///			Console.WriteLine(Constants.vbLf + "Errors = " + Ctx.ToString())
        ///		End If
        /// </code>
        /// </example>
        public virtual Response SubmitTransaction()
        {
            PayflowNETAPI PfProNetApi   = null;
            String        ResponseValue = null;
            bool          Fatal         = false;

            Logger.Instance.Log("##### BEGIN TRANSACTION ##### -- " + mRequestId, PayflowConstants.SEVERITY_INFO);
            Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Entered", PayflowConstants.SEVERITY_DEBUG);
            try
            {
                if (mClientInfo == null)
                {
                    mClientInfo = new ClientInfo();
                }
                //Check for the errors in the context now.
                ArrayList Errors = PayflowUtility.AlignContext(mContext, false);
                mContext.LoadLoggerErrs = false;
                mContext.ClearErrors();
                mContext.AddErrors(Errors);

                if (mContext.HighestErrorLvl
                    == PayflowConstants.SEVERITY_FATAL)
                {
                    Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SEVERITY_DEBUG);
                    Fatal = true;
                }
                if (!Fatal)
                {
                    GenerateRequest();

                    mRequest = RequestBuffer.ToString();


                    //Remove the trailing PayflowConstants.DELIMITER_NVP;
                    int ParmListLen = mRequest.Length;
                    if (ParmListLen > 0 && mRequest[ParmListLen - 1] == '&')
                    {
                        mRequest = mRequest.Substring(0, ParmListLen - 1);
                    }


                    //Call the api from here and submit transaction

                    if (mPayflowConnectionData != null)
                    {
                        PfProNetApi = new PayflowNETAPI(mPayflowConnectionData.HostAddress,
                                                        mPayflowConnectionData.HostPort,
                                                        mPayflowConnectionData.TimeOut,
                                                        mPayflowConnectionData.ProxyAddress,
                                                        mPayflowConnectionData.ProxyPort,
                                                        mPayflowConnectionData.ProxyLogon,
                                                        mPayflowConnectionData.ProxyPassword);
                    }
                    else
                    {
                        PfProNetApi = new PayflowNETAPI();
                    }

                    PfProNetApi.IsStrongAssemblyTransaction = true;
                    PfProNetApi.ClientInfo = mClientInfo;
                    ResponseValue          = PfProNetApi.SubmitTransaction(mRequest, mRequestId);

                    Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SEVERITY_DEBUG);
                    Logger.Instance.Log("##### END TRANSACTION ##### -- " + mRequestId, PayflowConstants.SEVERITY_INFO);
                }
            }
            catch (BaseException BaseEx)
            {
                ErrorObject Error = BaseEx.GetFirstErrorInExceptionContext();
                //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_FATAL,false, null);
                mContext.AddError(Error);
            }
            catch (Exception Ex)
            {
                TransactionException TransEx = new TransactionException(Ex);
                ErrorObject          Error   = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, TransEx, PayflowConstants.SEVERITY_FATAL, false, null);
                mContext.AddError(Error);
            }
            finally
            {
                if (PfProNetApi != null)
                {
                    mRequest = PfProNetApi.TransactionRequest;
                    mContext.AddErrors(PfProNetApi.TransactionContext.GetErrors());
                    mRequestId  = PfProNetApi.RequestId;
                    mClientInfo = PfProNetApi.ClientInfo;
                }
                else
                {
                    //There is some error due to which the return
                    //is called even before pfpronetapi object is
                    //created.
                    //Check the first fatal error in context and
                    //put its response value to string.
                    if (mRequest != null && mRequest.Length > 0)
                    {
                        mRequest = PayflowUtility.MaskSensitiveFields(mRequest);
                    }
                    ArrayList   ErrorList       = mContext.GetErrors(PayflowConstants.SEVERITY_FATAL);
                    ErrorObject FirstFatalError = (ErrorObject)ErrorList[0];
                    ResponseValue = FirstFatalError.ToString();
                }

                mResponse = new Response(mRequestId, mContext);
                mResponse.setRequestString(mRequest);
                mResponse.SetParams(ResponseValue);


                //Log the context
                if (mContext.IsErrorContained())
                {
                    mContext.LogErrors();
                }
                PfProNetApi = null;
            }
            return(mResponse);
        }
Пример #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form != null && Request.Form.AllKeys.Count() > 0)
        {

            businessName = ConfigurationManager.AppSettings["BusinessName"];
            rawUrl = Request.RawUrl;
            string billaddress = Request.Form["Address"];
            invoice = Request.Form["InvoiceNumber"];
            string name = Request.Form["FirstName"] + " " + Request.Form["LastName"];
            string address = Request.Form["City"] + "," + Request.Form["State"] + "," + Request.Form["Country"] + "," + Request.Form["Zip"];
            string phno = Request.Form["PhoneNumber"];
            email = Request.Form["EmailAddress"];
            amt = Request.Form["Pleaseenteramount"];
            business = Request.Form["YourBusinessName"];
            if (!String.IsNullOrEmpty(email))
            {
                string PayPalRequest = "TRXTYPE=S" //S - sale transaction
              + "&TENDER=C" //C - Credit card
              + "&ACCT=" + Request.Form["ctl00$ctl00$MainContent$LeftContent$cardNumber"] //card number
               + "&EXPDATE=" + Request.Form["ctl00$ctl00$MainContent$LeftContent$cardMonth"] + Request.Form["ctl00$ctl00$MainContent$LeftContent$cardYear"].Substring(2, 2)
              + "&CVV2=" + Request.Form["ctl00$ctl00$MainContent$LeftContent$cardSecurityCode"]   //card validation value (card security code)
              + "&AMT=" + Request.Form["ctl00$ctl00$MainContent$LeftContent$ccAmount"]
              + "&COMMENT1=Payment for invoices"
              + "&FIRSTNAME=" + Request.Form["FirstName"]
              + "&LASTNAME=" + Request.Form["LastName"]
              + "&EMAIL=" + email
              + "&USER="******"USER"]
              + "&VENDOR=" + ConfigurationManager.AppSettings["VENDOR"]
              + "&PARTNER=" + ConfigurationManager.AppSettings["PARTNER"]
              + "&PWD=" + ConfigurationManager.AppSettings["PWD"];

                // Create an instantce of PayflowNETAPI.
                PayflowNETAPI PayflowNETAPI = new PayflowNETAPI();

                // RequestId is a unique string that is required for each & every transaction.
                // The merchant can use her/his own algorithm to generate this unique request id or
                // use the SDK provided API to generate this as shown below (PayflowUtility.RequestId).
                string PayPalResponse = PayflowNETAPI.SubmitTransaction(PayPalRequest, PayflowUtility.RequestId);

                //place data from PayPal into a namevaluecollection
                NameValueCollection RequestCollection = GetPayPalCollection(PayflowNETAPI.TransactionRequest);
                NameValueCollection ResponseCollection = GetPayPalCollection(PayPalResponse);

                string requestCollection = ShowPayPalInfo(RequestCollection);
                Session["RequestCollection"] = requestCollection;

                string responseCollection = ShowPayPalInfo(ResponseCollection);
                Session["ResponseCollection"] = responseCollection;

                //show transaction errors if any
                string TransErrors = PayflowNETAPI.TransactionContext.ToString();
                Session["TransErrors"] = TransErrors;
                Session["PayPalResponse"] = PayPalResponse;

                string status = PayflowUtility.GetStatus(PayPalResponse).ToString();
                ExceptionUtils.WriteTransactionMessage(ResponseCollection, status, email, business);
                 if (status == "Transaction Successful.")
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<HTML><BODY><Font face='Arial'>");
                    sb.Append("Hi " + business + ",<br><br>");
                    sb.Append("Thanks for prompt payment. We appreciate your business and look forward to continued business with you in the future.<br>");
                    sb.Append("If you have any questions please do not hesitate to contact our invoice team at <a href='mailto:[email protected]'>[email protected]</a>. we will be glad to help you.<br><br>");
                    sb.Append("<strong>PAYMENT DETAILS</strong>");
                    sb.Append("<TABLE><TR><TD>Transaction ID:</TD><TD>" + TransactionID(email) + "</TD></TR>");
                    sb.Append("<TR><TD>Business Name:</TD><TD>" + business + "</TD></TR>");
                    sb.Append("<TR><TD>Invoice Number:</TD><TD>" + invoice + "</TD></TR>");
                    sb.Append("<TR><TD>Amount:</TD><TD>" + amt + "</TD></TR>");
                    sb.Append("<TR><TD>Address:</TD><TD>" + billaddress + "," + address + "</TD></TR>");
                    sb.Append("<TR><TD>Phone Number:</TD><TD>" + phno + "</TD></TR>");
                    sb.Append("<TR><TD>Email:</TD><TD>" + email + "</TD></TR>");
                    sb.Append("</TABLE></Font></BODY></HTML>");

                     try
                     {
                         string subject = "Thank you - Ameex received Your Payment!";
                         Email(email, subject, sb.ToString(), "PaymentEmailTo".GetAppKeyString());
                     }
                     catch (Exception ex)
                     {
                         ExceptionUtils.WriteError(ex);
                     }
                }
                 else
                 {
                     StringBuilder sb = new StringBuilder();
                     sb.Append("<HTML><BODY><Font face='Arial'>");
                     sb.Append("Hi " + business + ",<br><br>");
                     sb.Append("We apologize that your recent transaction to Ameex has failed due to some technical reasons. The reasons for the failure are mentioned below. You can retry the payment through our <a href='https://ameexusa.com/Online-Payment/'>online payment page<a>. If you have any queries, please <a href='mailto:[email protected]'>contact our invoice team</a>. We are more than happy to help you.<br><br>");
                     sb.Append("<strong>PAYMENT DETAILS</strong>");
                     sb.Append("<TABLE><TR><TD>Transaction ID:</TD><TD>" + TransactionID(email) + "</TD></TR>");
                     sb.Append("<TR><TD>Business Name:</TD><TD>" + business + "</TD></TR>");
                     sb.Append("<TR><TD>Email ID:</TD><TD>" + email + "</TD></TR>");
                     sb.Append("<TR><TD>" + responseCollection + "</TD></TR>");
                     sb.Append("<TR><TD>" + TransErrors + "</TD></TR>");
                     sb.Append("</TABLE><br/>Regards,<br/>Accounts Team,<br/>Ameex Technologies Corp.<br/>1701 E Wood field Rd, Suite 710<br/>Schaumburg, IL 60173. USA.<br/></Font></BODY></HTML>");
                     try
                     {
                         string subject = "Your payment to Ameex is failed due to some technical reasons";
                         Email(email, subject, sb.ToString(), "PaymentEmailTo".GetAppKeyString());
                     }

                     catch (Exception ex)
                     {
                         ExceptionUtils.WriteError(ex);
                     }
                 }

                 if (status == "Transaction Successful.")
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<HTML><BODY><Font face='Arial'>");
                    sb.Append("Accounts Team,<br><br>");
                    sb.Append("We have received a new payment from " + business + ". Kindly verify and acknowledge.<br><br>");
                    sb.Append("<strong>PAYMENT DETAILS</strong>");
                    sb.Append("<TABLE><TR><TD>Transaction ID:</TD><TD>" + TransactionID(email) + "</TD></TR>");
                    sb.Append("<TR><TD>Business Name:</TD><TD>" + business + "</TD></TR>");
                    sb.Append("<TR><TD>Invoice Number:</TD><TD>" + invoice + "</TD></TR>");
                    sb.Append("<TR><TD>Amount:</TD><TD>" + amt + "</TD></TR>");
                    sb.Append("<TR><TD>Address:</TD><TD>" + billaddress + "," + address + "</TD></TR>");
                    sb.Append("<TR><TD>Phone Number:</TD><TD>" + phno + "</TD></TR>");
                    sb.Append("<TR><TD>Email:</TD><TD>" + email + "</TD></TR>");
                    sb.Append("</TABLE></Font></BODY></HTML>");

                    try
                    {
                        string subject = "Payment received from " + business;
                        Email("PaymentEmailTo".GetAppKeyString(), subject, sb.ToString(), "");
                    }
                    catch (Exception ex)
                    {
                        ExceptionUtils.WriteError(ex);
                    }
                }
                 else
                 {
                     StringBuilder sb = new StringBuilder();
                     sb.Append("<HTML><BODY><Font face='Arial'>");
                     sb.Append("Accounts Team,<br><br>");
                     sb.Append("A Client (" + business + ") has tried to make payment in our online portal, but failed. Please reach out to the client and assist in making the payment. The failed payment details are,<br><br>");
                     sb.Append("<strong>PAYMENT DETAILS</strong>");
                     sb.Append("<TABLE><TR><TD>Transaction ID:</TD><TD>" + TransactionID(email) + "</TD></TR>");
                     sb.Append("<TR><TD>Business Name:</TD><TD>" + business + "</TD></TR>");
                     sb.Append("<TR><TD>Email ID:</TD><TD>" + email + "</TD></TR>");
                     sb.Append("<TR><TD>" + responseCollection + "</TD></TR>");
                     sb.Append("<TR><TD>" + TransErrors + "</TD></TR>");
                     sb.Append("</TABLE></Font></BODY></HTML>");
                     try
                     {
                         string subject = "Transaction Failure for " + business;
                         Email("PaymentEmailTo".GetAppKeyString(), subject, sb.ToString(), "");
                     }
                     catch (Exception ex)
                     {
                         ExceptionUtils.WriteError(ex);
                     }
                 }
            }
        }
    }