Copied to clipboard

Flag this post as spam?

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


  • Simon 81 posts 184 karma points
    Nov 07, 2016 @ 12:56
    Simon
    0

    Get Total (including shipping) in PaymentProvider form

    Hi,

    I'm trying to get out the total to bill (basket total + shipping) in my payment form. For Stripe, we need to do something like this:

    <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="pk_test_blahblahblah"
            data-amount="@Model.TotalBasketPriceInPence"
            data-name="Some company"
            data-description="Widget"
            data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
            data-locale="auto"
            data-currency="gbp">
    </script>
    

    However, for the life of me I can't find this total anywhere: I've tried this:

    var model = this.CheckoutPaymentModelFactory.Create(CurrentCustomer, paymentMethod);
    model.TotalBasketPriceInPence = Convert.ToInt32(this.Basket.TotalBasketPrice * 100);
    

    But that just returns the total basket value excluding any shipping charge.

    Don't mind if it's in a value I then add to my model I pass to the MVC view or set in the MVC view itself.

    Thanks!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 07, 2016 @ 16:38
    Rusty Swayne
    0

    Hey Simon,

    You want to use the CheckoutManager.Payment.PrepareInvoice() method. Unless you have done a some customizations, the basket will never have a shipping line item. This is due to in many (most) cases, when values in the basket (quantity, items, etc) change the shipping quote needs to be performed again.

    The typical workflow works like:

    Basket -> Basket.PackageShipments() -> Quote Shipments -> Save quote in checkout manager -> Prepare Invoice -> payment

  • Simon 81 posts 184 karma points
    Nov 07, 2016 @ 16:50
    Simon
    0

    Hi Rusty,

    Basket doesn't seem to have a PackageShipments function?

    Where do I go from here:

    var shipment = this.Basket.PackageBasket(this.CheckoutManager.Customer.GetShipToAddress());
    shipment.FirstOrDefault().???
    

    Should add that this is using FastTrack as a basis. Also, as the Order Summary panel to the right shows the complete total (including shipping) the value should be available somewhere?

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 07, 2016 @ 17:45
    Rusty Swayne
    0

    You're right - PackageBasket is the one your looking for. On the road today so I was going from memory =)

    So I don't misquote again - there is an extension of of the shipment ... but checkout the FastTrack code here https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Factories/CheckoutShipRateQuoteModelFactory.cs#L65

  • Simon 81 posts 184 karma points
    Nov 09, 2016 @ 13:24
    Simon
    0

    Hi Rusty,

    Thanks for that - but there's a much easier route if you're using the default FastTrack checkout.

    By the time you hit the PaymentForm in the payment provider you've already gone through the Shipping Quote stage so to get the total order cost, including any shipping and taxes you can simply do this:

    decimal totalCost = this.CheckoutManager.Context.ItemCache.Items.Sum(t => t.TotalPrice);
    

    Rusty - any problems you can see with this shortcut?

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 10, 2016 @ 14:16
    Rusty Swayne
    0

    Hi Simon,

    It really depends how fully your are relying on the checkout workflow. By circumventing the invoice builder you are not doing things like ensuring line times are all tagged with a currency code, applying discounts or calculating taxes on shipping (if that is required).

    In fact, if you were relying on taxing the sale like we do in the US, you would not have a tax line item at that point ... and as mentioned the discounts will not be applied.

    Probably a bitter approach would be:

     var invoice = CheckoutManager.Payment.PrepareInvoice();
     var totalCode = invoice.Total;
    
Please Sign in or register to post replies

Write your reply to:

Draft