Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Dev 8 posts 28 karma points
    Jul 22, 2012 @ 15:21
    Dev
    0

    Adding the completed order to New Orders list programatically

    Hi,

    I implemented the solution (in asp.net usercontrol) provided by Søren Spelling Lund in the following post.

    http://our.umbraco.org/projects/website-utilities/ucommerce/ucommerce-support/29925-step-by-step-Process-on-Ordering?p=0#comment122570

     

    At the end of the code after CreatePayment() call, I added Library.RequestPayment() to redirect to PayPal sandbox. It also worked fine and the payment process through PayPal sandbox was completed successfully.

    Now I want to get this order, listed in the New Orders List in the uCommerce section. I guess this would require additional coding but since i am new to uCommerce I don't know its api libraries much. I tried to execute "checkout" pipeline at the end of the code but it threw some security exception that the payment is not sufficient for the order guid..... I also tried to execute "saveorder" pipeline in the end but it had no effect.

    I have added the code below just in case:

            protected void btnBuyProdNow_Click(object sender, EventArgs e)
            {
                // First load the current catalog (URLs will contain this information)
                int catalogId = 0;
                string catalogName = "uCommerce";
                ProductCatalog catalog;
                SiteContext.Current.OrderContext.NewBasket(Currency.SingleOrDefault(x => x.ExchangeRate == 100));
                if (int.TryParse(SiteContext.Current.CatalogContext.CurrentCatalogName, out catalogId))
                    catalog = ProductCatalog.Get(catalogId);
                else
                    catalog = ProductCatalog.SingleOrDefault(x => x.Name == catalogName);
                // Then load the product to add
                Product product = Product.All().Single(x => x.Sku == "MyProd-01");
                PurchaseOrder order = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
                order.AddProduct(catalog, product, 1);
                // Exec basket pipeline to update totals
                Library.ExecuteBasketPipeline();
                /* BILLING */
                var address = order.BillingAddress ?? new OrderAddress();
                address.AddressName = "Billing";
                address.FirstName = "firstName";
                address.LastName = "lastName";
                address.EmailAddress = "emailAddress";
                address.PhoneNumber = "phoneNumber";
                address.MobilePhoneNumber = "mobilePhoneNumber";
                address.CompanyName = "company";
                address.Line1 = "line1";
                address.Line2 = "line2";
                address.PostalCode = "postCode";
                address.City = "city";
                address.State = "state";
                address.Attention = "attention";
                address.Country = Country.FirstOrDefault(x => x.Name == "Great Britain");
                address.PurchaseOrder = order;
                order.BillingAddress = address;
                order.Save(); // Saves cascade to children, so the address is saved as well
                /* SHIPPING */
                // First we'll need a shipping method using the name as defined in the backend, e.g. Ground or Air
                var shippingMethod = ShippingMethod.SingleOrDefault(x => x.Name == "Download");
                var shipment = order.CreateShipment(shippingMethod, address);
                // Add all order lines to shipment using a handy extension mehod in UCommerce.Extensions called ForEach
                order.OrderLines.ForEach(x => shipment.AddOrderLine(x));
                // Execute basket pipeline to make sure totals are up to date
                // Also save order and new shipment           
                PipelineFactory.Create<PurchaseOrder>("basket").Execute(order);
                /* PAYMENT */
                // As with shipping grab the payment method to use by name as defined in the backend
                var paymentMethod = PaymentMethod.SingleOrDefault(x => x.Name == "PayPal");
                // Use the library to create the payment and request it from the gateway
                Library.CreatePayment(paymentMethod.Id);
                // Alternatively you can use to defer the request if you
                // need to display an confirm page before handing it over
                // to the gateway. The false value indicates that the request
                // should be deferred.
                // You can then use Library.RequestPayments()
                // to trigger the gateway
                Library.CreatePayment(paymentMethod.Id, -1, false, true);
                Library.RequestPayments();
            }

    Kindly help me in this issue. Many thanks.

    PS: Just in case if this is related, I want to integrate the above code in umbraco contour, either in a workflow or as a new FieldType to be added in the last contour step. The purpose is ... the user would complete all the form steps and in the end, either a BuyProd button will complete the actual transaction and return to the last step again. Or ... the actual submit button of contour will execute a custom workflow that would contain the above mentioned code.

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Aug 07, 2012 @ 11:07
    Søren Spelling Lund
    0

    The reason for the exception is that the payments on the order don't cover the entire order total.

    If you PurchaseOrder.OrderTotal amount is the same as the Payment.Amount the payment status might not be updated properly on the payment itself. uCommerce required payment status to be set to "Authorized" or "Acquired" for the payment amount to count against the total of the order. 

  • brinck10 24 posts 55 karma points
    Aug 09, 2012 @ 15:59
    brinck10
    0

    Hi Søren.

    I'm facing the same problem, however I don't know how to work around it with the information you just provided. Can you please elaborate on it?

    Best regards, Brinck10 

  • brinck10 24 posts 55 karma points
    Aug 15, 2012 @ 16:04
    brinck10
    0

    Well, I've been trying to figure out the problem and my foundings are as follows:

    1. The DIBS gateway succeeds creating the invoice and the transaction goes through with the correct amount of payment.

    2. I get the security error on the order confirmation page containing the following code c# in the Page_Load function:

    var b = SiteContext.Current.OrderContext.GetBasket(true);

    var po = b.PurchaseOrder;

    var plco = PipelineFactory.Create("Checkout");

    plco.Execute(po);

    3. When I try to show the sum of the basket on the order confirmation page the correct number is displayed, however, when I do the same for the payment an amount of zero euroes is displayed. The code I use is:

    var b = SiteContext.Current.OrderContext.GetBasket(true);

    var po = b.PurchaseOrder;

    InformationMessage.Text = po.PaymentTotal.ToString();

    Therefore, I think there is a problem with the callback between DIBS and the page - also uCommerce required payment status to Authorized; where do I do so?

    Best regards, Brinck10

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Aug 29, 2012 @ 10:43
    Søren Spelling Lund
    0

    Typically you want the checkout pipeline to be called when you receive a succesful callback from the payment provider as this is the only event that will tell whether the customer actually paid or not.

    Setup uCommerce to Include DIBS as a Payment method describes how to set up the pipeline to be executed upon callback (just select "Checkout" in the pipelines drop down list).

    Ideally your confirmation page should only handle displaying a receipt based on the provided orderGuid in the URL.

Please Sign in or register to post replies

Write your reply to:

Draft