Exemple #1
0
        /// <summary>
        /// Authorizes the specified payment info.
        /// </summary>
        /// <param name="financialGateway"></param>
        /// <param name="paymentInfo">The payment info.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override FinancialTransaction Authorize(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage)
        {
            errorMessage = string.Empty;
            Response ppResponse = null;

            var invoice = GetInvoice(paymentInfo);
            var tender  = GetTender(paymentInfo);

            if (tender != null)
            {
                if (paymentInfo is ReferencePaymentInfo)
                {
                    var reference     = paymentInfo as ReferencePaymentInfo;
                    var ppTransaction = new ReferenceTransaction("Authorization", reference.TransactionCode, GetUserInfo(financialGateway), GetConnection(financialGateway), invoice, tender, PayflowUtility.RequestId);
                    ppResponse = ppTransaction.SubmitTransaction();
                }
                else
                {
                    var ppTransaction = new AuthorizationTransaction(GetUserInfo(financialGateway), GetConnection(financialGateway), invoice, tender, PayflowUtility.RequestId);
                    ppResponse = ppTransaction.SubmitTransaction();
                }
            }
            else
            {
                errorMessage = "Could not create tender from PaymentInfo";
            }

            if (ppResponse != null)
            {
                TransactionResponse txnResponse = ppResponse.TransactionResponse;
                if (txnResponse != null)
                {
                    if (txnResponse.Result == 0)   // Success
                    {
                        var transaction = new FinancialTransaction();
                        transaction.TransactionCode = txnResponse.Pnref;
                        return(transaction);
                    }
                    else
                    {
                        errorMessage = string.Format("[{0}] {1}", txnResponse.Result, txnResponse.RespMsg);
                    }
                }
                else
                {
                    errorMessage = "Invalid transaction response from the financial gateway";
                }
            }
            else
            {
                errorMessage = "Invalid response from the financial gateway.";
            }

            return(null);
        }
        public ActionResult PayOrder(int orderId)
        {                        
            var model = new PaymentFormModel();

            try
            {
                model.OrderId = orderId;

                var order = _orderService.GetOrderById(orderId);

                if (order == null || order.Deleted)
                    return View("~/Plugins/Payments.PayPalAdvanced/Views/PaymentPayPalAdvanced/PaymentForm.cshtml", model);

                if (_workContext.CurrentCustomer.Id != order.CustomerId)
                    return new HttpUnauthorizedResult();

                if (order.OrderStatus == OrderStatus.Cancelled || order.PaymentStatus != PaymentStatus.Pending)
                    return RedirectToRoute("OrderDetails", new { orderId = order.Id });

                                                                
                // Create a new Invoice data object with the Amount, Billing Address etc. details.
                Invoice inv = new Invoice();
                decimal orderTotal = 0.0M;

                try
                {                    
                    // Set Amount.
                    orderTotal = Math.Round(order.OrderTotal, 2);
                    PayPal.Payments.DataObjects.Currency amt = new PayPal.Payments.DataObjects.Currency(orderTotal);
                    inv.Amt = amt;                    
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create invoice amount: " + ex.Message);
                }

                inv.PoNum = order.Id.ToString();
                inv.InvNum = order.Id.ToString();

                try
                {
                    // Check license
                    bool isLicensed = this._licenseService.IsLicensed(HttpContext.Request.Url.Host);
                    if (!isLicensed && orderTotal > 5.00M)
                    {
                        return ShowLicenseInfo();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to verify plugin's license: " + ex.Message);
                }

                // Set the Billing Address details.
                BillTo billTo = new BillTo();

                // optional fields
                try
                {
                    billTo.FirstName = order.Customer.BillingAddress.FirstName;
                }
                catch { }
                try
                {
                    billTo.LastName = order.Customer.BillingAddress.LastName;
                }
                catch { }
                try
                {
                    billTo.Street = order.Customer.BillingAddress.Address1;
                }
                catch { }
                try
                {
                    billTo.City = order.Customer.BillingAddress.City;
                }
                catch { }
                try
                {
                    billTo.State = order.Customer.BillingAddress.StateProvince.Abbreviation;
                }
                catch { }
                try
                {
                    billTo.Zip = order.Customer.BillingAddress.ZipPostalCode;
                }
                catch { }
                try
                {
                    billTo.BillToCountry = order.Customer.BillingAddress.Country.NumericIsoCode.ToString();
                }
                catch { }

                inv.BillTo = billTo;

                // Set the Shipping Address details.
                //if (order.Customer.ShippingAddress != null)
                //{
                //    if (order.Customer.ShippingAddress.StateProvince != null && order.Customer.ShippingAddress.Country != null)
                //    {
                //        ShipTo shipTo = new ShipTo();
                //        shipTo.ShipToFirstName = order.Customer.ShippingAddress.FirstName;
                //        shipTo.ShipToLastName = order.Customer.ShippingAddress.LastName;
                //        shipTo.ShipToStreet = order.Customer.ShippingAddress.Address1;
                //        //shipTo.ShipToStreet2 = order.Customer.ShippingAddress.Address2;
                //        shipTo.ShipToCity = order.Customer.ShippingAddress.City;
                //        shipTo.ShipToState = order.Customer.ShippingAddress.StateProvince.Abbreviation;
                //        shipTo.ShipToZip = order.Customer.ShippingAddress.ZipPostalCode;
                //        shipTo.ShipToCountry = order.Customer.ShippingAddress.Country.NumericIsoCode.ToString();
                //        inv.ShipTo = shipTo;
                //    }
                //}


                // Create the Payflow Data Objects.
                // Create the User data object with the required user details.
                UserInfo payflowUser = null;
                try
                {
                    payflowUser = _payPalHelper.GetUserInfo();
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create Payflow User object, check the configuration: " + ex.Message);
                }

                // Create the Payflow Connection data object with the required connection details.                        
                PayflowConnectionData payflowConn = null;
                try
                {
                    payflowConn = new PayflowConnectionData(_payPalHelper.GetPayflowProHost());
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create Payflow connection, check the web.config: " + ex.Message);
                }

                string payflowRequestId = PayflowUtility.RequestId;
                Response resp;

                if (_payPalAdvancedPaymentSettings.TransactMode == TransactMode.Authorize)
                {
                    // Create a new Auth Transaction.
                    AuthorizationTransaction trans = null;
                    try
                    {
                        trans = new AuthorizationTransaction(payflowUser, payflowConn, inv, null, payflowRequestId);

                        trans.AddToExtendData(new ExtendData("CREATESECURETOKEN", "Y"));
                        trans.AddToExtendData(new ExtendData("SECURETOKENID", payflowRequestId));
                        if (_payPalAdvancedPaymentSettings.EnableMobileOptimizedLayout && this.IsMobileDevice())
                            trans.AddToExtendData(new ExtendData("TEMPLATE", "MOBILE"));

                        // Submit the Transaction
                        resp = trans.SubmitTransaction();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error processing AuthorizationTransaction: " + ex.Message);
                    }
                }
                else
                {
                    // Create a new Sale Transaction.
                    SaleTransaction trans = null;
                    try
                    {
                        trans = new SaleTransaction(payflowUser, payflowConn, inv, null, payflowRequestId);

                        trans.AddToExtendData(new ExtendData("CREATESECURETOKEN", "Y"));
                        trans.AddToExtendData(new ExtendData("SECURETOKENID", payflowRequestId));
                        if (_payPalAdvancedPaymentSettings.EnableMobileOptimizedLayout && this.IsMobileDevice())
                            trans.AddToExtendData(new ExtendData("TEMPLATE", "MOBILE"));

                        // Submit the Transaction
                        resp = trans.SubmitTransaction();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error processing SaleTransaction: " + ex.Message);
                    }
                }

                string paypalSecureToken = string.Empty;
                string paypalContent = string.Empty;

                // Process the Payflow response.
                if (resp != null)
                {
                    // Get the Transaction Response parameters.
                    TransactionResponse trxResp = resp.TransactionResponse;
                    if (trxResp != null)
                    {
                        if (trxResp.Result == 0)
                        {
                            paypalSecureToken = (from ExtendData edEntry in resp.ExtendDataList
                                                 where edEntry.ParamName == "SECURETOKEN"
                                                 select edEntry.ParamValue).FirstOrDefault();

                            model.PayflowSecureToken = paypalSecureToken.Trim();
                            model.PayflowSecureTokenId = payflowRequestId.Trim();
                            model.PayflowMode = _payPalAdvancedPaymentSettings.UseSandbox ? "TEST" : "LIVE";
                            model.PayflowUrl = _payPalHelper.GetPayflowLinkHost();
                            model.Success = true;
                        }
                        else
                        {
                            // Show error msg
                            model.ErrorMsg = string.Format("Error: {0} - {1}", trxResp.Result, trxResp.RespMsg != null ? trxResp.RespMsg : "");

                            // Log resp error
                            order.OrderNotes.Add(new OrderNote
                            {
                                Note = "Failed fetching PayPal Secure Token: " + model.ErrorMsg,
                                DisplayToCustomer = false,
                                CreatedOnUtc = DateTime.UtcNow
                            });

                            if (_orderService != null)
                            {
                                _orderService.UpdateOrder(order);
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                model.ErrorMsg = "An error has occurred, please check System Log for more information.";
            }                       
            
            return View("~/Plugins/Payments.PayPalAdvanced/Views/PaymentPayPalAdvanced/PaymentForm.cshtml", model);
        }
Exemple #3
0
        /// <summary>
        /// Authorizes the specified payment info.
        /// </summary>
        /// <param name="paymentInfo">The payment info.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override FinancialTransaction Authorize( PaymentInfo paymentInfo, out string errorMessage )
        {
            errorMessage = string.Empty;
            Response ppResponse = null;

            var invoice = GetInvoice( paymentInfo );
            var tender = GetTender( paymentInfo );

            if ( tender != null )
            {
                if ( paymentInfo is ReferencePaymentInfo )
                {
                    var reference = paymentInfo as ReferencePaymentInfo;
                    var ppTransaction = new ReferenceTransaction( "Authorization", reference.TransactionCode, GetUserInfo(), GetConnection(), invoice, tender, PayflowUtility.RequestId );
                    ppResponse = ppTransaction.SubmitTransaction();
                }
                else
                {
                    var ppTransaction = new AuthorizationTransaction( GetUserInfo(), GetConnection(), invoice, tender, PayflowUtility.RequestId );
                    ppResponse = ppTransaction.SubmitTransaction();
                }
            }
            else
            {
                errorMessage = "Could not create tender from PaymentInfo";
            }

            if ( ppResponse != null )
            {
                TransactionResponse txnResponse = ppResponse.TransactionResponse;
                if ( txnResponse != null )
                {
                    if ( txnResponse.Result == 0 ) // Success
                    {
                        var transaction = new FinancialTransaction();
                        transaction.TransactionCode = txnResponse.Pnref;
                        return transaction;
                    }
                    else
                    {
                        errorMessage = string.Format( "[{0}] {1}", txnResponse.Result, txnResponse.RespMsg );
                    }
                }
                else
                {
                    errorMessage = "Invalid transaction response from the financial gateway";
                }
            }
            else
            {
                errorMessage = "Invalid response from the financial gateway.";
            }

            return null;
        }
Exemple #4
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DOPartialAuth.cs");
            Console.WriteLine("------------------------------------------------------");

            // Refer to the DOSaleComplete.cs sample for a more detailed explaination of fields.
            //
            //Create the Data Objects.
            // Creates a CultureInfo for English in the U.S.
            // Not necessary, just here for example of using currency formatting.
            CultureInfo us         = new CultureInfo("en-US");
            String      usCurrency = "USD";

            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            // The PAYFLOW_HOST property is defined in the App config file.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Create a new Invoice data object with the Amount, Billing Address etc. details.
            Invoice Inv = new Invoice();

            // Set the amount and currency being used.
            // See the Developer's Guide for the list of the three-digit currency codes.
            // Refer to the Payflow Pro Developer's Guide on testing parameters for Partial Authorization.
            // In this example, sending $120.00 will generate a partial approval of only $100.00.

            Currency Amt = new Currency(new decimal(120.00), usCurrency);

            Inv.Amt    = Amt;
            Inv.PoNum  = "PO12345";
            Inv.InvNum = "INV12345";

            // Set the Billing Address details.
            BillTo Bill = new BillTo();

            Bill.BillToFirstName = "Sam";
            Bill.BillToLastName  = "Smith";
            Bill.BillToStreet    = "123 Main St.";
            Bill.BillToZip       = "12345";
            Inv.BillTo           = Bill;

            // Create a new Payment Device - Credit Card data object.
            // The input parameters are Credit Card Number and Expiration Date of the Credit Card.
            CreditCard CC = new CreditCard("5105105105105100", "0115");

            CC.Cvv2 = "123";

            // Create a new Tender - Card Tender data object.
            CardTender Card = new CardTender(CC);

            // Create a new Auth Transaction.
            AuthorizationTransaction Trans = new AuthorizationTransaction(User, Connection, Inv, Card, PayflowUtility.RequestId);

            // Set the flag to request that Partial Authorizations be accepted.
            Trans.PartialAuth = "Y";

            // You must set the transaction verbosity to HIGH to display the appropriate response.
            Trans.Verbosity = "HIGH";

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            if (Resp != null)
            {
                // Get the Transaction Response parameters.
                TransactionResponse TrxnResponse = Resp.TransactionResponse;

                // Refer to the Payflow Pro .NET API Reference Guide and the Payflow Pro Developer's Guide
                // for explanation of the items returned and for additional information and parameters available.
                if (TrxnResponse != null)
                {
                    Console.WriteLine("Transaction Response:");
                    Console.WriteLine("Result Code (RESULT) = " + TrxnResponse.Result);
                    Console.WriteLine("Transaction ID (PNREF) = " + TrxnResponse.Pnref);
                    // If the amount is partially authorized the RESPMSG will be "Partial Approval".
                    // If the amount is fully authorized the RESPMSG will be "Approved".
                    Console.WriteLine("Response Message (RESPMSG) = " + TrxnResponse.RespMsg);
                    Console.WriteLine("Authorization (AUTHCODE) = " + TrxnResponse.AuthCode);
                    Console.WriteLine("Street Address Match (AVSADDR) = " + TrxnResponse.AVSAddr);
                    Console.WriteLine("Streep Zip Match (AVSZIP) = " + TrxnResponse.AVSZip);
                    Console.WriteLine("International Card (IAVS) = " + TrxnResponse.IAVS);
                    Console.WriteLine("CVV2 Match (CVV2MATCH) = " + TrxnResponse.CVV2Match);
                    Console.WriteLine("------------------------------------------------------");
                    // These are all new items returned when VERBOSITY=HIGH.
                    Console.WriteLine("Credit Card Information:");
                    Console.WriteLine("Last 4-digits Credit Card Number (ACCT) = " + TrxnResponse.Acct);
                    if (TrxnResponse.CardType != null)
                    {
                        Console.Write("Card Type (CARDTYPE) = ");
                        switch (TrxnResponse.CardType)
                        {
                        case "0":
                            Console.WriteLine("Visa");
                            break;

                        case "1":
                            Console.WriteLine("MasterCard");
                            break;

                        case "2":
                            Console.WriteLine("Discover");
                            break;

                        case "3":
                            Console.WriteLine("American Express");
                            break;

                        case "4":
                            Console.WriteLine("Diner's Club");
                            break;

                        case "5":
                            Console.WriteLine("JCB");
                            break;

                        case "6":
                            Console.WriteLine("Maestro");
                            break;

                        default:
                            Console.WriteLine("Unknown: " + TrxnResponse.CardType);                                     // new or unknown card type
                            break;
                        }
                    }
                    Console.WriteLine("Expiration Date (EXPDATE) = " + TrxnResponse.ExpDate);
                    Console.WriteLine("Billing Name (FIRSTNAME, LASTNAME) = " + TrxnResponse.FirstName + " " + TrxnResponse.LastName);
                    Console.WriteLine("------------------------------------------------------");
                    Console.WriteLine("Verbosity Response:");
                    Console.WriteLine("Processor AVS (PROCAVS) = " + TrxnResponse.ProcAVS);
                    Console.WriteLine("Processor CSC (PROCCVV2) = " + TrxnResponse.ProcCVV2);
                    Console.WriteLine("Processor Result (HOSTCODE) = " + TrxnResponse.HostCode);
                    Console.WriteLine("Transaction Date/Time (TRANSTIME) = " + TrxnResponse.TransTime);

                    // For Partial Authorization you will need to check the following 3 items to see if the card was
                    // fully authorized or partially authorized.
                    //
                    // For example, if you send in a request of $120.00 (AMT=120.00) and the card only has $100.00 of available credit on it,
                    // the card will be authorized for $100.00, the AMT field will be changed from 120 to 100 (AMT=100.00 to reflect this.
                    // The balance of $20.00 which is still due will be returned in the BALAMT (BALAMT=-20.00) field and the ORIGAMT field
                    // will contain the original requested amount (ORIGAMT=120.00).
                    Console.WriteLine("------------------------------------------------------");
                    Console.WriteLine("Partial Payment Response:");
                    Console.WriteLine("Original Amount (ORIGAMT) = " + TrxnResponse.OrigAmt);
                    Console.WriteLine("Amount of Transaction (AMT) = " + TrxnResponse.Amt);
                    if (Convert.ToDecimal(TrxnResponse.BalAmt) == 0 & (Convert.ToDecimal(TrxnResponse.OrigAmt) > Convert.ToDecimal(TrxnResponse.Amt)))
                    {
                        decimal BalDue = Convert.ToDecimal(TrxnResponse.OrigAmt) - Convert.ToDecimal(TrxnResponse.Amt);
                        if (BalDue > 0)
                        {
                            // Seems a balance is still due, collect the difference.
                            Console.WriteLine("Please provide additional payment of: " + BalDue.ToString("c", us));
                        }
                        else if (BalDue == 0)
                        {
                            Console.WriteLine("Transaction is Paid in Full.");
                        }
                        else
                        {
                            // Card still has available balance on it.
                            Console.WriteLine("Balance Amount (BALAMT) = " + TrxnResponse.BalAmt);
                        }
                    }
                    Console.WriteLine("------------------------------------------------------");
                    Console.WriteLine("DUPLICATE = " + TrxnResponse.Duplicate);
                }

                // Display the response.
                Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));

                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
                }
            }
            Console.WriteLine(Environment.NewLine + "Press Enter to Exit ...");
            Console.ReadLine();
        }
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DOSecureTokenAuth.cs");
            Console.WriteLine("------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            // UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");


            // Create the Payflow  Connection data object with the required connection details.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Create a new Invoice data object with the Amount, Billing Address etc. details.
            Invoice Inv = new Invoice();

            // Set Amount.  The amount cannot be changed once submitted.
            Currency Amt = new Currency(new decimal(25.00), "USD");

            Inv.Amt    = Amt;
            Inv.InvNum = "INV12345";

            // Set the Billing Address details.  You can also send the shipping information.  Both the Billing
            // and Shipping information can be changed if the functionality is allowed in the Configuration section
            // of Manager.  No other information submitted using a secure token call can be changed.
            BillTo Bill = new BillTo();

            Bill.BillToFirstName = "Sam";
            Bill.BillToLastName  = "Smith";
            Bill.BillToStreet    = "123 Main St.";
            Bill.BillToCity      = "Anytown";
            Bill.BillToState     = "CA";
            Bill.BillToZip       = "12345";
            Bill.BillToPhone     = "408-123-1234";
            Bill.BillToEmail     = "*****@*****.**";
            Bill.BillToCountry   = "124";
            Inv.BillTo           = Bill;

            // Create a new Payment Device - Credit Card data object.
            // The input parameters are Credit Card Number and Expiration Date of the Credit Card.
            //CreditCard CC = new CreditCard("5105105105105100", "0110");
            //CC.Cvv2 = "023";

            // Create a new Tender - Card Tender data object.
            //CardTender Card = new CardTender(CC);
            ///////////////////////////////////////////////////////////////////

            // Since we are using the hosted payment pages, you will not be sending the credit card data with the
            // Secure Token Request.  You just send all other 'sensitive' data within this request and when you
            // call the hosted payment pages, you'll only need to pass the SECURETOKEN; which is generated and returned
            // and the SECURETOKENID that was created and used in the request.
            //
            // Create a new Secure Token Authorization Transaction.  Even though this example is performing
            // an authorization, you can create a secure token using SaleTransaction too.  Only Authorization and Sale
            // type transactions are permitted.
            //
            // Remember, all data submitted as part of the Secure Token call cannot be modified at a later time.  The only exception
            // is the billing and shipping information if these items are selection in the Setup section in PayPal Manager.
            AuthorizationTransaction Trans = new AuthorizationTransaction(User, Connection, Inv, null, PayflowUtility.RequestId);

            // Set VERBOSITY to High
            Trans.Verbosity = "High";

            // Set the flag to create a Secure Token.
            Trans.CreateSecureToken = "Y";
            // The Secure Token Id must be a unique id up to 36 characters.  Using the RequestID object to
            // generate a random id, but any means to create an id can be used.
            Trans.SecureTokenId = PayflowUtility.RequestId;

            // Set the extended data value.
            ExtendData ExtData = new ExtendData("SILENTTRAN", "True");

            // Add extended data to transaction.
            Trans.AddToExtendData(ExtData);

            // IMPORTANT NOTE:
            //
            // Remember, the Secure Token can only be used once.  Once it is redeemed by a valid transaction it cannot be used again and you will
            // need to generate a new token.  Also, the token has a life time of 30 minutes.

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            if (Resp != null)
            {
                // Get the Transaction Response parameters.
                TransactionResponse TrxnResponse = Resp.TransactionResponse;

                if (TrxnResponse != null)
                {
                    Console.WriteLine("RESULT = " + TrxnResponse.Result);
                    Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
                    Console.WriteLine("SECURETOKEN = " + TrxnResponse.SecureToken);
                    Console.WriteLine("SECURETOKENID = " + TrxnResponse.SecureTokenId);
                    // If value is true, then the Request ID has not been changed and the original response
                    // of the original transction is returned.
                    Console.WriteLine("DUPLICATE = " + TrxnResponse.Duplicate);
                }

                if (TrxnResponse.Result == 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction was successful.");
                    Console.WriteLine(Environment.NewLine + "The next step would be to redirect to PayPal to display the hosted");
                    Console.WriteLine("checkout page to allow your customer to select and enter payment.");
                    Console.WriteLine(Environment.NewLine + "This is only a simple example, which does not take into account things like");
                    Console.WriteLine(Environment.NewLine + "RETURN or SILENT POST URL, etc.");
                    Console.WriteLine(Environment.NewLine + "Press <Enter> to redirect to PayPal.");
                    Console.ReadLine();
                    // Simple way to pass token data to Payflow Link Servers.
                    String PayPalUrl = "https://payflowlink.paypal.com?securetoken=" + TrxnResponse.SecureToken + "&securetokenid=" + TrxnResponse.SecureTokenId + "&MODE=test&USER1=testuser1&ACCT=5105105105105100&EXPDATE=1212&CVV2=123";
                    //Process.Start(PayPalUrl);  // Open default browser.
                    Process.Start("iexplore.exe", PayPalUrl);
                    //Process.Start("C:\\Program Files\\Mozilla Firefox\\firefox.exe", PayPalUrl);
                }

                // Display the response.
                Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));

                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
                }
            }
            Console.WriteLine("Press Enter to Exit ...");
            Console.ReadLine();
        }
Exemple #6
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DOAuth.cs");
            Console.WriteLine("------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            // The PAYFLOW_HOST property is defined in the App config file.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Create a new Invoice data object with the Amount, Billing Address etc. details.
            Invoice Inv = new Invoice();

            // Set Amount.
            Currency Amt = new Currency(new decimal(10.00));

            Inv.Amt    = Amt;
            Inv.PoNum  = "PO12345";
            Inv.InvNum = "INV123415";

            // Set the Billing Address details.
            BillTo Bill = new BillTo();

            Bill.BillToFirstName = "Sam";
            Bill.BillToLastName  = "Smith";
            Bill.BillToStreet    = "123 Main St.";
            Bill.BillToZip       = "12345";
            Inv.BillTo           = Bill;

            // Create a new Payment Device - Credit Card data object.
            // The input parameters are Credit Card Number and Expiration Date of the Credit Card.
            CreditCard CC = new CreditCard("5105105105105100", "0125");

            CC.Cvv2 = "123";

            // Create a new Tender - Card Tender data object.
            CardTender Card = new CardTender(CC);

            // Create a new Auth Transaction.
            AuthorizationTransaction Trans = new AuthorizationTransaction(User, Connection, Inv, Card, PayflowUtility.RequestId);

            // Set the transaction verbosity to HIGH to display most details.
            Trans.Verbosity = "HIGH";
            Trans.AddTransHeader("PAYPAL-NVP", "Y");

            // Set the extended data value.
            ExtendData ExtData = new ExtendData("VERSION", "214.0");

            // Add extended data to transaction.
            Trans.AddToExtendData(ExtData);

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            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);
                    Console.WriteLine("CVV2MATCH = " + TrxnResponse.CVV2Match);
                    // If value is true, then the Request ID has not been changed and the original response
                    // of the original transaction is returned.
                    Console.WriteLine("DUPLICATE = " + TrxnResponse.Duplicate);
                }

                // Get the Fraud Response parameters.
                FraudResponse FraudResp = Resp.FraudResponse;

                // Display Fraud Response parameter
                if (FraudResp != null)
                {
                    Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg);
                    Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg);
                }

                // Display the response.
                Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));

                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
                }
            }

            Console.WriteLine("Press Enter to Exit ...");
            Console.ReadLine();
        }
Exemple #7
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("---------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DO_TeleCheck.cs");
            Console.WriteLine("---------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            // The PAYFLOW_HOST property is defined in the App config file.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Create a new Invoice data object with the Amount, Billing Address etc. details.
            Invoice Inv = new Invoice();

            // Set Amount.
            Currency Amt = new Currency(new decimal(25.12));

            Inv.Amt    = Amt;
            Inv.PoNum  = "PO12345";
            Inv.InvNum = "INV12345";

            // Set the Billing Address details.
            BillTo Bill = new BillTo();

            Bill.BillToStreet  = "123 Main St.";
            Bill.BillToZip     = "12345";
            Bill.BillToCity    = "New York";
            Bill.BillToState   = "PA";
            Bill.BillToZip     = "12345";
            Bill.BillToPhone   = "123-4546-7890";
            Bill.BillToEmail   = "*****@*****.**";
            Bill.BillToCountry = "US";
            Inv.BillTo         = Bill;

            // Set the IP address of the customer
            CustomerInfo custInfo = new CustomerInfo();

            custInfo.CustIP  = "111.111.11.111";
            Inv.CustomerInfo = custInfo;

            // Create a new Payment Device - Check Payment data object.
            // The input parameters is MICR. Magnetic Ink Check Reader. This is the entire line
            // of numbers at the bottom of all checks. It includes the transit number, account
            // number, and check number.
            CheckPayment ChkPayment = new CheckPayment("1234567804390850001234");

            // Name property needs to be set for the Check Payment.
            ChkPayment.Name = "Ivan Smith";
            // Create a new Tender - Check Tender data object.
            CheckTender ChkTender = new CheckTender(ChkPayment);

            // Account holder’s next unused (available) check number. Up to 7 characters.
            ChkTender.ChkNum = "1234";
            // DL or SS is required for a TeleCheck transaction.
            // If CHKTYPE=P, a value for either DL or SS must be passed as an identifier.
            // If CHKTYPE=C, the Federal Tax ID must be passed as the SS value.
            ChkTender.ChkType = "P";
            // Driver’s License number. If CHKTYPE=P, a value for either DL or SS must be passed as an identifier.
            // Format: XXnnnnnnnn
            // XX = State Code, nnnnnnnn = DL Number - up to 31 characters.
            ChkTender.DL = "CAN85452345";
            // Social Security number.  Needed if ChkType = P
            ChkTender.SS = "456765833";
            // AuthType = I-Internet Check, P-Checks by Phone, D-Prearranged Deposit
            ChkTender.AuthType = "I";

            // Create a new TeleCheck - Authorization Transaction.
            AuthorizationTransaction Trans = new AuthorizationTransaction(
                User, Connection, Inv, ChkTender, PayflowUtility.RequestId);

            //Want VERBOSITY=HIGH to get all the response values back.
            Trans.Verbosity = "HIGH";

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            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("HOSTCODE = " + TrxnResponse.HostCode);
                    Console.WriteLine("TRACEID = " + TrxnResponse.TraceId);
                    Console.WriteLine("ACHSTATUS = " + TrxnResponse.AchStatus);
                }
                // Display the response.
                Console.WriteLine(PayflowUtility.GetStatus(Resp) + Environment.NewLine);
                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine("Transaction Errors = " + TransCtx.ToString() + Environment.NewLine);
                }
                if (TrxnResponse.Result == 0)
                {
                    // Transaction approved, display acceptance verbiage, after consumer accepts, capture the
                    // transaction to finalize it.
                    CaptureTransaction capTrans = new CaptureTransaction(TrxnResponse.Pnref, User, Connection, null, ChkTender, PayflowUtility.RequestId);
                    // Set the transaction verbosity to HIGH to display most details.
                    capTrans.Verbosity = "HIGH";

                    // Submit the Transaction
                    Response capResp = capTrans.SubmitTransaction();

                    // Display the transaction response parameters.
                    if (capResp != null)
                    {
                        // Get the Transaction Response parameters.
                        TransactionResponse capTrxnResponse = capResp.TransactionResponse;
                        if (capTrxnResponse != null)
                        {
                            Console.WriteLine("RESULT = " + capTrxnResponse.Result);
                            Console.WriteLine("PNREF = " + capTrxnResponse.Pnref);
                            Console.WriteLine("RESPMSG = " + capTrxnResponse.RespMsg);
                            Console.WriteLine("HOSTCODE = " + capTrxnResponse.HostCode);
                            Console.WriteLine("TRACEID = " + capTrxnResponse.TraceId);
                        }
                        // Display the response.
                        Console.WriteLine(PayflowUtility.GetStatus(capResp) + Environment.NewLine);
                        // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                        Context capTransCtx = capResp.TransactionContext;
                        if (capTransCtx != null && capTransCtx.getErrorCount() > 0)
                        {
                            Console.WriteLine("Transaction Errors = " + capTransCtx.ToString() + Environment.NewLine);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unable to capture transaction as it declined or failed." + Environment.NewLine);
                    }
                }
            }
            Console.WriteLine("Press Enter to Exit ...");
            Console.ReadLine();
        }
Exemple #8
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DOSetEC.cs");
            Console.WriteLine("------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            // See the DoSaleComplete sample for more information on setting the Connection object.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Create the invoice object and set the amount value.
            Invoice Inv = new Invoice();

            Inv.Amt       = new Currency(new decimal(21.98), "USD");
            Inv.OrderDesc = "This is my Order Description";

            // **** PayPal Pay Later Service ****
            // PayPal Pay Later is a new, convenient, and secure service that allows you to offer your
            // customers promotional financing. Buyers that choose the promotional offer can defer
            // payments for purchases on participating merchant web sites, allowing them to shop now and
            // pay later.
            // The PayPal Pay Later service allows online merchants to offer promotional financing to
            // buyers at checkout - even if a buyer doesn't have a PayPal account. Promotional offers, such as
            // no payments for 90 days, give merchants new and powerful ways to market to online
            // shoppers.
            // The PayPal Pay Later service is issued by GE Money Bank, one of the world's leading
            // providers of consumer credit.
            // **** Signing Up for PayPal Pay Later ****
            // PayPal's new promotional financing is currently available to consumers and select merchants
            // in the U.S. If you are a merchant and would like to add this service, please contact your sales
            // representative for information and additional documentation.
            //
            //PayLater setPayLater = new PayLater();
            //setPayLater.ShippingMethod = "UPSGround";
            //setPayLater.ProductCategory = "E"; // Camera and Photos
            //setPayLater.PayPalCheckoutBtnType = "P";
            // You can combine up to 10 promotions for PayPal Promotional Financing.
            // L_PROMOCODE0
            //PayLaterLineItem setPayLaterLineItem = new PayLaterLineItem();
            //setPayLaterLineItem.PromoCode = "101";
            //setPayLater.PayLaterAddLineItem(setPayLaterLineItem);
            // L_PROMOCODE1
            //PayLaterLineItem setPayLaterLineItem1 = new PayLaterLineItem();
            //setPayLaterLineItem1.PromoCode = "102";
            //setPayLater.PayLaterAddLineItem(setPayLaterLineItem1);

            // **** Performing a Standard Transaction using Express Checkout ****
            //
            // Express Checkout offers your customers an easy, convenient checkout experience. It lets them
            // use shipping and billing information stored securely at PayPal to check out, so they don’t have
            // to re-enter it on your site.
            //
            // From the perspective of website development, Express Checkout works like other Payflow Pro
            // features. You submit transaction information to the server as name-value pair parameter
            // strings.
            //
            // Create the data object for Express Checkout SET operation using ECSetRequest Data Object.
            ECSetRequest SetRequest = new ECSetRequest("http://www.myreturnurl.com", "http://www.mycancelurl.com");

            // If using Pay Later, you would create the data object as below.
            //ECSetRequest setRequest = new ECSetRequest("http://www.myreturnurl.com", "http://www.mycancelurl.com", setPayLater);

            // **** Performing a Reference Transaction using Express Checkout ****
            //
            // NOTE: You must be enabled by PayPal to use reference transactions. Contact your account manager
            // or the sales department for more details.
            //
            // See the "Using Reference Transactions with Express Checkout" guide that is supplied to you
            // once your account is active with the feature.

            // *** With Making a Purchase ***
            // Say that you have implemented Express Checkout on your website. The customer logs in to
            // purchase an item of merchandise and chooses PayPal to pay for it. In the normal Express
            // Checkout flow, the customer is then redirected to PayPal to log in to verify their billing
            // information. If the customer approves payment on the Confirmation page when you are using
            // a reference transaction, you receive the billing agreement as part of the transaction.You can
            // use that billing agreement later to bill the customer a set amount on a recurring basis, such as
            // once-a-month, for future purchases. The customer doesn’t need to log into PayPal each time to
            // make a payment.
            //
            // Create the data object for Express Checkout Reference Transaction SET operation
            // with Purchase using ECSetRequest Data Object.
            //ECSetRequest SetRequest = new ECSetRequest("http://www.myreturnurl.com", "http://www.mycancelurl.com",
            //		"MerchantInitiatedBilling", "Test Description", "any", "BACustom");

            // *** Without Making a Purchase ***
            // Typically, the customer chooses a billing agreement without making a purchase when they
            // subscribe for merchandise they will pay for on a recurring schedule. If, for example, the
            // customer logs in to your website to order a magazine subscription, you set up an agreement to
            // bill the customer on a scheduled basis, say, once a month. In the billing agreement flow
            // without purchase, the customer is redirected to PayPal to log in. On the PayPal site, they
            // consent to the billing agreement. Next month, when you send the customer the first magazine
            // issue, the billing agreement authorizes you to start charging the customer’s PayPal account on
            // the agreed upon recurring basis without having the customer log in to PayPal.
            //
            // Create the data object for Express Checkout Reference Transaction SET operation
            // without Purchase using ECSetBARequest Data Object.
            //ECSetBARequest SetRequest = new ECSetBARequest("http://www.myreturnurl.com", "http://www.mycancelurl.com",
            //		"MerchantInitiatedBilling", "Test Description", "any", "BACustom");

            // Create the Tender object.
            PayPalTender Tender = new PayPalTender(SetRequest);

            // Create the transaction object.
            AuthorizationTransaction Trans = new AuthorizationTransaction
                                                 (User, Connection, Inv, Tender, PayflowUtility.RequestId);

            // Create an Order Transaction.  An Order transaction represents an agreement to pay one or more
            // authorized amounts up to the specified total over a maximum of 29 days.
            // Refer to the Express Checkout for Payflow Pro Developer's Guide regarding Orders.
            //OrderTransaction Trans = new OrderTransaction(User, Connection, Inv, Tender, PayflowUtility.RequestId);

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            if (Resp != null)
            {
                // Get the Transaction Response parameters.
                TransactionResponse TrxnResponse = Resp.TransactionResponse;

                if (TrxnResponse != null)
                {
                    Console.WriteLine("RESULT = " + TrxnResponse.Result.ToString());
                    Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
                    Console.WriteLine("TOKEN = " + Trans.Response.ExpressCheckoutSetResponse.Token);
                    Console.WriteLine("CORRELATIONID = " + TrxnResponse.CorrelationId);
                    // If value is true, then the Request ID has not been changed and the original response
                    // of the original transction is returned.
                    Console.WriteLine("DUPLICATE = " + TrxnResponse.Duplicate);
                }

                if (TrxnResponse.Result == 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction was Approved.");
                    Console.WriteLine(Environment.NewLine + "The next step would be to redirect to PayPal to allow customer to log");
                    Console.WriteLine("into their account to select payment.  For this demo, DO NOT CLOSE the browser");
                    Console.WriteLine("as you will need the TOKEN and/or PAYER ID from the URL for the GET and DO");
                    Console.WriteLine("samples.");
                    Console.WriteLine(Environment.NewLine + "Make sure you are logged into Developer Central (https://developer.paypal.com) before continuing.");
                    Console.WriteLine(Environment.NewLine + "Press <Enter> to redirect to PayPal.");
                    Console.ReadLine();

                    // Using the PayPal SandBox for Express Checkout:
                    // Before you can use the PayPal Sandbox with a Gateway account you'll need to do the following:
                    // To setup a PayPal Sandbox account to work with a Payflow Pro account you will need to go to
                    // https://developer.paypal.com and create an account.  Once you have access to the Sandbox then
                    // you will be able to set up test business accounts, premier accounts and personal accounts.  Please
                    // set up a test business account and personal account so you can test Express Checkout.
                    //
                    // Once you have a test business account created, create a ticket at http://www.paypal.com/mts
                    // under Contact Support and request to have your Payflow Pro (US, AU) or Websites Payments Pro
                    // Payflow Edition (UK) account modified to use the PayPal Sandbox.  Provide the e-mail ID you
                    // used when you created your account on the Sandbox.
                    //
                    // Once you are notified that your account has been updated you will then need to modify the host
                    // URLs of the Payflow Pro Express Checkout test servers to the URLs used by the Sandbox.
                    // For example, https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<token>.

                    // If the SET operation succeeds, you will get a secure session token id in the response of this
                    // operation.  Using this token, redirect the user's browser as follows:

                    // For Regular Express Checkout or Express Checkout (Reference) with Purchase.
                    String PayPalUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";

                    // For Express Checkout (Reference) without Purchase.
                    //String PayPalUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_customer-billing-agreement&token=";

                    PayPalUrl += Trans.Response.ExpressCheckoutSetResponse.Token;
                    //Process.Start(PayPalUrl);  // Open default browser.
                    //Process.Start("iexplore.exe", PayPalUrl);
                    Process.Start("C:\\Program Files\\Mozilla Firefox\\firefox.exe", PayPalUrl);
                }

                // Display the response.
                Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));

                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
                }
            }
            Console.WriteLine("Press <Enter> to Exit ...");
            Console.ReadLine();
        }
Exemple #9
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DOSecureTokenAuth.cs");
            Console.WriteLine("------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Create a new Invoice data object with the Amount, Billing Address etc. details.
            Invoice Inv = new Invoice();

            // Set Amount.  The amount cannot be changed once submitted.
            Currency Amt = new Currency(new decimal(10.00), "USD");

            Inv.Amt    = Amt;
            Inv.InvNum = "INV12345";

            // Set the Billing Address details.  You can also send the shipping information.  Both the Billing
            // and Shipping information can be changed if the functionality is allowed in the Configuration section
            // of Manager.  No other information submitted using a secure token call can be changed.
            BillTo Bill = new BillTo();

            Bill.BillToFirstName = "Sam";
            Bill.BillToLastName  = "Smith";
            Bill.BillToStreet    = "123 Main St.";
            Bill.BillToCity      = "Any Town";
            Bill.BillToState     = "CA";
            Bill.BillToZip       = "12345";
            Bill.BillToPhone     = "408-123-1234";
            Bill.BillToEmail     = "*****@*****.**";
            Bill.BillToCountry   = "840";
            Inv.BillTo           = Bill;

            // Create a new Payment Device - Credit Card data object.
            // The input parameters are Credit Card Number and Expiration Date of the Credit Card.
            //CreditCard CC = new CreditCard("5105105105105100", "0110");
            //CC.Cvv2 = "023";

            // Create a new Tender - Card Tender data object.
            //CardTender Card = new CardTender(CC);
            ///////////////////////////////////////////////////////////////////

            // Since we are using the hosted payment pages, you will not be sending the credit card data with the
            // Secure Token Request.  You just send all other 'sensitive' data within this request and when you
            // call the hosted payment pages, you'll only need to pass the SECURETOKEN; which is generated and returned
            // and the SECURETOKENID that was created and used in the request.
            //
            // Create a new Secure Token Authorization Transaction.  Even though this example is performing
            // an authorization, you can create a secure token using SaleTransaction too.  Only Authorization and Sale
            // type transactions are permitted.
            //
            // Remember, all data submitted as part of the Secure Token call cannot be modified at a later time.  The only exception
            // is the billing and shipping information if these items are selection in the Setup section in PayPal Manager.
            AuthorizationTransaction Trans = new AuthorizationTransaction(User, Connection, Inv, null, PayflowUtility.RequestId);

            // Set VERBOSITY to High
            Trans.Verbosity = "High";

            // Set the flag to create a Secure Token.
            Trans.CreateSecureToken = "Y";

            // The Secure Token Id must be a unique id up to 36 characters.  Using the RequestID object to
            // generate a random id, but any means to create an id can be used.
            Trans.SecureTokenId = PayflowUtility.RequestId;

            // Set the extended data value.
            //ExtendData ExtData = new ExtendData("SILENTTRAN", "True");
            // Add extended data to transaction.
            //Trans.AddToExtendData(ExtData);

            // IMPORTANT NOTE:
            //
            // Remember, the Secure Token can only be used once.  Once it is redeemed by a valid transaction it cannot be used again and you will
            // need to generate a new token.  Also, the token has a life time of 30 minutes.

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            Console.WriteLine(DateTime.Now.ToString("hh:mm:ss tt") + " : " + Trans.Response.ResponseString);
            Console.WriteLine("Press Enter to Exit ...");
            Console.ReadLine();
        }
Exemple #10
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DOGetEC.cs");
            Console.WriteLine("------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Calling a GET operation is second step in PayPal Express checkout process. Once the
            // customner has logged into his/her paypal account, selected shipping address and clicked on
            // "Continue checkout", the PayPal server will redirect the page to the ReturnUrl you have
            // specified in the previous SET request.  To obtain the shipping details chosen by the
            // Customer, you will then need to do a GET operation.
            //
            // For more information on Reference Transactions, see the DOSetEC Sample for more details.

            // For Regular Express Checkout or Express Checkout Reference Transaction with Purchase.
            ECGetRequest GetRequest = new ECGetRequest("<TOKEN>");

            // For Express Checkout Reference Transaction without Purchase.
            //ECGetBARequest GetRequest = new ECGetBARequest("<TOKEN>");

            // Create the Tender.
            PayPalTender Tender = new PayPalTender(GetRequest);

            // Create a transaction.
            AuthorizationTransaction Trans = new AuthorizationTransaction
                                                 (User, Connection, null, Tender, PayflowUtility.RequestId);

            // Submit the Transaction
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            if (Resp != null)
            {
                // Get the Transaction Response parameters.
                TransactionResponse TrxnResponse = Resp.TransactionResponse;

                if (TrxnResponse != null)
                {
                    Console.WriteLine("RESULT = " + TrxnResponse.Result.ToString());
                    Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
                    // The TOKEN is needed for the DODoEC Sample.
                    Console.WriteLine("TOKEN = " + Trans.Response.ExpressCheckoutSetResponse.Token);
                    Console.WriteLine("CORRELATIONID = " + TrxnResponse.CorrelationId);
                    Console.WriteLine("EMAIL = " + Trans.Response.ExpressCheckoutGetResponse.EMail);
                    // The PAYERID is needed for the DODoEC Sample.
                    Console.WriteLine("PAYERID = " + Trans.Response.ExpressCheckoutGetResponse.PayerId);
                    Console.WriteLine("PAYERSTATUS = " + Trans.Response.ExpressCheckoutGetResponse.PayerStatus);
                    // Express Checkout Transactions and Express Checkout Reference Transactions with Purchase
                    // begin with EC, while Express Checkout Reference Transactions without Purchase begin with BA.
                    // Reference Transactions without Purchase do not return shipping information.
                    if (Trans.Response.ExpressCheckoutSetResponse.Token != null)
                    {
                        if (Trans.Response.ExpressCheckoutSetResponse.Token.StartsWith("EC"))
                        {
                            Console.WriteLine(Environment.NewLine + "Shipping Information:");
                            Console.WriteLine("FIRST = " + Trans.Response.ExpressCheckoutGetResponse.FirstName);
                            Console.WriteLine("LAST = " + Trans.Response.ExpressCheckoutGetResponse.LastName);
                            Console.WriteLine("SHIPTOSREET = " + Trans.Response.ExpressCheckoutGetResponse.ShipToStreet);
                            Console.WriteLine("SHIPTOSTREET2 = " + Trans.Response.ExpressCheckoutGetResponse.ShipToStreet2);
                            Console.WriteLine("SHIPTOCITY = " + Trans.Response.ExpressCheckoutGetResponse.ShipToCity);
                            Console.WriteLine("SHIPTOSTATE = " + Trans.Response.ExpressCheckoutGetResponse.ShipToState);
                            Console.WriteLine("SHIPTOZIP = " + Trans.Response.ExpressCheckoutGetResponse.ShipToZip);
                            Console.WriteLine("SHIPTOCOUNTRY = " + Trans.Response.ExpressCheckoutGetResponse.ShipToCountry);
                            Console.WriteLine("AVSADDR = " + Trans.Response.TransactionResponse.AVSAddr);
                        }
                        // BA_Flag is returned with Express Checkout Reference Transaction with Purchase.
                        // See the notes in DOSetEC regarding this feature.
                        if (Trans.Response.ExpressCheckoutGetResponse.BA_Flag != null)
                        {
                            Console.WriteLine(Environment.NewLine + "BA_FLAG = " + Trans.Response.ExpressCheckoutGetResponse.BA_Flag);
                            if (Trans.Response.ExpressCheckoutGetResponse.BA_Flag == "1")
                            {
                                Console.WriteLine("Buyer Agreement was created.");
                            }
                            else
                            {
                                Console.WriteLine("Buyer Agreement not was accepted.");
                            }
                        }
                    }

                    // If value is true, then the Request ID has not been changed and the original response
                    // of the original transction is returned.
                    Console.WriteLine(Environment.NewLine + "DUPLICATE = " + TrxnResponse.Duplicate);
                }

                // Display the response.
                Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));

                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
                }
            }
            Console.WriteLine("Press Enter to Exit ...");
            Console.ReadLine();
        }
Exemple #11
0
        public static void Main(string[] Args)
        {
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("Executing Sample from File: DODoEC.cs");
            Console.WriteLine("------------------------------------------------------");

            // Create the Data Objects.
            // Create the User data object with the required user details.
            UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

            // Create the Payflow  Connection data object with the required connection details.
            // The PAYFLOW_HOST property is defined in the App config file.
            PayflowConnectionData Connection = new PayflowConnectionData();

            // Once the customer has reviewed the shipping details and decides to continue
            // checkout by clicking on "Continue Checkout" button, it's time to actually
            // authorize the transaction.
            // This is the third step in PayPal Express Checkout, in which you need to perform a
            // DO operation to authorize the purchase amount.
            //
            // For more information on Reference Transactions, see the DOSetEC Sample for more details.

            // For Regular Express Checkout or Express Checkout Reference Transaction with Purchase.
            ECDoRequest DoRequest = new ECDoRequest("<TOKEN>", "<PAYERID>");

            // For Express Checkout Reference Transaction without Purchase.
            //ECDoBARequest DoRequest = new ECDoBARequest("<TOKEN>", "<PAYERID>");

            // Performing a Reference Transaction, Credit Transaction, Do Authorization or a Reauthorization
            // These transactions do not require a token or payerid.  Additional fields
            // are set using the ExtendData, ECDoRequest or AuthorizationTransaction objects, see below.
            //ECDoRequest DoRequest = new ECDoRequest("", "");

            // Perform a Do Reauthorization
            // To reauthorize an Authorization for an additional three-day honor period, you can use a Do
            // Reauthorization transaction. A Do Reauthorization can be used at most once during the 29-day
            // authorization period.
            // To set up a Do Reauthorization, you must pass ORIGID in the AuthorizationTransaction object
            // and set DoReauthorization to 1.
            //DoRequest.DoReauthorization("1");

            // Populate Invoice object.
            Invoice Inv = new Invoice();

            Inv.Amt      = new Currency(new decimal(21.98), "USD");
            Inv.Comment1 = "Testing Express Checkout";

            // **** PayPal Pay Later Service ****
            // See DoSetEC.vb for information on PayPal's Pay Later Service.

            // Create the Tender object.
            PayPalTender Tender = new PayPalTender(DoRequest);

            // Create the transaction object.
            AuthorizationTransaction Trans = new AuthorizationTransaction(User, Connection, Inv, Tender, PayflowUtility.RequestId);

            // Doing a credit?
            //CreditTransaction Trans = new CreditTransaction(User, Connection, Inv, Tender, PayflowUtility.RequestId);

            // Using a Reference Transaction
            // To be able to "charge" a customer using their Billing Agreement you will need to pass the BAID
            // and other parameters via the ExtendData Object.
            //ExtendData BAId = new ExtendData("BAID", "<BAID>");
            //Trans.AddToExtendData(BAId);
            //ExtendData CaptureComplete = new ExtendData("CAPTURECOMPLETE", "NO");
            //Trans.AddToExtendData(CaptureComplete);
            //ExtendData MaxAmt = new ExtendData("MAXAMT", "15.00");
            //Trans.AddToExtendData(MaxAmt);

            // Perform a Do Authorization or Do Reauthorization
            // You must pass ORIGID using the PNREF of the original order transaction.
            //Trans.OrigId("<PNREF>");

            // Submit the transaction.
            Response Resp = Trans.SubmitTransaction();

            // Display the transaction response parameters.
            if (Resp != null)
            {
                // Get the Transaction Response parameters.
                TransactionResponse TrxnResponse = Resp.TransactionResponse;

                if (TrxnResponse != null)
                {
                    Console.WriteLine("RESULT = " + TrxnResponse.Result);
                    Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
                    Console.WriteLine("PNREF = " + TrxnResponse.Pnref);
                    Console.WriteLine("PPREF = " + TrxnResponse.PPref);
                    Console.WriteLine("TOKEN = " + Trans.Response.ExpressCheckoutSetResponse.Token);
                    Console.WriteLine("CORRELATIONID = " + TrxnResponse.CorrelationId);
                    Console.WriteLine("PAYERID = " + Trans.Response.ExpressCheckoutGetResponse.PayerId);
                    Console.WriteLine("PAYMENTTYPE = " + Trans.Response.TransactionResponse.PaymentType);
                    Console.WriteLine("PENDINGREASON = " + Trans.Response.TransactionResponse.PendingReason);

                    // BAID is returned with Express Checkout Reference Transaction with and without Purchase.
                    // See the notes in DOSetEC regarding this feature.
                    if (Trans.Response.ExpressCheckoutDoResponse.BAId != null)
                    {
                        Console.WriteLine(Environment.NewLine + "BAID = " + Trans.Response.ExpressCheckoutDoResponse.BAId);
                    }

                    // If value is true, then the Request ID has not been changed and the original response
                    // of the original transction is returned.
                    Console.WriteLine(Environment.NewLine + "DUPLICATE = " + TrxnResponse.Duplicate);
                }

                // Display the response.
                Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));

                // Get the Transaction Context and check for any contained SDK specific errors (optional code).
                Context TransCtx = Resp.TransactionContext;
                if (TransCtx != null && TransCtx.getErrorCount() > 0)
                {
                    Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
                }
            }
            Console.WriteLine("Press Enter to Exit ...");
            Console.ReadLine();
        }
Exemple #12
0
        public PaymentResponse BusinessCheckPayment(BusinessCheckPaymentRequest req)
        {
            var     resp      = new PaymentResponse();
            Invoice Inv       = new Invoice();
            var     RequestID = PayflowUtility.RequestId;
            PayflowConnectionData Connection = new PayflowConnectionData(Host, Port, Timeout, "", 0, "", "");
            int  trxCount = 1;
            bool RespRecd = false;

            Currency Amt = new Currency(req.Amount);

            Amt.NoOfDecimalDigits = 0;
            Inv.Amt      = Amt;
            Inv.InvNum   = req.InvoiceNumber;
            Inv.Comment1 = req.Comment;

            // Create the BillTo object.
            Inv.BillTo = CreateBillTo(req.BillingInformation);

            // Create Credit Card data object.
            var payment = new PayPal.Payments.DataObjects.CheckPayment(req.RoutingNumber + req.AccountNumber + req.CheckNumber);

            // Create Card Tender data object.
            var tender = new CheckTender(payment)
            {
                ChkType = "C",
                SS      = req.EIN_SSN,
                ChkNum  = req.CheckNumber
            };


            UserInfo TeleCheckUser = new UserInfo(User, Vendor, Partner, Password);

            // Notice we set the request id earlier in the application and outside our loop.  This way if a response was not received
            // but PayPal processed the original request, you'll receive the original response with DUPLICATE set.
            AuthorizationTransaction Trans = new AuthorizationTransaction(TeleCheckUser, Connection, Inv, tender, RequestID);

            Trans.AddToExtendData(new ExtendData("AUTHTYPE", "I"));
            Trans.AddToExtendData(new ExtendData("CUSTIP", req.IPAddress));

            Trans.Verbosity = String.IsNullOrEmpty(Verbosity)? "HIGH" : Verbosity;


            while (trxCount <= 3 && !RespRecd)
            {
                Response Resp = Trans.SubmitTransaction();
                if (Resp != null)
                {
                    RespRecd = true;  // Got a response.
                    TransactionResponse TrxnResponse = Resp.TransactionResponse;
                    if (TrxnResponse != null)
                    {
                        resp = ProcessTransaction(TrxnResponse);
                    }
                }
                else
                {
                    trxCount++;
                }
            }

            if (!RespRecd)
            {
                resp.Success = false;
                resp.Message = "Payment not processed.  Please contact Customer Service";
            }

            return(resp);
        }