using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class Admin_OrderWizard_Capture : WebBlocks.AdministrativePage
{
private int OrderID
{
get { return (ViewState["OrderID"] == null ? 0 : (int)ViewState["OrderID"]); }
set { ViewState["OrderID"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
OrderID = Int32.Parse(Request["OrderID"]);
// first step, check if the order has been captured
DataRow dr = Database.Orders_GetByOrderID(OrderID);
bool IsAuthorized = (bool)dr["IsAuthorized"];
bool IsCaptured = (bool)dr["IsCaptured"];
if (IsCaptured) // skip step one if its captured already
wizShip.ActiveStepIndex = 1;
}
}
private void CaptureFunds()
{
Gateways.GatewayBase gateway = Gateways.GatewayBase.GetGateway(Configuration.Get("Gateways.PaymentGateway"));
if (gateway.CaptureFunds(OrderID))
{
litCapture.Text = "Capture Successful";
wizShip.ActiveStepIndex = 1;
}
else
{
DataRow dr = Database.Orders_GetByOrderID(OrderID);
litCapture.Text = "
Capture failed for the following reason:
";
litCapture.Text += (dr["LastResponseText"] == DBNull.Value ? "No Reason" : (string)dr["LastResponseText"]);
litCapture.Text += "
If you'd like to continue anyway, you can click the 'Continue Anyway' button below. Otherwise, you may want to check the order details.
";
btnFinish.Visible = true;
wizShip.ActiveStepIndex = 0;
}
}
protected void wizShip_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
}
protected void wizShip_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
Response.Redirect("EditOrder.aspx?OrderID=" + OrderID.ToString());
}
protected void StepPreviousButton_Click(object sender, EventArgs e)
{
Response.Redirect("EditOrder.aspx?OrderID=" + OrderID.ToString());
}
protected void btnFinish_Click(object sender, EventArgs e)
{
wizShip.ActiveStepIndex = 1;
btnFinish.Visible = false;
DataRow dr = Database.Orders_GetByOrderID(OrderID);
if ((int)dr["OrderStatusID"] == 3) // 3 = shipped
Database.Orders_SetOrderStatusID(OrderID, 13); // 13 = completed
else
Database.Orders_SetOrderStatusID(OrderID, 14); // 14 = captured
Response.Redirect("EditOrder.aspx?OrderID=" + OrderID.ToString());
}
protected void StepNextButton_Click(object sender, EventArgs e)
{
CaptureFunds();
}
}