I've finishing up creating a payment method for Brazil called CobreDireto. Everything is working properly except that I need to have the customer redirected to the CobreDireto payment gateway. For that purpose, I'm creating an OrderNote and am inserting it during the PostProcessPayment method. The insert is working properly, but loading it back so it shows up in the OrderDetails.aspx page is giving me trouble.
The PostProcessPayment code is
public string PostProcessPayment(Order order)
{
//... CODE BEFORE
_order.OrderItems = _items;
Order __order = NopContext.Current.User.Orders[0];
OrderService orderService = new OrderService(NopSolutions.NopCommerce.BusinessLogic.Infrastructure.IoC.Resolve<NopObjectContext>());
try
{
_return = CobreDireto.net.Manager.PayOrder(_processor); //THIS IS WHERE THE PAYMENT GATEWAY PROCESSES THE PAYMENT (EXTERNAL DLL)
ReturnUrl = _return.BPagData.Url; //THE RETURN URL IS THE URL FOR COMPLETING THE PAYMENT (CREDIT CARD, BOLETO, OR DIRECT DEBIT)
if (_return.Status == "0") //STATUS 0 MEANS SUCCESS
{
__order.PaymentStatus = PaymentStatusEnum.Authorized;
HttpContext.Current.Session.Add("paymentUrl", ReturnUrl); //ADD TO THE SESSION VARIABLES THE REDIRECTION URL - THIS IS A POP UP FOR THE PAYMENT COMPLETE PAGE
}
else
{
_result.PaymentStatus = PaymentStatusEnum.Pending;
_result.Error = _return.Message;
}
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
_return = null;
_processor = null;
_payment = null;
_order = null;
_customer = null;
_behavior = null;
_result = null;
//insert a note into the order with the url to the cobreDireto payment portal
orderService.InsertOrderNote(__order.OrderId, ReturnUrl, false, DateTime.UtcNow); //INSERTING THE ORDERNOTE IS WORKING FINE, BUT LOADING IT BACK IS NOT WORKING
}
return string.Empty; // END OF THE METHOD
}
The Order details page is
ORDERDETAILS.ASPX.CS
protected void BindData()
{
//CODE BEFORE HERE ...
this.phReturnRequest.Visible = this.OrderService.IsReturnRequestAllowed(order);
if (order.PaymentStatus != PaymentStatusEnum.Paid)
{
if (order.OrderNotes.Count > 0) //THIS IS ALWAYS RETURNING COUNT = 0 EVEN IF THE ORDER NOTE IS THERE - CHECKED IT WITH SQL MANAGEMENT STUDIO AND THEY'RE ALL THERE
{
string cardTypeDecrypted = SecurityHelper.Decrypt(order.CardType);
if (cardTypeDecrypted.Contains("boleto"))
this.linkPayment.Text = "Imprimir Boleto"; //SHOW LINK TO PRINT BOLETO
else this.linkPayment.Text = "Completar pagamento"; //SHOW LINK TO COMPLETE PAYMENT (CREDIT CARD, OR DIRECT DEBIT)
this.linkPayment.NavigateUrl = order.OrderNotes[0].Note; //THE LINK SHOULD SHOW THE RETURN URL FROM THE POSTPROCESSPAYMENT
}
}
So, in sum, I'm not being able to figure out how to correct this. Sometimes it works (it worked fine this morning until I started testing with more payment methods provided by the gateway) but now it's not even working with the order notes that were working earlier.
I hope to find out where my logic is tricking me here, or if there's a way to reload the order notes somehow without having to manually create the SQL connection and select script.