+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Place Order using API Subtotal is always 0

Place Order using API Subtotal is always 0

4 posts, 0 answered
  1. Ron
    Ron avatar
    3 posts
    Registered:
    22 Aug 2013
    22 Aug 2013
    Link to this post
    I'm using the API to add a product to the cart and to place the order with a custom MVC widget, using a lot of the code from the OnePageCheckoutWidget sample as a basis.

    Everything seems to be working fine until I call the Checkout method on the OrdersManager class.  It always fails with the message "A valid amount is required" in the GatewayResponse field of the PaymentResponse class that is returned.

    If I log into the backend and view Orders, it shows the order with a Payment status of "Declined".  When I view the order itself, it shows one product with a price of $500.00, but the subtotal & total fields show $0.

    Is there a method I need to call to update / re-calculate the subtotal and total fields when using the API to place an order, possibly before calling the Checkout method of the OrdersManager class? Or any other ideas of what to look for?
  2. Nayden Gochev
    Nayden Gochev avatar
    32 posts
    Registered:
    03 Nov 2014
    26 Aug 2013
    Link to this post
    Hello Ron,
    The CatalogManager.Checkout is a wrapper of :

                OrderCheckout orderCheckout = new OrderCheckout(theCataogManager);
                orderCheckout.Checkout(cartOrderId, checkoutState, customer);

    he just creates an Order object from the Cart object you can use both ways.
    The thing is the CartOrder should be calculated before that before you invoke the Checkout.
    So your problem here is not with the checkout but possibly with the shopping cart. I am not sure how the products/items are added to that cart but in our controls each time a product is added to the cart we do the fallowing call :
     var orderCalculator = ObjectFactory.Resolve<IOrderCalculator>();
     orderCalculator.CalculateAndSaveChanges(shoppingCart);

    So in your code if you do this call before placing the order the total and subtotal and etc should be populated after that.

    About your other issue.. the GatewayResponse field and the PaymentResponse.
    Inside the Checkout method we are trying to process the order.. so in short we are taking the PaymentMethodId and the CreditCardInfo from the CheckoutState and we are trying to send a Transaction to the selected payment method with this credit card details and we receive response from them. I guess in your case you are not using the right PaymentMethod or the CheckoutState is not populated correctly. Just for testing if you set the PaymentMethodId of some Offline Payment Method you should not get any error and the order at the end should have a status Pending.

    Please let me know if you need future assistance.

    Regards,
    Nayden Gochev
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Ron
    Ron avatar
    3 posts
    Registered:
    22 Aug 2013
    26 Aug 2013 in reply to Nayden Gochev
    Link to this post
    Thanks Nayden.  

    My widget needed those two lines of code in order to update the totals correctly.  The payment was getting declined because it was always trying to charge $0.00 - the total was never getting updated properly, so calculating after adding to the cart fixed it.
  4. Nayden Gochev
    Nayden Gochev avatar
    32 posts
    Registered:
    03 Nov 2014
    27 Aug 2013
    Link to this post
    Hello Ron,

    I am glad I was able to help you.

    Please let me know if you need future assistance.

    Regards,
    Nayden Gochev
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered