Incorrect Order Status displayed in custom code
Posted: Fri Oct 10, 2008 2:52 pm
What do I need to do to cause an order to display the correct status in the Order Manager page? (and have the correct status available in my code?)
I have succeeded in creating, authorizing, and capturing an order via the API, but all the orders created this way show up with a status of "Payment Pending" in the Order Manager page. If I view the detail for the order, its status changes to "Completed".
It seems that a postback/page reload is required to cause the status to go to the correct value. What is happening behind the scenes and what do I need to do to achieve the same effect.
I was able to duplicate the behavior using the code below and the following scenario:
Button1 always displays
order.OrderStatus=Payment Pending
order.PaymentStatus=Unpaid
order.OrderStatus=Payment Pending
order.PaymentStatus=Unpaid
Button2 always displays
order.OrderStatus=Completed
order.PaymentStatus=Paid
I have succeeded in creating, authorizing, and capturing an order via the API, but all the orders created this way show up with a status of "Payment Pending" in the Order Manager page. If I view the detail for the order, its status changes to "Completed".
It seems that a postback/page reload is required to cause the status to go to the correct value. What is happening behind the scenes and what do I need to do to achieve the same effect.
I was able to duplicate the behavior using the code below and the following scenario:
Button1 always displays
order.OrderStatus=Payment Pending
order.PaymentStatus=Unpaid
order.OrderStatus=Payment Pending
order.PaymentStatus=Unpaid
Button2 always displays
order.OrderStatus=Completed
order.PaymentStatus=Paid
Code: Select all
protected void Button1_Click(object sender, EventArgs e)
{
// Create the basket, add items, etc.
// Create the pmt, set account info, etc.
int orderId = ProcessPayment(bskt, pmt);
this.ShowStatus(orderId);
this.ShowStatus(orderId); // yes, a repeat
}
protected void Button2_Click(object sender, EventArgs e)
{
ShowStatus(Convert.ToInt32(txtOrderId.Text));
}
private int ProcessPayment(Basket bskt, Payment pmt)
{
CheckoutRequest req = new CheckoutRequest(pmt);
CheckoutResponse resp = bskt.Checkout(req, true, false);
pmt.Authorize();
pmt.Capture(pmt.Amount, true, false);
// pmt.PaymentStatus now equals "Captured"
Order newOrder = pmt.Order;
newOrder.RecalculatePaymentStatus();
newOrder.RecalculateShipmentStatus();
order.Save();
return newOrder.OrderId;
}
private void ShowStatus(int orderId)
{
Order order = OrderDataSource.Load(orderId);
order.RecalculatePaymentStatus();
Response.Write(String.Format("order.OrderStatus={0}<br/>", order.OrderStatus.DisplayName));
Response.Write(String.Format("order.PaymentStatus={0}<br/>", order.PaymentStatus));
}