Copied to clipboard

Flag this post as spam?

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


  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 14:40
    seanrock
    0

    How to finalise an order

    Hi Matt

    Ok so I need to finalise an order but its not obvious how to do that (unless I've overlooked it in the docs?).

    I've got products in the order, i've added shipping and billing properties, i've selected a shipping method and payment method.

    Now I need to finalise the order so that 1) it is not returned by the call to VendrApi.Instance.GetCurrentOrder() and 2) it is returned when i call IOrderService.GetFinalizedOrdersForCustomer().

    Thanks.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 10, 2020 @ 15:09
    Matt Brailsford
    101

    Hey Sean

    If you are wanting to bypass the checkout process and move an order to be finalized without taking payment then you need to call

    order.InitializeTransaction()
    order.Finalize(amount, status)
    
    _orderService.Save(order);
    

    The next time you ask for GetCurrentOrder then it should recognize the current order has finalized and move it into the CurrentFinalized slot.

    /Matt

    Hmm, maybe we should look to just call InitializeTransaction from within Finalize if the transaction isn't already initialized. Would make this a bit simpler. 🤔

  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 15:57
    seanrock
    0

    For anyone elses benefit.

    This did not link the order to the member so I had to add this line..

    order.AssignToCustomer(Members.GetCurrentMember().Key.ToString());
    
  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 15:15
    seanrock
    0

    I'm on the payment page (final page of checkout) so not bypassing checkout per se.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 10, 2020 @ 15:17
    Matt Brailsford
    0

    Ahh, ok, well then the payment providers should take care of that for you.

    Rendering the payment form on your final review step as shown here https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore.Web/Views/CheckoutReviewPage.cshtml#L9 will initialize the transaction for you and render the form for the payment providers redirect. The payment provider is then responsible for finalizing the order once you've gone through the payment gateway.

    /Matt

  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 15:20
    seanrock
    0

    I'll be implementing a custom payment provider that is api based rather than forms.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 10, 2020 @ 15:22
    Matt Brailsford
    0

    Ok, then maybe it's actually worth you outlining the exact process of what you are trying to achieve as I don't think I'm understanding enough to give you the right answer.

    /Matt

  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 15:27
    seanrock
    0

    Ok. Well the checkout process is more or less standard aside from the steps. Our designer has condensed this down to 3 steps (joy!).

    1) Cart 2) Shipping + Billing + Shipping Method 3) Payment > Result

    You may recall my previous query about CalculatePrice() throwing an exception, that is the Shipping Method in step 2.

    The client insists they want the customers to stay on site to complete the transaction so the payment method will be api based. That is, the site will take all the cc details, communicate with the designated provider (tbd) via api calls and then update the order based on the outcome of the transaction, e.g. approved, error or rejected.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 10, 2020 @ 15:36
    Matt Brailsford
    0

    Ahh, ok, so you are wanting an inline checkout process.

    In that case, I'd probably take a look at how this was done in TC for example, the old Stripe payment provider https://github.com/TeaCommerce/Tea-Commerce-Payment-Providers/blob/master/Source/TeaCommerce.PaymentProviders.Stripe/BaseStripeProvider.cs

    Essentially, you'd create a payment provider but when this provider generates it's form, instead of that form redirecting to the payment gateway, you have it redirect to payment page on your site. On that page you access the settings posted to it and display your payment page, then once it's complete you have you form post back to the payment provider to do it's final bits to actually finalize the order.

    This is how I would probably do it.

    Or I guess you could bypass the payment provider process entirely as I stated in my first post and call the finalize method from behind an API controller you post to once you've accepted payment.

    /Matt

  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 15:40
    seanrock
    0

    hmm interesting, i'll have a look at that.

    With the design i've got the payment page, step 3, is where the customer enters the cc details.

    Thanks Matt.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 10, 2020 @ 15:49
    Matt Brailsford
    0

    Yup, so you would want to render the payment form on stage 2 and have the payment provider to redirect to the stage 3 page for where you render your payment form.

    Saying this, the tricky think you might have here is that you need to render the PaymentForm only once the order is completely up to date and about to move to the payment phase. It all being on the one page means it won't be ready till the page is filled in so you may need to do some fun stuff to handle this.

    The way I've done this in the past is to have stage 2 post to a hidden i frame which then updates the order and renders the payment form but uses js to auto submit it redirecting to the payment gateway.

    Maybe given you are handling all the payment side, creating your own API controller might be more straight forward. Maybe just create an empty payment provider to assign payment to, but you manually call finalize setting the relevant captured amount / payment status etc.

    /Matt

  • seanrock 240 posts 461 karma points
    Jul 10, 2020 @ 15:33
    seanrock
    0

    I think calling Finalise on the order is what I need. I've just tried it and I received a confirmation email and now GetCurrentOrder(storeId) returns an empty order.

Please Sign in or register to post replies

Write your reply to:

Draft