Inserting OrderNote during PostProcessPayment not working correctly

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 лет назад
Hello Folks,

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.
12 лет назад
For now my workaround has been to create my own OrderNote extension method (BASED ON THE ORIGINAL CLASS) to pull out the note I want based on the OrderId

public static class OrderNotes
    {
        /// <summary>
        /// Gets an order note
        /// </summary>
        /// <param name="orderNoteId">Order note identifier</param>
        /// <returns>Order note</returns>
        public static OrderNote GetOrderNoteByOrderId(int orderId)
        {
            if (orderId == 0)
                return null;

            NopObjectContext _context = NopSolutions.NopCommerce.BusinessLogic.Infrastructure.IoC.Resolve<NopObjectContext>();
            var query = from onote in _context.OrderNotes
                        where onote.OrderId == orderId && onote.Note.Contains("https://") // THE NOTES WILL ALWAYS BE A URL SO IT'S ONLY A MATTER OF PULLING OUT THE ONE WITH THE URL - JUST IN CASE THERE ARE OTHER NOTES ADDED LATER
                        select onote;
            OrderNote orderNote = query.FirstOrDefault();
            return orderNote;
        }
    }


But, if there's another ***SIMPLER*** way to do this I'd prefer it over my cumbersome method.
11 лет назад
I'm using v2.5, one page checkout and don't see order note during the checkout, is it configurable in the admin panel?
11 лет назад
I've created a custom class just for that feature. You can copy the code and use it if you'd like.
11 лет назад
Oh so it's not implemented yet.  That's ok I'll write mine (since my nop is customized so much now).  Thanks for the offer though...Thought I could get some easy way out.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.