Example #1
0
 /// <summary>
 /// Check if this setting already exists for this profile
 /// </summary>
 private bool PaymentSettingExists()
 {
     StoreSettingsAdmin settingsAdmin = new StoreSettingsAdmin();
     return settingsAdmin.PaymentSettingExists(int.Parse(lstProfile.SelectedValue), int.Parse(lstPaymentType.SelectedValue));
 }
Example #2
0
    /// <summary>
    /// Submit button click event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        StoreSettingsAdmin settingsAdmin = new StoreSettingsAdmin();
        PaymentSetting paymentSetting = new PaymentSetting();

        //If edit mode then retrieve data first
        if (ItemId > 0)
        {
            paymentSetting = settingsAdmin.GetPaymentSettingByID(ItemId);

            if (paymentSetting.ProfileID.HasValue)
            {
                if ((paymentSetting.ProfileID != int.Parse(lstProfile.SelectedValue)) || (paymentSetting.PaymentTypeID != int.Parse(lstPaymentType.SelectedValue)))
                {
                    //check if this setting already exists for this profile
                    bool settingExists = PaymentSettingExists();

                    if (settingExists)
                    {
                        lblMsg.Text = "This Payment Option already exists for this Profile. Please select a different Payment Option.";
                        return;
                    }
                }
            }
            else
            {
                if (lstProfile.SelectedValue != "-1")
                {
                    //check if this setting already exists for this profile
                    bool settingExists = PaymentSettingExists();

                    if (settingExists)
                    {
                        lblMsg.Text = "This Payment Option already exists for this Profile. Please select a different Payment Option.";
                        return;
                    }
                }
            }
        }

        //set values based on user input
        paymentSetting.ActiveInd = chkActiveInd.Checked;
        paymentSetting.PaymentTypeID = int.Parse(lstPaymentType.SelectedValue);
        if (lstProfile.SelectedValue == "-1")
        {
            paymentSetting.ProfileID = null;//If All profiles is selected
        }
        else
        {
            paymentSetting.ProfileID = int.Parse(lstProfile.SelectedValue);
        }
        paymentSetting.DisplayOrder = Convert.ToInt32(txtDisplayOrder.Text);
        //paymentSetting.OfflineMode = false;

        //if credit card
        if (paymentSetting.PaymentTypeID == 0)
        {
            paymentSetting.GatewayTypeID = int.Parse(lstGateway.SelectedValue);

            paymentSetting.EnableAmex = chkEnableAmex.Checked;
            paymentSetting.EnableDiscover = chkEnableDiscover.Checked;
            paymentSetting.EnableMasterCard = chkEnableMasterCard.Checked;
            paymentSetting.EnableVisa = chkEnableVisa.Checked;
            paymentSetting.TestMode = chkTestMode.Checked;
            paymentSetting.PreAuthorize = chkPreAuthorize.Checked;
            paymentSetting.GatewayPassword = string.Empty;
            paymentSetting.TransactionKey = string.Empty;

            ZNodeEncryption encrypt = new ZNodeEncryption();

            paymentSetting.GatewayUsername = encrypt.EncryptData(txtGatewayUserName.Text);

            //if authorize.net
            if (paymentSetting.GatewayTypeID == 1)
            {
                paymentSetting.TransactionKey = encrypt.EncryptData(txtTransactionKey.Text);
            }
            //If Verisign PayFlow pro gateway is selected
            else if (paymentSetting.GatewayTypeID == 2)
            {
                paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
                paymentSetting.Partner = txtPartner.Text.Trim();
                paymentSetting.Vendor = txtVendor.Text.Trim();
            }
            //If Nova gateway is selected
            else if (paymentSetting.GatewayTypeID == 5)
            {
                paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
                paymentSetting.TransactionKey = encrypt.EncryptData(txtTransactionKey.Text);
            }
            //If Paypal direct payment gateway is selected
            else if (paymentSetting.GatewayTypeID == 6)
            {
                paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
                paymentSetting.TransactionKey = txtTransactionKey.Text;
            }
            // If World Pay gateway is selected
            else if (paymentSetting.GatewayTypeID == 10)
            {
                // Authorization password
                paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
                // Installation Id
                paymentSetting.TransactionKey = encrypt.EncryptData(txtTransactionKey.Text);
            }
            else
            {
                paymentSetting.TransactionKey = "";
                paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
            }
        }
        // if Paypal
        else if (paymentSetting.PaymentTypeID == 2)
        {
            paymentSetting.GatewayTypeID = null;
            ZNodeEncryption encrypt = new ZNodeEncryption();

            paymentSetting.GatewayUsername = encrypt.EncryptData(txtGatewayUserName.Text);
            paymentSetting.TransactionKey = txtTransactionKey.Text;
            paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
            paymentSetting.TestMode = chkTestMode.Checked;

        }
            //if Google Checkout
        else if (paymentSetting.PaymentTypeID == 3)
        {
            paymentSetting.GatewayTypeID = null; //Set null value to Google
            ZNodeEncryption encrypt = new ZNodeEncryption();

            paymentSetting.GatewayUsername = encrypt.EncryptData(txtGatewayUserName.Text);
            paymentSetting.GatewayPassword = encrypt.EncryptData(txtGatewayPassword.Text);
            paymentSetting.TestMode = chkTestMode.Checked;
        }
        else // Purchase Order
        {
            paymentSetting.GatewayTypeID = null;
        }

        bool retval = false;

        //Update Payment setting into database
        if (ItemId > 0)
        {
            retval = settingsAdmin.UpdatePaymentSetting(paymentSetting);
        }
        else
        {
            bool settingExists = settingsAdmin.PaymentSettingExists(int.Parse(lstProfile.SelectedValue), int.Parse(lstPaymentType.SelectedValue));

            if (settingExists)
            {
                lblMsg.Text = "This Payment Option already exists for this Profile. Please select a different Payment Option.";
                return;
            }

            retval = settingsAdmin.AddPaymentSetting(paymentSetting);
        }

        if (retval)
        {
            //redirect to main page
            Response.Redirect("~/admin/secure/settings/payment/");
        }
        else
        {
            //display error message
            lblMsg.Text = "An error occurred while updating. Please try again.";
        }
    }