Example #1
0
 public override string ProcessCard(
     int orderNumber,
     int customerId,
     decimal orderTotal,
     bool useLiveTransactions,
     TransactionModeEnum transactionMode,
     AspDotNetStorefrontCore.Address billingAddress,
     string cardExtraCode,
     AspDotNetStorefrontCore.Address shippingAddress,
     string cavv,
     string eci,
     string xid,
     out string avsResult,
     out string authorizationResult,
     out string authorizationCode,
     out string authorizationTransId,
     out string transactionCommandOut,
     out string transactionResponse)
 {
     return(AcceptJsProcessCardOrECheck(
                customerId,
                orderTotal,
                useLiveTransactions,
                transactionMode,
                out avsResult,
                out authorizationResult,
                out authorizationCode,
                out authorizationTransId,
                out transactionCommandOut,
                out transactionResponse));
 }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        int      selectedAddressId = int.Parse(BillingAddresses.SelectedValue);
        SkinBase page = HttpContext.Current.Handler as SkinBase;

        AspDotNetStorefrontCore.Customer adnsfCustomer = AspDotNetStorefrontCore.Customer.Current;

        string errorMessage, errorCode;

        this.PaymentProfileId = ProcessTools.SaveProfileAndPaymentProfile(adnsfCustomer.CustomerID, adnsfCustomer.EMail, AspDotNetStorefrontCore.AppLogic.AppConfig("StoreName"), this.PaymentProfileId, selectedAddressId, TextCreditCard.Text, TextCardSecurity.Text, ExpirationMonth.SelectedValue, ExpirationYear.SelectedValue, out errorMessage, out errorCode);

        if (PaymentProfileId <= 0)
        {
            ShowError(String.Format("{0} {1}", AspDotNetStorefrontCore.AppLogic.GetString("AspDotNetStorefrontGateways.AuthorizeNet.Cim.ErrorMessage", adnsfCustomer.SkinID, adnsfCustomer.LocaleSetting), errorMessage));
            return;
        }

        if (CBMakePrimaryCard.Checked)
        {
            AspDotNetStorefrontCore.Address adnsfAddress = new AspDotNetStorefrontCore.Address();
            adnsfAddress.LoadFromDB(selectedAddressId);
            adnsfAddress.MakeCustomersPrimaryAddress(AspDotNetStorefrontCore.AddressTypes.Billing);
            DataUtility.SetPrimaryPaymentProfile(adnsfCustomer.CustomerID, this.PaymentProfileId);
        }

        BindPage(this.PaymentProfileId);

        FireCardEditComplete();
    }
Example #3
0
        protected void dlAddress_DeleteCommand(object sender, DataListCommandEventArgs e)
        {
            int         addressID   = 0;
            HiddenField hfAddressID = e.Item.FindControl("hfAddressID") as HiddenField;

            if (hfAddressID != null && Int32.TryParse(hfAddressID.Value, out addressID))
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                anyAddress.LoadFromDB(addressID);

                if (ThisCustomer.CustomerID == anyAddress.CustomerID || ThisCustomer.IsAdminSuperUser)
                {
                    AspDotNetStorefrontCore.Address.DeleteFromDB(anyAddress.AddressID, ThisCustomer.CustomerID);
                }
            }
            dlAddress.EditItemIndex = -1;
            LoadData();
        }
Example #4
0
        /// <summary>
        /// Delete Customer Address by addressID
        /// </summary>
        /// <param name="addressID">addressID</param>
        private void DeleteAddress(int addressID)
        {
            try
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();
                anyAddress.LoadFromDB(addressID);

                if (ThisCustomer.CustomerID == anyAddress.CustomerID || ThisCustomer.IsAdminSuperUser)
                {
                    AspDotNetStorefrontCore.Address.DeleteFromDB(anyAddress.AddressID, ThisCustomer.CustomerID);
                }

                LoadAddresses(GetAddressType(Request.QueryString["AddressType"]));
            }
            catch (Exception ex)
            {
                SysLog.LogMessage(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " :: " + System.Reflection.MethodBase.GetCurrentMethod().Name,
                                  ex.Message + ((ex.InnerException != null && string.IsNullOrEmpty(ex.InnerException.Message)) ? " :: " + ex.InnerException.Message : ""),
                                  MessageTypeEnum.GeneralException, MessageSeverityEnum.Error);
            }
        }
Example #5
0
        public override string ProcessCard(
            int orderNumber,
            int customerId,
            decimal orderTotal,
            bool useLiveTransactions,
            TransactionModeEnum transactionMode,
            AspDotNetStorefrontCore.Address billingAddress,
            string cardExtraCode,
            AspDotNetStorefrontCore.Address useShippingAddress,
            string CAVV,
            string ECI,
            string XID,
            out string AVSResult,
            out string authorizationResult,
            out string authorizationCode,
            out string authorizationTransId,
            out string transactionCommandOut,
            out string transactionResponse)
        {
            AVSResult             = string.Empty;
            authorizationResult   = string.Empty;
            authorizationCode     = string.Empty;
            authorizationTransId  = string.Empty;
            transactionCommandOut = string.Empty;
            transactionResponse   = string.Empty;

            try
            {
                if (AppConfigProvider.GetAppConfigValue("Localization.StoreCurrency") != "AUD" &&
                    AppConfigProvider.GetAppConfigValue("Localization.StoreCurrency") != "NZD")
                {
                    return("eWAY requires that the store currency be either AUD or NZD.");
                }

                var cardDetails = new CardDetails()
                {
                    Name        = $"{billingAddress.FirstName} {billingAddress.LastName}",
                    Number      = billingAddress.CardNumber,
                    ExpiryMonth = FormatExpiryMonth(billingAddress.CardExpirationMonth),
                    ExpiryYear  = FormatExpiryYear(billingAddress.CardExpirationYear),
                    CVN         = cardExtraCode
                };

                var address = new eWAY.Rapid.Models.Address()
                {
                    Street1    = billingAddress.Address1,
                    Street2    = billingAddress.Address2,
                    City       = billingAddress.City,
                    State      = billingAddress.State,
                    PostalCode = billingAddress.Zip,
                    Country    = AppLogic.GetCountryTwoLetterISOCode(billingAddress.Country),
                };

                var customer = new eWAY.Rapid.Models.Customer()
                {
                    FirstName   = billingAddress.FirstName,
                    LastName    = billingAddress.LastName,
                    Email       = billingAddress.EMail,
                    Phone       = billingAddress.Phone,
                    CardDetails = cardDetails,
                    Address     = address
                };

                var paymentDetails = new PaymentDetails()
                {
                    TotalAmount   = DecimalToFixedPoint(orderTotal),
                    InvoiceNumber = orderNumber.ToString(),
                    CurrencyCode  = Currency.GetDefaultCurrency()
                };

                var transaction = new Transaction()
                {
                    Customer        = customer,
                    PaymentDetails  = paymentDetails,
                    TransactionType = TransactionTypes.Purchase,
                    Capture         = transactionMode == TransactionModeEnum.authcapture
                                                ? true
                                                : false
                };

                transactionCommandOut = SanitizeTransaction(
                    XmlCommon.SerializeObject(transaction, transaction.GetType()),
                    new Dictionary <string, string>()
                {
                    { $">{billingAddress.CardNumber}</", $">{AppLogic.SafeDisplayCardNumber(billingAddress.CardNumber, "Orders", 0)}</" },
                    { $">{cardExtraCode}</", ">***</" },
                });

                var response = GetRapidClient()
                               .Create(PaymentMethod.Direct, transaction);

                if (response.TransactionStatus == null)
                {
                    return("Error calling payment gateway.");
                }

                transactionResponse = XmlCommon.SerializeObject(response, response.GetType());

                authorizationResult = response.TransactionStatus.ProcessingDetails?.ResponseMessage;

                if ((response.TransactionStatus.Status ?? false) == false)
                {
                    var errorCode = string.IsNullOrWhiteSpace(authorizationResult) &&
                                    response.Errors != null
                                                ? string.Join(" ", response.Errors)
                                                : authorizationResult;

                    return($"There was a problem processing the credit card transaction.  Error code: {errorCode}");
                }

                AVSResult            = response.TransactionStatus.VerificationResult?.CVN.ToString();
                authorizationCode    = response.TransactionStatus.ProcessingDetails.AuthorisationCode;
                authorizationTransId = response.TransactionStatus.TransactionID.ToString();
            }
            catch (Exception exception)
            {
                SysLog.LogException(exception, MessageTypeEnum.GeneralException, MessageSeverityEnum.Error);
                return("Error calling payment gateway.");
            }

            return(AppLogic.ro_OK);
        }
Example #6
0
        public override string RefundOrder(
            int orderNumber,
            int newOrderNumber,
            decimal refundAmount,
            string refundReason,
            AspDotNetStorefrontCore.Address billingAddress)
        {
            try
            {
                using (var connection = DB.dbConn())
                {
                    connection.Open();

                    DB.ExecuteSQL("update orders set refundtxcommand = null, refundtxresult = null where ordernumber = @orderNumber",
                                  connection,
                                  new SqlParameter("@orderNumber", orderNumber));

                    var authorizationPnref = string.Empty;
                    var totalAmount        = refundAmount;

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "select authorizationpnref, ordertotal from orders with (nolock) where ordernumber = @orderNumber";
                        command.Parameters.AddWithValue("@orderNumber", orderNumber);

                        using (var rs = command.ExecuteReader())
                        {
                            if (rs.Read())
                            {
                                authorizationPnref = DB.RSField(rs, "AuthorizationPNREF");
                                var orderTotal = DB.RSFieldDecimal(rs, "OrderTotal");
                                totalAmount = refundAmount > orderTotal ? orderTotal : refundAmount;
                            }
                        }
                    }

                    if (orderNumber == 0)
                    {
                        return($"There was a problem refunding the credit card transaction.  Order {orderNumber} not found.");
                    }

                    var refundDetails = new RefundDetails();
                    refundDetails.InvoiceNumber         = orderNumber.ToString();
                    refundDetails.OriginalTransactionID = Convert.ToInt32(authorizationPnref);
                    refundDetails.TotalAmount           = DecimalToFixedPoint(totalAmount);
                    refundDetails.CurrencyCode          = Currency.GetDefaultCurrency();

                    var refund = new Refund();
                    refund.InvoiceDescription = refundReason;
                    refund.RefundDetails      = refundDetails;

                    DB.ExecuteSQL("update orders set refundtxcommand = @refundTxCommand where ordernumber = @orderNumber",
                                  connection,
                                  new SqlParameter("@refundTxCommand", XmlCommon.SerializeObject(refund, refund.GetType())),
                                  new SqlParameter("@orderNumber", orderNumber));

                    var response = GetRapidClient()
                                   .Refund(refund);

                    if (!(response.TransactionStatus ?? false))
                    {
                        var errorCode = string.IsNullOrWhiteSpace(response.ResponseMessage) &&
                                        response.Errors != null
                                                                ? string.Join(" ", response.Errors)
                                                                : response.ResponseMessage;

                        return($"There was a problem refunding the credit card transaction.  Error code: { errorCode }.");
                    }

                    DB.ExecuteSQL("update orders set RefundTXResult = @refundTxResult where OrderNumber = @orderNumber",
                                  connection,
                                  new SqlParameter("@refundTxResult", XmlCommon.SerializeObject(response, response.GetType())),
                                  new SqlParameter("@orderNumber", orderNumber));
                }
            }
            catch (Exception exception)
            {
                SysLog.LogException(exception, MessageTypeEnum.GeneralException, MessageSeverityEnum.Error);
                return("Error calling payment gateway.");
            }

            return(AppLogic.ro_OK);
        }
Example #7
0
        public override String ProcessCard(int OrderNumber, int CustomerID, Decimal OrderTotal, bool useLiveTransactions, TransactionModeEnum TransactionMode, AspDotNetStorefrontCore.Address UseBillingAddress, String CardExtraCode, AspDotNetStorefrontCore.Address UseShippingAddress, String CAVV, String ECI, String XID, out String AVSResult, out String AuthorizationResult, out String AuthorizationCode, out String AuthorizationTransID, out String TransactionCommandOut, out String TransactionResponse)
        {
            AVSResult             = "N/A";
            AuthorizationResult   = "N/A";
            AuthorizationCode     = "N/A";
            AuthorizationTransID  = "N/A";
            TransactionCommandOut = "N/A";
            TransactionResponse   = String.Empty;

            String signedPARes = String.Empty;
            String result      = AppLogic.ro_OK;

            CustomerSession cSession = new CustomerSession(CustomerID);

            if (cSession["3Dsecure.PaRes"].Length != 0)
            {
                signedPARes = cSession["3Dsecure.PaRes"];
                // After grabbing it, clear out the session PaRes so it won't be re-used ever again.
                cSession["3Dsecure.PaRes"] = String.Empty;
            }

            Configuration conf = new Configuration();

            conf.KeysDirectory = AppLogic.AppConfig("CYBERSOURCE.keysDirectory");
            conf.KeyFilename   = AppLogic.AppConfig("CYBERSOURCE.keyFilename");
            conf.MerchantID    = AppLogic.AppConfig("CYBERSOURCE.merchantID");
            conf.ServerURL     = CommonLogic.IIF(useLiveTransactions, AppLogic.AppConfig("CYBERSOURCE.LiveURL"), AppLogic.AppConfig("CYBERSOURCE.TestURL"));
            if (AppLogic.AppConfigBool("CYBERSOURCE.UsePIT"))
            {
                conf.ServerURL = AppLogic.AppConfig("CYBERSOURCE.PITURL");
            }


            RequestMessage request = new RequestMessage();

            request.clientApplication        = "AspDotNetStorefront";
            request.clientApplicationVersion = AppLogic.AppConfig("StoreVersion");
            request.clientApplicationUser    = CustomerID.ToString();

            request.merchantReferenceCode = "Order # " + OrderNumber.ToString() + " " + Localization.ToNativeDateTimeString(System.DateTime.Now);

            int  CardTypeID  = DB.GetSqlN("select CardTypeID N from CreditCardType where CardType = " + DB.SQuote(UseBillingAddress.CardType));
            bool Try3DSecure = CommonLogic.IntegerIsInIntegerList(CardTypeID, AppLogic.AppConfig("3DSECURE.CreditCardTypeIDs"));

            if (Try3DSecure)
            {
                if (signedPARes == String.Empty)
                {
                    request.payerAuthEnrollService     = new PayerAuthEnrollService();
                    request.payerAuthEnrollService.run = "true";
                    if (AppLogic.AppConfig("CYBERSOURCE.paCountryCode") != "")
                    {
                        request.payerAuthEnrollService.countryCode = AppLogic.AppConfig("CYBERSOURCE.paCountryCode");
                    }
                    if (AppLogic.AppConfig("CYBERSOURCE.paMerchantName") != "")
                    {
                        request.payerAuthEnrollService.merchantName = AppLogic.AppConfig("CYBERSOURCE.paMerchantName");
                    }
                    if (AppLogic.AppConfig("CYBERSOURCE.paMerchantURL") != "")
                    {
                        request.payerAuthEnrollService.merchantURL = AppLogic.AppConfig("CYBERSOURCE.paMerchantURL");
                    }
                    request.payerAuthEnrollService.httpAccept    = CommonLogic.ServerVariables("HTTP_ACCEPT");
                    request.payerAuthEnrollService.httpUserAgent = CommonLogic.ServerVariables("HTTP_USER_AGENT");
                }
                else
                {
                    request.payerAuthValidateService             = new PayerAuthValidateService();
                    request.payerAuthValidateService.signedPARes = signedPARes;
                    request.payerAuthValidateService.run         = "true";
                }
            }

            request.ccAuthService     = new CCAuthService();
            request.ccAuthService.run = "true";

            if (CAVV.Trim().Length != 0)
            {     // only gets set as a result of 3D Secure processing
                if (GetCardTypeFieldValue(UseBillingAddress.CardType) == "002")
                { // for MasterCard
                    request.ccAuthService.xid  = XID;
                    request.ccAuthService.cavv = CAVV;
                }
            }

            request.merchantID = AppLogic.AppConfig("CYBERSOURCE.merchantID");

            if (TransactionMode == TransactionModeEnum.authcapture)
            {
                request.ccCaptureService     = new CCCaptureService();
                request.ccCaptureService.run = "true";
            }

            BillTo billTo = new BillTo();

            billTo.firstName   = UseBillingAddress.FirstName;
            billTo.lastName    = UseBillingAddress.LastName;
            billTo.company     = UseBillingAddress.Company;
            billTo.street1     = UseBillingAddress.Address1;
            billTo.street2     = UseBillingAddress.Address2;
            billTo.city        = UseBillingAddress.City;
            billTo.state       = UseBillingAddress.State;
            billTo.postalCode  = UseBillingAddress.Zip;
            billTo.country     = AppLogic.GetCountryTwoLetterISOCode(UseBillingAddress.Country);
            billTo.phoneNumber = UseBillingAddress.Phone.PadRight(6, '1');
            billTo.email       = CommonLogic.IIF(UseBillingAddress.EMail.Length > 2, UseBillingAddress.EMail, "*****@*****.**");
            billTo.ipAddress   = CommonLogic.CustomerIpAddress();
            request.billTo     = billTo;

            if (UseShippingAddress != null)
            {
                ShipTo ShipTo = new ShipTo();
                ShipTo.firstName   = UseShippingAddress.FirstName;
                ShipTo.lastName    = UseShippingAddress.LastName;
                ShipTo.company     = UseShippingAddress.Company;
                ShipTo.street1     = UseShippingAddress.Address1;
                ShipTo.street2     = UseShippingAddress.Address2;
                ShipTo.city        = UseShippingAddress.City;
                ShipTo.state       = UseShippingAddress.State;
                ShipTo.postalCode  = UseShippingAddress.Zip;
                ShipTo.country     = AppLogic.GetCountryTwoLetterISOCode(UseShippingAddress.Country);
                ShipTo.phoneNumber = UseShippingAddress.Phone.PadRight(6, '1');
                ShipTo.email       = CommonLogic.IIF(UseShippingAddress.EMail.Length > 2, UseShippingAddress.EMail, "*****@*****.**");
                request.shipTo     = ShipTo;
            }

            Card card = new Card();

            card.accountNumber = UseBillingAddress.CardNumber;
            if (CardExtraCode.Trim().Length != 0)
            {
                card.cvIndicator = "1";
                card.cvNumber    = CardExtraCode;
            }
            else
            {
                card.cvIndicator = "0";
            }

            if (!String.IsNullOrEmpty(UseBillingAddress.CardStartDate) && UseBillingAddress.CardStartDate != "00")
            {
                card.startMonth = UseBillingAddress.CardStartDate.Substring(0, 2);
                card.startYear  = UseBillingAddress.CardStartDate.Substring(4, 2);
            }

            if (UseBillingAddress.CardIssueNumber.Length != 0)
            {
                card.issueNumber = UseBillingAddress.CardIssueNumber;
            }
            card.expirationMonth = UseBillingAddress.CardExpirationMonth;
            card.expirationYear  = UseBillingAddress.CardExpirationYear;

            if (Try3DSecure)
            {
                card.cardType = GetCardTypeFieldValue(UseBillingAddress.CardType);
                if (card.cardType == "000")
                {
                    return(" Error in configuration. Card type " + UseBillingAddress.CardType + " is not recognized by the gateway.");
                }
            }

            request.card = card;

            request.item = new Item[1];
            Item the_item = new Item();

            the_item.id        = "0";
            the_item.unitPrice = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal);
            request.item[0]    = the_item;

            PurchaseTotals ptotal = new PurchaseTotals();

            ptotal.currency         = Localization.StoreCurrency();                                         // Currency REQUIRED
            ptotal.grandTotalAmount = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal); // Not needed - can use instead of item price, I think it's better..
            request.purchaseTotals  = ptotal;                                                               // Neccessary

            result = "ERROR: ";


            try
            {
                ReplyMessage reply = SoapClient.RunTransaction(conf, request);

                if (Try3DSecure && request.payerAuthEnrollService != null)
                {
                    if (request.payerAuthEnrollService.run == "true")
                    { // we have some data that needs stored
                        string LookupResult = String.Empty;
                        if (reply.payerAuthEnrollReply != null &&
                            reply.payerAuthEnrollReply.paReq != null &&
                            reply.payerAuthEnrollReply.paReq.Length > 0)
                        { // will be null if card not enrolled
                            // the paReq comes back encoded, Streamline requires it to be decoded.
                            string sPAReq = CommonLogic.UnzipBase64DataToString(reply.payerAuthEnrollReply.paReq);
                            LookupResult += "paReq=" + XmlCommon.PrettyPrintXml(sPAReq) + System.Environment.NewLine;
                        }
                        if (reply.payerAuthEnrollReply != null &&
                            reply.payerAuthEnrollReply.proofXML != null)
                        {
                            /****************************************************************
                            *  Store the complete proofXML whenever it is                  *
                            *  returned. If you ever need to show proof of                 *
                            *  enrollment checking, you will need to parse the string      *
                            *  for the information required by the card association.       *
                            ****************************************************************/
                            LookupResult += "proofXML data =";
                            LookupResult += System.Environment.NewLine + XmlCommon.PrettyPrintXml(reply.payerAuthEnrollReply.proofXML);
                        }
                        if (LookupResult != String.Empty)
                        { // encode it to store in the session, it will be decoded before being saved to the database
                            byte[] str = Encoding.UTF8.GetBytes(LookupResult);
                            cSession["3DSecure.LookupResult"] = Convert.ToBase64String(str);
                        }
                    }
                }

                if (reply.decision == "REJECT" && reply.reasonCode == "475")
                { // card enrolled, must perform 3D Secure processing (reasonCode == 475)
                    cSession["3DSecure.CustomerID"]  = CustomerID.ToString();
                    cSession["3DSecure.OrderNumber"] = OrderNumber.ToString();
                    cSession["3DSecure.MD"]          = OrderNumber.ToString();
                    cSession["3DSecure.ACSUrl"]      = reply.payerAuthEnrollReply.acsURL;
                    cSession["3DSecure.paReq"]       = reply.payerAuthEnrollReply.paReq;
                    cSession["3DSecure.XID"]         = reply.payerAuthEnrollReply.xid;
                    cSession.UpdateCustomerSession(null, null);
                    result = AppLogic.ro_3DSecure; // This is what triggers the 3D Secure IFRAME to be used.
                    return(result);
                }

                if (reply.decision == "ACCEPT" || reply.decision == "REVIEW")
                {
                    result = AppLogic.ro_OK;
                    if (AppLogic.TransactionModeIsAuthCapture())
                    {
                        AVSResult            = reply.ccAuthReply.avsCode;
                        AuthorizationResult  = reply.ccCaptureReply.reasonCode;
                        AuthorizationCode    = reply.ccAuthReply.authorizationCode;
                        AuthorizationTransID = reply.requestID;
                    }
                    else
                    {
                        AVSResult            = reply.ccAuthReply.avsCode;
                        AuthorizationResult  = reply.reasonCode;
                        AuthorizationCode    = reply.ccAuthReply.authorizationCode;
                        AuthorizationTransID = reply.requestID;
                    }
                    if (signedPARes.Length > 0)
                    {
                        if (reply.payerAuthValidateReply != null)
                        {
                            if (reply.payerAuthValidateReply.ucafAuthenticationData != null)
                            { // MasterCard SecureCode
                                AuthorizationResult += System.Environment.NewLine + "CAVV: " + reply.payerAuthValidateReply.ucafAuthenticationData;
                                AuthorizationResult += System.Environment.NewLine + "ECI: " + reply.payerAuthValidateReply.ucafCollectionIndicator;
                            }
                            else
                            { // Visa VBV
                                AuthorizationResult += System.Environment.NewLine + "CAVV: " + reply.payerAuthValidateReply.cavv;
                                AuthorizationResult += System.Environment.NewLine + "ECI: " + reply.payerAuthValidateReply.eci;
                            }
                        }
                        AuthorizationResult += System.Environment.NewLine + "signedPARes: ";
                        // Streamline requires saving the decoded PARes to the database
                        string sPARes = CommonLogic.UnzipBase64DataToString(signedPARes);

                        // zap the signature since it is long and we don't need it
                        String t1  = "<Signature ";
                        String t2  = "</Signature>";
                        String sig = t1 + CommonLogic.ExtractToken(sPARes, t1, t2) + t2;
                        AuthorizationResult += System.Environment.NewLine + XmlCommon.PrettyPrintXml(sPARes.Replace(sig, ""));
                    }
                }
                else
                {
                    result = "Your transaction was NOT approved, reason code: " + reply.reasonCode + ". ";
                    if (reply.reasonCode == "476" && reply.payerAuthValidateReply != null)
                    {
                        result += reply.payerAuthValidateReply.authenticationStatusMessage
                                  + ". Please try another payment method.";
                    }

                    else
                    {
                        result += GetReasonCodeDescription(reply.reasonCode);

                        if (reply.missingField != null)
                        {
                            foreach (string fieldname in reply.missingField)
                            {
                                result += "[" + fieldname + "]";
                            }
                        }

                        if (reply.invalidField != null)
                        {
                            foreach (string fieldname in reply.invalidField)
                            {
                                result += "[" + fieldname + "]";
                            }
                        }
                    }
                }
            }
            catch (SignException se)
            {
                result += "Error calling Cybersource gateway. Please retry your order in a few minutes or select another checkout payment option. "
                          + String.Format("Failed to sign the request with error code {0} and message {1}.", DB.SQuote(se.ErrorCode.ToString()), DB.SQuote(se.Message));
            }
            catch (SoapHeaderException she)
            {
                result += String.Format("A SOAP header exception was returned with fault code {0} and message {1}.", DB.SQuote(she.Code.ToString()), DB.SQuote(she.Message));
            }
            catch (SoapBodyException sbe)
            {
                result += String.Format("A SOAP body exception was returned with fault code {0} and message {1}.", DB.SQuote(sbe.Code.ToString()), DB.SQuote(sbe.Message));
            }
            catch (WebException we)
            {
                result += String.Format("Failed to get a response with status {0} and mmessage {1}", DB.SQuote(we.Status.ToString()), DB.SQuote(we.Message));
            }
            catch (Exception ex)
            {
                // See requirements at the top of this file.
                result += "Error calling Cybersource gateway. Please retry your order in a few minutes or select another checkout payment option.";
                result += " Error message: Make sure the required components for Cybersource are installed on the server. " + ex.Message;
                result += " <> " + ex.ToString();
            }
            return(result);
        }
Example #8
0
        // if RefundAmount == 0.0M, then then ENTIRE order amount will be refunded!
        public override string RefundOrder(int OriginalOrderNumber, int NewOrderNumber, decimal RefundAmount, String RefundReason, AspDotNetStorefrontCore.Address UseBillingAddress)
        {
            var result = AppLogic.ro_OK;

            DB.ExecuteSQL("update orders set RefundTXCommand=NULL, RefundTXResult=NULL where OrderNumber=" + OriginalOrderNumber.ToString());
            var TransID     = string.Empty;
            var CustomerID  = 0;
            var TotalAmount = 0.0M;

            using (var con = new SqlConnection(DB.GetDBConn()))
            {
                con.Open();
                using (var rs = DB.GetRS("select AuthorizationPNREF,OrderTotal,CustomerID from orders   with (NOLOCK)  where OrderNumber=" + OriginalOrderNumber.ToString(), con))
                {
                    if (rs.Read())
                    {
                        TransID     = DB.RSField(rs, "AuthorizationPNREF");
                        TotalAmount = DB.RSFieldDecimal(rs, "OrderTotal");
                        CustomerID  = DB.RSFieldInt(rs, "CustomerID");
                    }
                }
            }

            var conf = new Configuration();

            conf.KeysDirectory = AppLogic.AppConfig("CYBERSOURCE.keysDirectory");
            conf.KeyFilename   = AppLogic.AppConfig("CYBERSOURCE.keyFilename");
            conf.MerchantID    = AppLogic.AppConfig("CYBERSOURCE.merchantID");
            conf.ServerURL     = CommonLogic.IIF(AppLogic.AppConfigBool("UseLiveTransactions"), AppLogic.AppConfig("CYBERSOURCE.LiveURL"), AppLogic.AppConfig("CYBERSOURCE.TestURL"));
            if (AppLogic.AppConfigBool("CYBERSOURCE.UsePIT"))
            {
                conf.ServerURL = AppLogic.AppConfig("CYBERSOURCE.PITURL");
            }

            RequestMessage request = new RequestMessage();

            request.clientApplication        = "AspDotNetStorefront";
            request.clientApplicationVersion = AppLogic.AppConfig("StoreVersion");
            request.clientApplicationUser    = CustomerID.ToString();

            request.merchantReferenceCode = "Order #: " + OriginalOrderNumber.ToString() + " " + Localization.ToNativeDateTimeString(System.DateTime.Now);

            request.merchantID = AppLogic.AppConfig("CYBERSOURCE.merchantID");

            request.ccCreditService = new CCCreditService();
            request.ccCreditService.captureRequestID = TransID;
            request.ccCreditService.run = "true";

            if (RefundAmount == System.Decimal.Zero)
            {
                RefundAmount = TotalAmount;
            }

            PurchaseTotals ptotal = new PurchaseTotals();

            ptotal.currency         = Localization.StoreCurrency(); // Currency REQUIRED
            ptotal.grandTotalAmount = Localization.CurrencyStringForGatewayWithoutExchangeRate(CommonLogic.IIF(RefundAmount > TotalAmount, TotalAmount, RefundAmount));
            request.purchaseTotals  = ptotal;                       // Neccessary

            result = "ERROR: ";

            try
            {
                ReplyMessage reply = SoapClient.RunTransaction(conf, request);
                if (reply.ccCreditReply.reasonCode == "100")
                {
                    result = AppLogic.ro_OK;
                }
                else
                {
                    result += GetReasonCodeDescription(reply.reasonCode);
                }
            }
            catch (SignException se)
            {
                result += String.Format("Failed to sign the request with error code {0} and message {1}.", DB.SQuote(se.ErrorCode.ToString()), DB.SQuote(se.Message));
            }
            catch (SoapHeaderException she)
            {
                result += String.Format("A SOAP header exception was returned with fault code {0} and message {1}.", DB.SQuote(she.Code.ToString()), DB.SQuote(she.Message));
            }
            catch (SoapBodyException sbe)
            {
                result += String.Format("A SOAP body exception was returned with fault code {0} and message {1}.", DB.SQuote(sbe.Code.ToString()), DB.SQuote(sbe.Message));
            }
            catch (WebException we)
            {
                result += String.Format("Failed to get a response with status {0} and message {1}", DB.SQuote(we.Status.ToString()), DB.SQuote(we.Message));
            }
            catch (Exception ex)
            {
                result += ex.Message;
            }
            DB.ExecuteSQL("update orders set RefundTXResult=" + DB.SQuote(result) + " where OrderNumber=" + OriginalOrderNumber.ToString());

            return(result);
        }
Example #9
0
        private void PopulateAddressControlValues(AddressControl ctrlAddress, CreditCardPanel ctrlCreditCard, Echeck ctrlEcheck, int Index, int?editAddressId)
        {
            Addresses allAddress = GetAddresses();

            if (editAddressId.HasValue)
            {
                for (int i = 0; i < allAddress.Count; i++)
                {
                    if (allAddress[i].AddressID == editAddressId)
                    {
                        Index = i;
                    }
                }
            }
            AspDotNetStorefrontCore.Address anyAddress = allAddress[Index];

            if (ctrlAddress != null)
            {
                ctrlAddress.NickName      = anyAddress.NickName;
                ctrlAddress.FirstName     = anyAddress.FirstName;
                ctrlAddress.LastName      = anyAddress.LastName;
                ctrlAddress.PhoneNumber   = anyAddress.Phone;
                ctrlAddress.Company       = anyAddress.Company;
                ctrlAddress.ResidenceType = anyAddress.ResidenceType.ToString();
                ctrlAddress.Address1      = anyAddress.Address1;
                ctrlAddress.Address2      = anyAddress.Address2;
                ctrlAddress.Suite         = anyAddress.Suite;
                ctrlAddress.City          = anyAddress.City;
                ctrlAddress.ZipCode       = anyAddress.Zip;
                CountryDropDownData(ctrlAddress);
                ctrlAddress.Country = anyAddress.Country;
                StateDropDownData(ctrlAddress, ThisCustomer.LocaleSetting);
                ctrlAddress.State   = anyAddress.State;
                ctrlAddress.ShowZip = AppLogic.GetCountryPostalCodeRequired(AppLogic.GetCountryID(ctrlAddress.Country));
            }

            if (CustomerCCRequired)
            {
                if (ctrlCreditCard != null)
                {
                    ctrlCreditCard.CreditCardName   = anyAddress.CardName;
                    ctrlCreditCard.CreditCardNumber = AppLogic.SafeDisplayCardNumber(anyAddress.CardNumber, "Address", anyAddress.AddressID);
                    ctrlCreditCard.CreditCardType   = anyAddress.CardType;
                    ctrlCreditCard.CardExpMonth     = anyAddress.CardExpirationMonth;
                    ctrlCreditCard.CardExpYr        = anyAddress.CardExpirationYear;
                    if (AppLogic.AppConfigBool("Misc.ShowCardStartDateFields"))
                    {
                        if (!CommonLogic.IsStringNullOrEmpty(anyAddress.CardStartDate))
                        {
                            if (anyAddress.CardStartDate.Length >= 6)
                            {
                                ctrlCreditCard.CardStartMonth = anyAddress.CardStartDate.Substring(0, 2);
                                ctrlCreditCard.CardStartYear  = anyAddress.CardStartDate.Substring(2, 4);
                            }
                        }
                    }
                    if (AppLogic.AppConfigBool("CardExtraCodeIsOptional"))
                    {
                        ctrlCreditCard.CreditCardIssueNumber = anyAddress.CardIssueNumber;
                    }
                }
            }

            if (ShowEcheck)
            {
                if (ctrlEcheck != null)
                {
                    ctrlEcheck.ECheckBankAccountName   = anyAddress.ECheckBankAccountName;
                    ctrlEcheck.ECheckBankName          = anyAddress.ECheckBankName;
                    ctrlEcheck.ECheckBankABACode       = AppLogic.SafeDisplayCardNumber(anyAddress.ECheckBankABACode, "Address", anyAddress.AddressID);
                    ctrlEcheck.ECheckBankAccountNumber = anyAddress.ECheckBankAccountNumberMasked;
                    ctrlEcheck.ECheckBankAccountType   = anyAddress.ECheckBankAccountType;
                }
            }
        }
Example #10
0
        protected void btnNewAddress_Click(object sender, EventArgs e)
        {
            AddressControl ctrlNewAddress = pnlContent.FindControl("ctrlNewAddress") as AddressControl;

            if (ctrlNewAddress != null)
            {
                ctrlNewAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlNewAddress.Country);
            }

            Page.Validate("AddAddress");

            if (Page.IsValid)
            {
                AddressTypes addressType = AddressMode;
                bool         AllowShipToDifferentThanBillTo = AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo") &&
                                                              !AppLogic.AppConfigBool("SkipShippingOnCheckout");

                if (!AllowShipToDifferentThanBillTo)
                {
                    //Shipping and Billing address must be the same so save both
                    addressType = AddressTypes.Billing | AddressTypes.Shipping;
                }

                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                if (ctrlNewAddress != null)
                {
                    anyAddress.CustomerID    = ThisCustomer.CustomerID;
                    anyAddress.NickName      = ctrlNewAddress.NickName;
                    anyAddress.FirstName     = ctrlNewAddress.FirstName;
                    anyAddress.LastName      = ctrlNewAddress.LastName;
                    anyAddress.Company       = ctrlNewAddress.Company;
                    anyAddress.Address1      = ctrlNewAddress.Address1;
                    anyAddress.Address2      = ctrlNewAddress.Address2;
                    anyAddress.Suite         = ctrlNewAddress.Suite;
                    anyAddress.City          = ctrlNewAddress.City;
                    anyAddress.State         = ctrlNewAddress.State;
                    anyAddress.Zip           = ctrlNewAddress.ZipCode;
                    anyAddress.Country       = ctrlNewAddress.Country;
                    anyAddress.Phone         = ctrlNewAddress.PhoneNumber;
                    anyAddress.ResidenceType = (ResidenceTypes)addressType;

                    anyAddress.InsertDB();

                    int addressID = anyAddress.AddressID;

                    if (ThisCustomer.PrimaryBillingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set BillingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    }
                    if (ThisCustomer.PrimaryShippingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set ShippingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                        ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, addressID);
                    }

                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        String VerifyResult        = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        bool   verifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);

                        if (verifyAddressPrompt)
                        {
                            anyAddress = standardizedAddress;
                            anyAddress.UpdateDB();
                        }
                    }

                    String sURL = CommonLogic.ServerVariables("URL") + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING") != "", "?" + CommonLogic.ServerVariables("QUERY_STRING"), "");

                    if (!CommonLogic.IsStringNullOrEmpty(sURL))
                    {
                        Response.Redirect(sURL);
                    }
                }
            }
        }
Example #11
0
        protected void dlAddress_UpdateCommand(object sender, DataListCommandEventArgs e)
        {
            CreditCardPanel ctrlCreditCard = e.Item.FindControl("ctrlCreditCard") as CreditCardPanel;
            Panel           pnlCCData      = e.Item.FindControl("pnlCCData") as Panel;
            Panel           pnlECData      = e.Item.FindControl("pnlECData") as Panel;

            AddressControl ctrlAddress = e.Item.FindControl("ctrlAddress") as AddressControl;

            if (ctrlAddress != null)
            {
                ctrlAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlAddress.Country);
            }
            Page.Validate("EditAddress");

            if (AddressMode == AddressTypes.Billing && pnlCCData.Visible)
            {
                if (ctrlCreditCard.CreditCardType == AppLogic.GetString("address.cs.32", SkinID, ThisCustomer.LocaleSetting))
                {
                    pnlCCTypeErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCTypeErrorMsg.Visible = false;
                }
                if (ctrlCreditCard.CardExpMonth == AppLogic.GetString("address.cs.34", SkinID, ThisCustomer.LocaleSetting))
                {
                    pnlCCExpMonthErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCExpMonthErrorMsg.Visible = false;
                }
                if (ctrlCreditCard.CardExpYr == AppLogic.GetString("address.cs.35", 1, ThisCustomer.LocaleSetting))
                {
                    pnlCCExpYrErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCExpYrErrorMsg.Visible = false;
                }

                CardType            Type      = CardType.Parse(ctrlCreditCard.CreditCardType);
                CreditCardValidator validator = new CreditCardValidator(ctrlCreditCard.CreditCardNumber, Type);
                bool isValid = validator.Validate();

                if (!isValid && AppLogic.AppConfigBool("ValidateCreditCardNumbers"))
                {
                    ctrlCreditCard.CreditCardNumber = string.Empty;
                    // clear the card extra code
                    AppLogic.StoreCardExtraCodeInSession(ThisCustomer, string.Empty);
                    pnlCCNumberErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCNumberErrorMsg.Visible = false;
                }
            }

            bool isValidCCDropdown = !(pnlCCTypeErrorMsg.Visible || pnlCCExpMonthErrorMsg.Visible ||
                                       pnlCCExpYrErrorMsg.Visible || pnlCCNumberErrorMsg.Visible);

            if (dlAddress != null && Page.IsValid && isValidCCDropdown)
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();
                Echeck ctrlECheck = e.Item.FindControl("ctrlECheck") as Echeck;

                if (ctrlAddress != null)
                {
                    anyAddress.AddressID     = int.Parse((e.Item.FindControl("hfAddressID") as HiddenField).Value);
                    anyAddress.CustomerID    = ThisCustomer.CustomerID;
                    anyAddress.NickName      = ctrlAddress.NickName;
                    anyAddress.FirstName     = ctrlAddress.FirstName;
                    anyAddress.LastName      = ctrlAddress.LastName;
                    anyAddress.Phone         = ctrlAddress.PhoneNumber;
                    anyAddress.Company       = ctrlAddress.Company;
                    anyAddress.AddressType   = AddressMode;
                    anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlAddress.ResidenceType, true);
                    anyAddress.Address1      = ctrlAddress.Address1;
                    anyAddress.Address2      = ctrlAddress.Address2;
                    anyAddress.City          = ctrlAddress.City;
                    anyAddress.Suite         = ctrlAddress.Suite;
                    anyAddress.Zip           = ctrlAddress.ZipCode;
                    anyAddress.Country       = ctrlAddress.Country;
                    anyAddress.State         = ctrlAddress.State;

                    if (CustomerCCRequired && AddressMode == AddressTypes.Billing)
                    {
                        Address BillingAddress = new Address();
                        BillingAddress.LoadByCustomer(ThisCustomer.CustomerID, ThisCustomer.PrimaryBillingAddressID, AddressTypes.Billing);

                        if (ctrlCreditCard != null)
                        {
                            anyAddress.CardName = ctrlCreditCard.CreditCardName;

                            if (!ctrlCreditCard.CreditCardNumber.StartsWith("*"))
                            {
                                anyAddress.CardNumber = ctrlCreditCard.CreditCardNumber;
                            }
                            else
                            {
                                anyAddress.CardNumber = BillingAddress.CardNumber;
                            }

                            anyAddress.CardType            = ctrlCreditCard.CreditCardType;
                            anyAddress.CardExpirationMonth = ctrlCreditCard.CardExpMonth;
                            anyAddress.CardExpirationYear  = ctrlCreditCard.CardExpYr;

                            if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                            {
                                string cardStartDate = "";
                                if (ctrlCreditCard.CardExpMonth != AppLogic.GetString("address.cs.34", SkinID, ThisCustomer.LocaleSetting))
                                {
                                    cardStartDate = ctrlCreditCard.CardStartMonth;
                                }
                                if (ctrlCreditCard.CardExpYr != AppLogic.GetString("address.cs.35", SkinID, ThisCustomer.LocaleSetting))
                                {
                                    cardStartDate += ctrlCreditCard.CardStartYear;
                                }
                                anyAddress.CardStartDate = cardStartDate;
                            }
                            if (AppLogic.AppConfigBool("CardExtraCodeIsOptional"))
                            {
                                anyAddress.CardIssueNumber = ctrlCreditCard.CreditCardIssueNumber;
                            }
                        }

                        if (ShowEcheck && ctrlECheck != null)
                        {
                            anyAddress.ECheckBankAccountName = ctrlECheck.ECheckBankAccountName;
                            anyAddress.ECheckBankName        = ctrlECheck.ECheckBankName;

                            if (!ctrlECheck.ECheckBankABACode.StartsWith("*"))
                            {
                                anyAddress.ECheckBankABACode = ctrlECheck.ECheckBankABACode;
                            }
                            else
                            {
                                anyAddress.ECheckBankABACode = BillingAddress.ECheckBankABACode;
                            }

                            if (!ctrlECheck.ECheckBankAccountNumber.StartsWith("*"))
                            {
                                anyAddress.ECheckBankAccountNumber = ctrlECheck.ECheckBankAccountNumber;
                            }
                            else
                            {
                                anyAddress.ECheckBankAccountNumber = BillingAddress.ECheckBankAccountNumber;
                            }

                            anyAddress.ECheckBankAccountType = ctrlECheck.ECheckBankAccountType;
                        }

                        if (pnlCCData.Visible)
                        {
                            anyAddress.PaymentMethodLastUsed = AppLogic.ro_PMCreditCard;
                        }
                        else if (pnlECData.Visible)
                        {
                            anyAddress.PaymentMethodLastUsed = AppLogic.ro_PMECheck;
                        }
                        else
                        {
                            anyAddress.PaymentMethodLastUsed = BillingAddress.PaymentMethodLastUsed;
                        }
                    }

                    anyAddress.UpdateDB();

                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        string validateResult = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        anyAddress = standardizedAddress;
                        anyAddress.UpdateDB();

                        if (validateResult != AppLogic.ro_OK)
                        {
                        }
                    }

                    dlAddress.EditItemIndex = -1;
                    LoadData();
                }
            }
        }
Example #12
0
        protected void btnNewAddress_Click(object sender, EventArgs e)
        {
            AddressControl ctrlNewAddress = pnlContent.FindControl("ctrlNewAddress") as AddressControl;

            if (ctrlNewAddress != null)
            {
                ctrlNewAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlNewAddress.Country);
            }

            Page.Validate("AddAddress");

            if (Page.IsValid)
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                if (ctrlNewAddress != null)
                {
                    anyAddress.CustomerID = ThisCustomer.CustomerID;
                    anyAddress.NickName   = ctrlNewAddress.NickName;
                    anyAddress.FirstName  = ctrlNewAddress.FirstName;
                    anyAddress.LastName   = ctrlNewAddress.LastName;
                    anyAddress.Company    = ctrlNewAddress.Company;
                    anyAddress.Address1   = ctrlNewAddress.Address1;
                    anyAddress.Address2   = ctrlNewAddress.Address2;
                    anyAddress.Suite      = ctrlNewAddress.Suite;
                    anyAddress.City       = ctrlNewAddress.City;
                    anyAddress.State      = ctrlNewAddress.State;
                    anyAddress.Zip        = ctrlNewAddress.ZipCode;
                    anyAddress.Country    = ctrlNewAddress.Country;
                    anyAddress.Phone      = ctrlNewAddress.PhoneNumber;
                    //anyAddress.ResidenceType = (ResidenceTypes)addressType;
                    anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlNewAddress.ResidenceType, true);

                    anyAddress.InsertDB();

                    int addressID = anyAddress.AddressID;

                    if (ThisCustomer.PrimaryBillingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set BillingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    }
                    if (ThisCustomer.PrimaryShippingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set ShippingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                        ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, addressID);
                    }
                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        String validateResult = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        validateResult = "address.validation.errormsg".StringResource() + validateResult;

                        if (validateResult != AppLogic.ro_OK)
                        {
                            Session["ErrorMsgLabelText"] = System.Web.HttpUtility.HtmlEncode(validateResult);
                        }
                        else
                        {
                            anyAddress = standardizedAddress;
                            anyAddress.UpdateDB();
                        }
                    }

                    String sURL = CommonLogic.ServerVariables("URL") + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").Length > 0, "?" + CommonLogic.ServerVariables("QUERY_STRING"), "");
                    if (!CommonLogic.IsStringNullOrEmpty(sURL))
                    {
                        Response.Redirect(sURL);
                    }
                }
            }
        }
Example #13
0
        public override string RefundOrder(
            int originalOrderNumber,
            int newOrderNumber,
            decimal refundAmount,
            string refundReason,
            AspDotNetStorefrontCore.Address billingAddress)
        {
            var useLiveTransactions = AppConfigProvider.GetAppConfigValue <bool>("UseLiveTransactions");

            var originalOrder = new AspDotNetStorefrontCore.Order(originalOrderNumber);

            refundAmount.ValidateNumberOfDigits(15);

            var transactionRequest = new transactionRequestType
            {
                payment         = GetPreviousOrderPaymentInfo(originalOrderNumber),
                transactionType = transactionTypeEnum.refundTransaction.ToString(),
                amount          = refundAmount,
                amountSpecified = true,
                refTransId      = originalOrder.AuthorizationPNREF
            };

            if (useLiveTransactions)
            {
                transactionRequest.solution = new solutionType
                {
                    id = SolutionId
                }
            }
            ;

            var request = new createTransactionRequest
            {
                transactionRequest     = transactionRequest,
                merchantAuthentication = GetMerchantAuthentication(useLiveTransactions)
            };

            //Save the command we're sending
            originalOrder.RefundTXCommand = JsonConvert.SerializeObject(request);

            var controller = new createTransactionController(request);

            controller.Execute(
                GetRunEnvironment(useLiveTransactions));

            var response = controller.GetApiResponse();

            if (response == null)
            {
                return("NO RESPONSE FROM GATEWAY!");
            }

            //Save the response
            originalOrder.RefundTXResult = JsonConvert.SerializeObject(response);

            if (response.messages.resultCode != messageTypeEnum.Ok)
            {
                return(response.transactionResponse?.errors?[0].errorText
                       ?? response.messages.message[0].text);
            }

            if (response.transactionResponse.messages == null)
            {
                return(response.transactionResponse.errors?[0].errorText
                       ?? "Unspecified Error");
            }

            return(AppLogic.ro_OK);
        }

        paymentType GetPreviousOrderPaymentInfo(int orderNumber)
        {
            var cardNumber = DB.GetSqlS("SELECT Last4 S FROM Orders WITH (NOLOCK) WHERE OrderNumber = @orderNumber",
                                        new SqlParameter("@orderNumber", orderNumber));

            var creditCard = new creditCardType
            {
                cardNumber     = cardNumber,
                expirationDate = "XXXX"
            };

            return(new paymentType
            {
                Item = creditCard
            });
        }

        AuthorizeNet.Environment GetRunEnvironment(bool liveMode)
        {
            return(liveMode
                                ? AuthorizeNet.Environment.PRODUCTION
                                : AuthorizeNet.Environment.SANDBOX);
        }

        merchantAuthenticationType GetMerchantAuthentication(bool liveMode)
        {
            return(new merchantAuthenticationType()
            {
                name = liveMode
                                        ? AppConfigProvider.GetAppConfigValue("AcceptJs.Live.ApiLoginId")
                                        : AppConfigProvider.GetAppConfigValue("AcceptJs.Test.ApiLoginId"),
                ItemElementName = ItemChoiceType.transactionKey,
                Item = liveMode
                                        ? AppConfigProvider.GetAppConfigValue("AcceptJs.Live.TransactionKey")
                                        : AppConfigProvider.GetAppConfigValue("AcceptJs.Test.TransactionKey"),
            });
        }
    }
        protected void btnNewAddress_Click(object sender, EventArgs e)
        {
            AddressControl ctrlNewAddress = pnlContent.FindControl("ctrlNewAddress") as AddressControl;

            if (ctrlNewAddress != null)
            {
                ctrlNewAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlNewAddress.Country);
            }
            //LovelyEcom Add
            string  VerifyResult0       = string.Empty;
            Address StandardizedAddress = null;

            lbAddressError.Text = "";
            if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
            {
                Address Verifyaddress = new Address();
                Verifyaddress.Address1 = ctrlNewAddress.Address1;
                Verifyaddress.Address2 = ctrlNewAddress.Address2;
                Verifyaddress.City     = ctrlNewAddress.City;
                Verifyaddress.State    = ctrlNewAddress.State;
                Verifyaddress.Zip      = ctrlNewAddress.ZipCode;

                VerifyResult0 = AddressValidation.RunValidate(Verifyaddress, out StandardizedAddress);

                if (VerifyResult0 != AppLogic.ro_OK)
                {
                    lbAddressError.Text += VerifyResult0; //lovely Ecom Added
                    return;
                }
            }
            //LovelyEcom end
            Page.Validate("AddAddress");

            if (Page.IsValid)
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                if (ctrlNewAddress != null)
                {
                    anyAddress.CustomerID = ThisCustomer.CustomerID;
                    anyAddress.NickName   = ctrlNewAddress.NickName;
                    anyAddress.FirstName  = ctrlNewAddress.FirstName;
                    anyAddress.LastName   = ctrlNewAddress.LastName;
                    anyAddress.Company    = ctrlNewAddress.Company;
                    anyAddress.Address1   = ctrlNewAddress.Address1;
                    anyAddress.Address2   = ctrlNewAddress.Address2;
                    anyAddress.Suite      = ctrlNewAddress.Suite;
                    anyAddress.City       = ctrlNewAddress.City;
                    anyAddress.State      = ctrlNewAddress.State;
                    anyAddress.Zip        = ctrlNewAddress.ZipCode;
                    anyAddress.Country    = ctrlNewAddress.Country;
                    anyAddress.Phone      = ctrlNewAddress.PhoneNumber;
                    //anyAddress.ResidenceType = (ResidenceTypes)addressType;
                    anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlNewAddress.ResidenceType, true);

                    anyAddress.InsertDB();

                    int addressID = anyAddress.AddressID;

                    if (ThisCustomer.PrimaryBillingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set BillingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    }
                    if (ThisCustomer.PrimaryShippingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set ShippingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                        ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, addressID);
                    }

                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        String VerifyResult        = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        bool   verifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);

                        if (verifyAddressPrompt)
                        {
                            anyAddress = standardizedAddress;
                            anyAddress.UpdateDB();
                        }
                    }

                    String sURL = CommonLogic.ServerVariables("URL") + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING") != "", "?" + CommonLogic.ServerVariables("QUERY_STRING"), "");

                    if (!CommonLogic.IsStringNullOrEmpty(sURL))
                    {
                        Response.Redirect(sURL);
                    }
                }
            }
        }