Discount lookup after a user logs in

We're working out our checkout flow with Foxy, and have hit a snag where we need to substantially alter the cart during checkout. When someone logs in on the Foxy checkout via SSO, we need to look up any discounts they're eligible for on our main server, what funds they have on file, and possibly lower overall prices. We require everything that's added to the cart be signed, so I'm looking at an indirect approach, instead of altering the cart via the FC object. When someone logs in, I'll capture that event on the checkout page. That'll make a GET request back to our server with the email address and Foxy session id. Our server does its lookup, then uses the hAPI to adjust anything needed in the cart. When everything finishes, the GET request returns and it reloads + renders the new cart.

I have all the pieces working, but one: I can't figure out how to go from the fcsid to a cart id that the hAPI can recognize. I could probably find the cart deductively by working backwards from carts index API route, but that makes me uneasy. I could also pass up enough information to recreate the cart, then redirect the user to a new checkout page + fcsid, but that also seems inelegant, and we'd greatly prefer to avoid the refresh. Can someone point me in the right direction? I'd also be happy with a, "no, dummy, you missed this other obvious way to do that," if that's the case!

Thanks

-Patrick
Comments
  • brettbrett FoxyCart Team
    Hey @pmcneill
    Sounds like a pretty cool approach. So, a few things that come to mind:

    First and perhaps most importantly, you can get the transaction ID from the FC json object via `FC.json.transaction_id`. You can then use that to get the cart from the API and make changes serverside.

    Second and more involved: Can you clarify at what step you're modifying the cart? It sounds like you're maybe needing to handle this in two places:

    1. SSO _before_ the customer lands on the checkout. So if they're already authenticated on your end and hit checkout, your SSO endpoint can do everything behind the scenes, then redirect then to checkout and everything will be updated.

    2. On the checkout itself, so an unauthenticated user lands on checkout, then enters their email+pass. _Then_ you want to adjust their cart?

    Is that correct? For #2, we might need to help you figure out how to refresh the cart contents and re-render the page, so let us know about that.
  • pmcneillpmcneill Member
    Hi Brett,

    Thanks! I was so focused on cart_id that I missed the transaction_id - that should definitely help me close the loop on things.

    Discounts are one aspect of the project. If the user is already logged in, in a way that our SSO end point will recognize, we add any eligible discounts and pricing to the cart from the get-go. Since that's the case, your first point doesn't apply to us. We really are just trying to handle unauthenticated users who log in on the checkout page, your second scenario.

    As for refreshing the cart, I think I've got that taken care of, with something like:


    $.get("server_url_and_path_here").then((result) => {
    // magic here
    // now refresh the cart from the server
    FC.client.updateCart().then(() => FC.cart.render());
    });


    Thanks again!
  • fc_adamfc_adam FoxyCart Team
    @pmcneill,

    Awesome - sounds like you've got everything sorted then! Let us know if we can help with anything else as you work through it.
Sign In or Register to comment.