Пример #1
0
    static private void ARC_Cybersource_To_SQL(ARC_Cybersource_Log_Auth arcRecord, cybProcess cybProc)
    {
        #region Processing Start - SQL - Try
        try
        {
            #region SqlConnection
            using (SqlConnection con = new SqlConnection(sqlStr))
            {
                #region SqlCommand cmd
                using (SqlCommand cmd = new SqlCommand("", con))
                {
                    #region Populate the SQL Command
                    cmd.CommandTimeout = 600;
                    cmd.CommandText    = "[dbo].[recurring_records_add_cybersource]";
                    cmd.CommandType    = CommandType.StoredProcedure;
                    #endregion Populate the SQL Command
                    #region Populate the SQL Params
                    cmd.Parameters.Add(new SqlParameter("@Source", arcRecord.Source));
                    cmd.Parameters.Add(new SqlParameter("@ExternalID", arcRecord.ExternalID));
                    cmd.Parameters.Add(new SqlParameter("@Status", arcRecord.Status));
                    cmd.Parameters.Add(new SqlParameter("@CreateDate", arcRecord.CreateDate));

                    cmd.Parameters.Add(new SqlParameter("@decision", arcRecord.decision));
                    cmd.Parameters.Add(new SqlParameter("@merchantReferenceCode", arcRecord.merchantReferenceCode));
                    cmd.Parameters.Add(new SqlParameter("@reasonCode", arcRecord.reasonCode));
                    cmd.Parameters.Add(new SqlParameter("@requestID", arcRecord.requestID));
                    cmd.Parameters.Add(new SqlParameter("@requestToken", arcRecord.requestToken));

                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_accountBalance", arcRecord.ccAuthReply_accountBalance));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_accountBalanceCurrency", arcRecord.ccAuthReply_accountBalanceCurrency));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_accountBalanceSign", arcRecord.ccAuthReply_accountBalanceSign));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_amount", arcRecord.ccAuthReply_amount));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_authFactorCode", arcRecord.ccAuthReply_authFactorCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_authorizationCode", arcRecord.ccAuthReply_authorizationCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_authorizedDateTime", arcRecord.ccAuthReply_authorizedDateTime));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_avsCode", arcRecord.ccAuthReply_avsCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_avsCodeRaw", arcRecord.ccAuthReply_avsCodeRaw));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_cardCategory", arcRecord.ccAuthReply_cardCategory));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_cavvResponseCode", arcRecord.ccAuthReply_cavvResponseCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_cavvResponseCodeRaw", arcRecord.ccAuthReply_cavvResponseCodeRaw));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_cvCode", arcRecord.ccAuthReply_cvCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_cvCodeRaw", arcRecord.ccAuthReply_cvCodeRaw));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_merchantAdviceCode", arcRecord.ccAuthReply_merchantAdviceCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_merchantAdviceCodeRaw", arcRecord.ccAuthReply_merchantAdviceCodeRaw));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_ownerMerchantID", arcRecord.ccAuthReply_ownerMerchantID));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_paymentNetworkTransactionID", arcRecord.ccAuthReply_paymentNetworkTransactionID));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_processorResponse", arcRecord.ccAuthReply_processorResponse));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_reasonCode", arcRecord.ccAuthReply_reasonCode));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_reconciliationID", arcRecord.ccAuthReply_reconciliationID));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_referralResponseNumber", arcRecord.ccAuthReply_referralResponseNumber));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_requestAmount", arcRecord.ccAuthReply_requestAmount));
                    cmd.Parameters.Add(new SqlParameter("@ccAuthReply_requestCurrency", arcRecord.ccAuthReply_requestCurrency));
                    cmd.Parameters.Add(new SqlParameter("@ccCaptureReply_amount", arcRecord.ccCaptureReply_amount));
                    cmd.Parameters.Add(new SqlParameter("@ccCaptureReply_reasonCode", arcRecord.ccCaptureReply_reasonCode));
                    cmd.Parameters.Add(new SqlParameter("@ccCaptureReply_reconciliationID", arcRecord.ccCaptureReply_reconciliationID));
                    cmd.Parameters.Add(new SqlParameter("@ccCaptureReply_requestDateTime", arcRecord.ccCaptureReply_requestDateTime));

                    cmd.Parameters.Add(new SqlParameter("@ccContent", arcRecord.ccContent));
                    string cmdText  = "\n" + cmd.CommandText;
                    bool   cmdFirst = true;
                    foreach (SqlParameter param in cmd.Parameters)
                    {
                        cmdText += "\n" + ((cmdFirst) ? "" : ",") + param.ParameterName + " = " + ((param.Value != null) ? "'" + param.Value.ToString() + "'" : "default");
                        cmdFirst = false;
                    }
                    #endregion Populate the SQL Params
                    #region Process SQL Command - Try
                    try
                    {
                        if (con.State == ConnectionState.Closed)
                        {
                            con.Open();
                        }
                        Int32 ccauthid = Convert.ToInt32(cmd.ExecuteScalar());
                        cybProc.cybid = ccauthid;
                        // LogSQL(cmd, "sqlPassed");
                    }
                    #endregion Process SQL Command - Try
                    #region Process SQL Command - Catch
                    catch (Exception ex)
                    {
                        cybProc.status     = "ERROR";
                        cybProc.message    = "ARC_SQL - Catch - SqlCommand";
                        cybProc.lblmessage = ErrorLog.ErrorLog_Display_String(ex, "Error: ARC_Cybersource_To_SQL - Try");

                        // Log_Exception("Error 001", ex, "error", "ARC_Cybersource_To_SQL - Process SQL Command - Try");
                        // LogSQL(cmd, "sqlFailed");
                    }
                    #endregion Process SQL Command - Catch
                }
                #endregion SqlCommand cmd
            }
            #endregion SqlConnection
        }
        #endregion Processing Start - SQL - Try
        #region Processing Start - SQL - Catch
        catch (Exception ex)
        {
            cybProc.status     = "ERROR";
            cybProc.message    = "ARC_SQL - Catch - Processing";
            cybProc.lblmessage = ErrorLog.ErrorLog_Display_String(ex, "Error: ARC_Cybersource_To_SQL - Catch");
            // Log_Exception("Error 002", ex, "error", "ARC_Cybersource_To_SQL - Processing Start - SQL - Catch");
        }
        #endregion Processing Start - SQL - Catch
    }
Пример #2
0
    static public cybProcess cybCharge(ARC_Cybersource_Charge donor)
    {
        cybProcess cybProc = new cybProcess();

        cybProc.status  = "START";
        cybProc.message = "begin processing...";

        #region Insert: CYBERSOURCE
        Boolean doCyberSource    = true;  // [false] Prevents CS from processing (DeBug)
        Boolean donationApproved = false; // Determine if this is the proper place for this, it is used to determine success/failure
        String  ResponseSQL      = "";    // Determien proper place for this, it was a label
        String  cdChargeStatus   = "";    // Determien proper place for this, it was a label

        #region CS Request Creation and Type
        RequestMessage request = new RequestMessage();
        request.ccAuthService        = new CCAuthService();
        request.ccAuthService.run    = "true";
        request.ccCaptureService     = new CCCaptureService();
        request.ccCaptureService.run = "true";
        #endregion CS Request Creation and Type
        #region CS Reconcilliation ID
        /// Reconcilliation ID from ExternalID / DonationCCInfo.ID
        string reconciliationID = donor.donationid.ToString(); // sp_donationccinfoid.ToString();
        // Padding Not Used [Used in IVR/Recurring Services ???]
        //int pad = 16; // 9 for AmEx, 16 for others
        //if (sp_ccnum.StartsWith("3")) { pad = 9; }
        //reconciliationID = reconciliationID.PadRight(pad, '0');
        request.ccAuthService.reconciliationID    = reconciliationID;
        request.ccCaptureService.reconciliationID = reconciliationID;
        request.merchantReferenceCode             = donor.orderid; // sp_orderid = sp_donationccinfoid.ToString().PadLeft(14, '0');;
        #endregion CS Reconcilliation ID
        #region CS billTo
        /// We need to enter default data if non is supplied
        /// We also need to parse the Zip Code against the Zip database
        BillTo billTo = new BillTo();
        billTo.firstName  = donor.billto_firstname; // tb7_first_name.Text.Trim();
        billTo.lastName   = donor.billto_lastname;  // tb7_last_name.Text.Trim();
        billTo.street1    = donor.billto_streeet1;  // tb8_address1.Text.Trim();
        billTo.postalCode = donor.billto_zip;       // tb8_postal_code.Text.Trim();
        billTo.city       = donor.billto_city;      // tb8_city.Text.Trim();
        billTo.state      = donor.billto_state;     // sp_state; // tb8_state.SelectedValue;
        billTo.country    = donor.billto_country;   // sp_country; // "US";
        billTo.email      = donor.billto_email;     // tb8_email.Text.Trim()
        request.billTo    = billTo;
        #endregion CS billTo
        #region CS Card
        Card card = new Card();
        card.accountNumber   = donor.card_number; // sp_ccnum;
        card.expirationMonth = donor.card_month;  // tb7_card_month.SelectedValue;
        card.expirationYear  = donor.card_year;   // tb7_card_year.SelectedValue;
        request.card         = card;
        #endregion CS Card
        #region CS Item / Amount
        PurchaseTotals purchaseTotals = new PurchaseTotals();
        purchaseTotals.currency = "USD";
        request.purchaseTotals  = purchaseTotals;
        request.item            = new Item[1];
        Item item = new Item();
        item.id          = "0";
        item.unitPrice   = donor.amount.ToString(); // sp_donationamount.ToString();
        item.productSKU  = donor.product_sku;       //"DN001";
        item.productName = donor.product_name;      //"ARC Agent Script Donation";
        request.item[0]  = item;
        #endregion CS Item / Amount
        #region CS Process / Reply
        ARC_Cybersource_Log_Auth arcRecord = new ARC_Cybersource_Log_Auth();
        arcRecord.ExternalID = donor.donationid.ToString(); // sp_donationccinfoid.ToString();
        if (doCyberSource)
        {
            try
            {
                ReplyMessage reply    = SoapClient.RunTransaction(request);
                string       template = GetTemplate(reply.decision.ToUpper());
                string       content  = "";
                try { content = GetContent(reply); }
                catch { content = "error"; }
                //Log(logRecord + ",CB: " + String.Format(template, content), "record");
                #region Populate the ARC Record
                if (reply.decision == "ACCEPT")
                {
                    arcRecord.Status = "Settled"; donationApproved = true;
                }
                // Change me before launching Monday !!!!
                //else if (reply.decision == "REJECT" && sp_ccnum == "4111111111111111x" && tglMode == "Stage") { arcRecord.Status = "Settled"; donationApproved = true; }
                else if (reply.decision == "REJECT")
                {
                    arcRecord.Status = "Declined"; donationApproved = false;
                }
                else
                {
                    arcRecord.Status = "Error"; donationApproved = false;
                }


                ResponseSQL += "<br /><b>CS Status: " + arcRecord.Status + "</b>";

                arcRecord.ccContent             = content;
                arcRecord.decision              = reply.decision;
                arcRecord.merchantReferenceCode = reply.merchantReferenceCode;
                try
                {
                    arcRecord.reasonCode = Convert.ToInt32(reply.reasonCode);
                }
                catch { }
                arcRecord.requestID    = reply.requestID;
                arcRecord.requestToken = reply.requestToken;
                #region reply.ccAuthReply
                if (reply.ccAuthReply != null)
                {
                    arcRecord.ccAuthReply_accountBalance = reply.ccAuthReply.accountBalance;
                    //arcRecord.ccAuthReply_accountBalanceCurrency = String.Empty;
                    //arcRecord.ccAuthReply_accountBalanceSign = String.Empty;
                    arcRecord.ccAuthReply_amount            = reply.ccAuthReply.amount;
                    arcRecord.ccAuthReply_authFactorCode    = reply.ccAuthReply.authFactorCode;
                    arcRecord.ccAuthReply_authorizationCode = reply.ccAuthReply.authorizationCode;
                    if (reply.ccAuthReply.authorizedDateTime != null)
                    {
                        arcRecord.ccAuthReply_authorizedDateTime = reply.ccAuthReply.authorizedDateTime.Replace("T", " ").Replace("Z", "");
                    }
                    arcRecord.ccAuthReply_avsCode    = reply.ccAuthReply.avsCode;
                    arcRecord.ccAuthReply_avsCodeRaw = reply.ccAuthReply.avsCodeRaw;
                    //arcRecord.ccAuthReply_cardCategory = String.Empty;
                    arcRecord.ccAuthReply_cavvResponseCode    = reply.ccAuthReply.cavvResponseCode;
                    arcRecord.ccAuthReply_cavvResponseCodeRaw = reply.ccAuthReply.cavvResponseCodeRaw;
                    arcRecord.ccAuthReply_cvCode                = reply.ccAuthReply.cvCode;
                    arcRecord.ccAuthReply_cvCodeRaw             = reply.ccAuthReply.cvCodeRaw;
                    arcRecord.ccAuthReply_merchantAdviceCode    = reply.ccAuthReply.merchantAdviceCode;
                    arcRecord.ccAuthReply_merchantAdviceCodeRaw = reply.ccAuthReply.merchantAdviceCodeRaw;
                    //arcRecord.ccAuthReply_ownerMerchantID = String.Empty;
                    //arcRecord.ccAuthReply_paymentNetworkTransactionID = String.Empty;
                    arcRecord.ccAuthReply_processorResponse = reply.ccAuthReply.processorResponse;
                    try
                    {
                        arcRecord.ccAuthReply_reasonCode = Convert.ToInt32(reply.ccAuthReply.reasonCode);
                    }
                    catch { }
                    arcRecord.ccAuthReply_reconciliationID       = reply.ccAuthReply.reconciliationID;
                    arcRecord.ccAuthReply_referralResponseNumber = String.Empty;
                    arcRecord.ccAuthReply_requestAmount          = donor.amount.ToString(); // sp_donationamount.ToString();
                    arcRecord.ccAuthReply_requestCurrency        = String.Empty;
                }
                #endregion reply.ccAuthReply
                #region reply.ccCaptureReply
                if (reply.ccCaptureReply != null)
                {
                    arcRecord.ccCaptureReply_amount = reply.ccCaptureReply.amount;
                    try
                    {
                        arcRecord.ccCaptureReply_reasonCode = Convert.ToInt32(reply.ccCaptureReply.reasonCode);
                    }
                    catch { }
                    arcRecord.ccCaptureReply_reconciliationID = reply.ccCaptureReply.reconciliationID;
                    arcRecord.ccCaptureReply_requestDateTime  = reply.ccCaptureReply.requestDateTime.Replace("T", " ").Replace("Z", "");
                }
                #endregion reply.ccCaptureReply

                #endregion Populate the ARC Record
                cdChargeStatus = arcRecord.Status;
                cybProc.status = arcRecord.Status;
            }
            catch (Exception ex)
            {
                // Depending on the type of error, the user may be able to re-try, or this may be a fatal failure
                cybProc.status     = "ERROR";
                cybProc.message    = "cybCharge - Catch - doCyberSource";
                cybProc.lblmessage = ErrorLog.ErrorLog_Display_String(ex, "Error: Processing Donation 002");
            }
        }
        else
        {
            // Declined - Not Processed
            donationApproved = false;
            arcRecord.Status = "Declined";
            cdChargeStatus   = arcRecord.Status;
            cybProc.status   = arcRecord.Status;
        }
        #endregion CS Process / Reply
        #region CS Insert SQL
        #region Save the record to SQL
        if (arcRecord.Status != null)
        {
            //arcRecord.Source = "PORTAL";
            //arcRecord.Source = "WEB"; // Get this from the record type
            //arcRecord.Source = "IVR";
            //arcRecord.Source = "RECURRING";
            arcRecord.Source = donor.source;
            ARC_Cybersource_To_SQL(arcRecord, cybProc);
        }
        #endregion Save the record to SQL
        #endregion CS Insert SQL
        #endregion Insert: CYBERSOURCE
        return(cybProc);
    }