public bool IsValidResponse(decimal amountToCharge, NameValueCollection variables,
     Account userAccount, string voucherCode, out string errorMessage, out Charge charge)
 {
     errorMessage = string.Empty;
     charge = new Charge
     {
         Amount = amountToCharge,
         Currency = "INR",
         CustomerPaymentId =  "bank_ref_num",
         ExternalReferenceId = "mihpayid",
         InternalReferenceId = "txnid",
         IsRefund = false,
         Provider = "PayU",
         Type = "PG_TYPE"
     };
     return true;
 }
        public bool IsValidResponse(decimal amountToCharge, NameValueCollection variables, Account userAccount, string voucherCode, out string errorMessage, out Charge charge)
        {
            var providerResponse = string.Empty;
            charge = null;
            try
            {
                string dr = variables["DR"];
                dr = dr.Replace(' ', '+');

                var sQS = Base64Decode(dr);
                providerResponse = RC4.Decrypt(_providerDetails.MerchantSecretKey, sQS, false);
                errorMessage = string.Empty;

            }
            catch
            {
                errorMessage = "Invalid response received. Please try again later.";
                return false;
            }

            if (!string.IsNullOrEmpty(providerResponse))
            {
                var response = HttpUtility.ParseQueryString(providerResponse);

                charge = new Charge
                             {
                                 Amount = amountToCharge,
                                 Currency = "INR",
                                 CustomerPaymentId = response["TransactionID"],
                                 ExternalReferenceId = response["PaymentID"],
                                 InternalReferenceId = response["MerchantRefNo"],
                                 IsRefund = false,
                                 IsSuccess = response["ResponseCode"] == "0",
                                 Provider = "EBS",
                                 Type = response["PaymentMethod"],
                                 Mode = _providerDetails.Mode,
                             };

                if (response["ResponseCode"] == "0")
                    return true;

                errorMessage = string.IsNullOrEmpty(response["ResponseMessage"])
                                   ? "Payment failed. Transaction has been cancelled."
                                   : response["ResponseMessage"];
                charge.ErrorMessage = errorMessage;
            }
            else
            {
                errorMessage = "Invalid response received. Please try again later.";
            }

            return false;
        }
        private static bool SaveCharge(int bookingId, Charge charge)
        {
            int chargeId;
            var db = new MySqlDatabase(DbConfiguration.ReservationDB);
            var cmd = CommandBuilder.BuildSaveChargeCommand(bookingId, charge.Amount, charge.Currency,
                                                            charge.CustomerPaymentId,
                                                            charge.ErrorMessage, charge.ExternalReferenceId,
                                                            charge.InternalReferenceId, charge.IsRefund,
                                                            charge.IsSuccess, charge.Provider, charge.Mode,
                                                            charge.Type, db.Connection);

            db.ExecuteNonQuery(cmd, "outChargeId", out chargeId);
            charge.ChargeId = chargeId.ToString();
            return chargeId != 0;
        }
        public bool IsValidResponse(decimal amountToCharge, NameValueCollection variables,
            Account userAccount, string voucherCode, out string errorMessage, out Charge charge)
        {
            //<SALT>|status||||||udf5|udf4|udf3|udf2|udf1|email|firstname|productinfo|amount|txnid|key
            charge = null;

            string input = _providerDetails.AdditionalInfo["SALT"] + "|" + variables["status"] + "||||||||||" +
                           variables["udf1"] + "|" +
                           userAccount.Email + "|" + userAccount.FirstName + "|" + variables["productInfo"] + "|" +
                           amountToCharge.ToString("0.00") + "|" + variables["txnid"] + "|" + _providerDetails.MerchantId;
            var hash = Generatehash512(input);
            errorMessage = string.Empty;

            if (string.Equals(hash, variables["hash"]))
            {
                charge = new Charge
                {
                    Amount = amountToCharge,
                    Currency = "INR",
                    CustomerPaymentId = string.IsNullOrEmpty(variables["cardnum"]) ? variables["bank_ref_num"] : variables["cardnum"],
                    ExternalReferenceId = variables["mihpayid"],
                    InternalReferenceId = variables["txnid"],
                    IsRefund = false,
                    Provider = "PayU",
                    Type = variables["mode"]
                };
                if (string.Equals(variables["status"], "SUCCESS", StringComparison.OrdinalIgnoreCase))
                {
                    charge.IsSuccess = true;
                    UpdateVoucherCount(voucherCode);
                    return true;
                }
                errorMessage = "Payment failed. Transaction has been cancelled.";
            }
            else
            {
                errorMessage = "Invalid response received. Please try again after login.";
            }

            return false;
        }