コード例 #1
0
        // returns true if no errors, and card is enrolled:
        static public bool PreChargeLookup(string cardNumber,
                                           int cardExpirationYear,
                                           int cardExpirationMonth,
                                           int orderNumber,
                                           decimal orderTotal,
                                           string orderDescription,
                                           out string acsUrl,
                                           out string payload,
                                           out string transactionId,
                                           out string cardinalLookupResult)
        {
            var ccRequest     = new CardinalCommerce.CentinelRequest();
            var ccResponse    = new CardinalCommerce.CentinelResponse();
            var numAttempts   = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries");
            var callSucceeded = false;

            payload       = string.Empty;
            acsUrl        = String.Empty;
            transactionId = String.Empty;

            // ==================================================================================
            // Construct the cmpi_lookup message
            // ==================================================================================

            ccRequest.add("MsgType", AppLogic.AppConfig("CardinalCommerce.Centinel.MsgType.Lookup"));
            ccRequest.add("Version", "1.7");
            ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID"));
            ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID"));
            ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd"));
            ccRequest.add("TransactionType", "C");             //C = Credit Card / Debit Card Authentication.
            ccRequest.add("Amount", Localization.CurrencyStringForGatewayWithoutExchangeRate(orderTotal).Replace(",", "").Replace(".", ""));
            ccRequest.add("CurrencyCode", Localization.StoreCurrencyNumericCode());
            ccRequest.add("CardNumber", cardNumber);
            ccRequest.add("CardExpMonth", cardExpirationMonth.ToString().PadLeft(2, '0'));
            ccRequest.add("CardExpYear", cardExpirationYear.ToString().PadLeft(4, '0'));
            ccRequest.add("OrderNumber", orderNumber.ToString());

            // Optional fields
            ccRequest.add("OrderDescription", orderDescription);
            ccRequest.add("UserAgent", CommonLogic.ServerVariables("HTTP_USER_AGENT"));
            ccRequest.add("Recurring", "N");

            if (numAttempts == 0)
            {
                numAttempts = 1;
            }

            for (int i = 1; i <= numAttempts; i++)
            {
                callSucceeded = true;
                try
                {
                    var URL = AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive")
                                                ? AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live")
                                                : AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test");

                    ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout"));
                }
                catch
                {
                    callSucceeded = false;
                }
                if (callSucceeded)
                {
                    break;
                }
            }

            if (callSucceeded)
            {
                var errorNo  = ccResponse.getValue("ErrorNo");
                var enrolled = ccResponse.getValue("Enrolled");
                payload       = ccResponse.getValue("Payload");
                acsUrl        = ccResponse.getValue("ACSUrl");
                transactionId = ccResponse.getValue("TransactionId");

                cardinalLookupResult = ccResponse.getUnparsedResponse();

                ccRequest  = null;
                ccResponse = null;

                //======================================================================================
                // Assert that there was no error code returned and the Cardholder is enrolled in the
                // Payment Authentication Program prior to starting the Authentication process.
                //======================================================================================

                if (errorNo == "0" && enrolled == "Y")
                {
                    return(true);
                }
                return(false);
            }
            ccRequest            = null;
            ccResponse           = null;
            cardinalLookupResult = AppLogic.GetString("cardinal.cs.1", 1, Localization.GetDefaultLocale());
            return(false);
        }
コード例 #2
0
        static public bool MyECheckLookup(ShoppingCart cart, int OrderNumber, decimal OrderTotal, String OrderDescription, out String ACSUrl, out String Payload, out String TransactionID, out String CardinalLookupResult)
        {
            String MerchantID     = AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID");
            String ProcessorID    = AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID");
            String TransactionPwd = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd");

            if (MerchantID.Length == 0)
            {
                throw new ArgumentException("You MUST set AppConfig:CardinalCommerce.Centinel.MerchantID to a valid value.");
            }
            if (ProcessorID.Length == 0)
            {
                throw new ArgumentException("You MUST set AppConfig:CardinalCommerce.Centinel.ProcessorID to a valid value.");
            }
            if (TransactionPwd.Length == 0)
            {
                throw new ArgumentException("You MUST set AppConfig:CardinalCommerce.Centinel.TransactionPwd to a valid value.");
            }

            CardinalCommerce.CentinelRequest  ccRequest  = new CardinalCommerce.CentinelRequest();
            CardinalCommerce.CentinelResponse ccResponse = new CardinalCommerce.CentinelResponse();

            // ==================================================================================
            // Construct the cmpi_lookup message
            // ==================================================================================

            String IPAddress = cart.ThisCustomer.LastIPAddress;

            ccRequest.add("MsgType", "cmpi_lookup");
            ccRequest.add("Version", "1.7");
            ccRequest.add("MerchantId", MerchantID);
            ccRequest.add("ProcessorId", ProcessorID);
            ccRequest.add("TransactionPwd", TransactionPwd);
            ccRequest.add("TransactionType", "ME");
            ccRequest.add("Amount", Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal).Replace(",", "").Replace(".", ""));
            ccRequest.add("CurrencyCode", Localization.StoreCurrencyNumericCode());
            ccRequest.add("IPAddress", IPAddress);
            ccRequest.add("EMail", cart.ThisCustomer.EMail);
            ccRequest.add("OrderNumber", OrderNumber.ToString());
            ccRequest.add("OrderDescription", AppLogic.AppConfig("StoreName") + " Purchase");
            ccRequest.add("BillingFirstName", cart.ThisCustomer.PrimaryBillingAddress.FirstName);
            ccRequest.add("BillingLastName", cart.ThisCustomer.PrimaryBillingAddress.LastName);
            ccRequest.add("BillingAddress1", cart.ThisCustomer.PrimaryBillingAddress.Address1);
            ccRequest.add("BillingAddress2", cart.ThisCustomer.PrimaryBillingAddress.Address2);
            ccRequest.add("BillingCity", cart.ThisCustomer.PrimaryBillingAddress.City);
            ccRequest.add("BillingState", cart.ThisCustomer.PrimaryBillingAddress.State);
            ccRequest.add("BillingPostalCode", cart.ThisCustomer.PrimaryBillingAddress.Zip);
            ccRequest.add("BillingCountryCode", AppLogic.GetCountryTwoLetterISOCode(cart.ThisCustomer.PrimaryBillingAddress.Country));
            ccRequest.add("BillingPhone", cart.ThisCustomer.PrimaryBillingAddress.Phone.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", ""));


            int NumAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries");

            if (NumAttempts == 0)
            {
                NumAttempts = 1;
            }
            bool CallWasOK = false;

            for (int i = 1; i <= NumAttempts; i++)
            {
                CallWasOK = true;
                try
                {
                    String URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test");
                    if (AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive"))
                    {
                        URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live");
                    }
                    ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout"));
                }
                catch
                {
                    CallWasOK = false;
                }
                if (CallWasOK)
                {
                    break;
                }
            }

            Payload       = String.Empty;
            ACSUrl        = String.Empty;
            TransactionID = String.Empty;
            if (CallWasOK)
            {
                String errorNo   = ccResponse.getValue("ErrorNo");
                String errorDesc = ccResponse.getValue("ErrorDesc");
                String enrolled  = ccResponse.getValue("Enrolled");
                Payload       = ccResponse.getValue("Payload");
                ACSUrl        = ccResponse.getValue("ACSUrl");
                TransactionID = ccResponse.getValue("TransactionId");

                CardinalLookupResult = ccResponse.getUnparsedResponse();

                //======================================================================================
                // Assert that there was no error code returned and the Cardholder is enrolled in the
                // Payment Authentication Program prior to starting the Authentication process.
                //======================================================================================

                if (enrolled == "Y")
                {
                    return(true);
                }
                // write to Failed Transaction table
                String sql = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) values(" + cart.ThisCustomer.CustomerID.ToString() + "," + OrderNumber.ToString() + "," + DB.SQuote(IPAddress) + ",getdate(),'Cardinal'," + DB.SQuote(AppLogic.ro_PMCardinalMyECheck) + "," + DB.SQuote(ccRequest.getUnparsedRequest()) + "," + DB.SQuote(CardinalLookupResult) + ")";
                DB.ExecuteSQL(sql);
                ccRequest  = null;
                ccResponse = null;
                return(false);
            }
            CardinalLookupResult = AppLogic.GetString("cardinal.cs.6", 1, Localization.GetDefaultLocale());
            String sql2 = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) values(" + cart.ThisCustomer.CustomerID.ToString() + "," + OrderNumber.ToString() + "," + DB.SQuote(IPAddress) + ",getdate(),'Cardinal'," + DB.SQuote(AppLogic.ro_PMCardinalMyECheck) + "," + DB.SQuote(ccRequest.getUnparsedRequest()) + "," + DB.SQuote(CardinalLookupResult) + ")";

            DB.ExecuteSQL(sql2);
            ccRequest  = null;
            ccResponse = null;
            return(false);
        }