Copied to clipboard

Flag this post as spam?

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


  • RM 33 posts 95 karma points
    Mar 10, 2022 @ 17:52
    RM
    0

    Show payment type based on type of customer

    Hi There,

    We have a requirement where we want to setup 2 payment methods. Currently the store has credit card payment via Stripe and that is all fine. Now the customer wants to introduce invoice payments but only for a specific customer type, and all other customers would still use the existing checkout.

    We want to make that seamless, so essentially when logged in the customer will automatically be redirected to the correct payment screen. Is there a built in way to do this? if not, is there anywhere i should look first to custom build it?

    Thanks!

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 11, 2022 @ 09:34
    Matt Brailsford
    0

    Hi Roberto

    There isn't anything specific built in, other than a single default payment method settings on the country settings.

    I guess in it's simplest form though from a custom code perspective, when someone logs in you could set the session managers default payment method and any open orders payment methods to invoice, and when they log out, perform the opposite.

    var store = VendrApi.Instance.GetStore("myStore");
    var invoicePaymentMethod = VendrApi.Instance.GetPaymentMethod(store.id, "Invoicing");
    
    VendrApi.Instance.SetDefaultPaymentMethod(invoicePaymentMethod.Id);
    
    var currentOrder = VendrApi.Instance.GetCurrentOrder(store.Id);
    if (currentOrder != null) {
        using(var uow = VendrApi.Instance.Uow.Create()) {
            var writableOrder = currentOrder.AsWritable(uow)
               .SetPaymentMethod(invoicePaymentMethod.Id);
            VendrApi.Instance.SaveOrder(writableOrder);
            uow.Complete();
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft