The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Use Purchase Order option to process certain payments offline

I would like to be able to hold payment requests for offline processing when they meet a couple of requirements. Either the cart total exceeds $1000 or the order is from a non-US address. I think editing the Purchase Order option could make this happen, only I am not sure how to go about it. Thanks for any help. I am using v2.0.
  • fc_jedfc_jed FoxyCart Team

    You might want to consider using this snippet: With a few modifications (adding cart total > $1000 and customer country evaluation) this should work for your requirement.

    This could start you off with your cart total condition:
    if (fc_json.total_price < 1000) {
    This could start you off with your non-US parameter evaluation:
    var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    switch(country_code) {
    case "US":
  • Thanks for that. I did see that snippet, but it was labeled for use with the pre-2.0 versions, so I didn't know if it would work. I did try using it only as directed, but didn't see how it would turn off the payment options and only show the amended purchase order option when the price/location conditions were met (but I didn't quite ask that originally, I just realized). So, is there a way to offer regular payment options in one case, or the amended purchase order option in the other?
  • fc_adamfc_adam FoxyCart Team

    Ah yes - sorry, that wouldn't work with 2.0.

    We can work up something else you could use though - could you quickly clarify what other payment method you support for US based orders under $1000?
  • mastercard/visa, paypal and possibly check
  • fc_adamfc_adam FoxyCart Team

    Sorry, I should have also asked to confirm - are you wanting to only allow purchase orders for transactions over $1000 or non-US customers, as in they won't see any other options for payment apart from the purchase order option?
  • Yes. That is the plan.
  • I am wondering if I can use "supports_pay_with_plastic" and "supports_purchase_order" values to set this up, but I don't know where I should plug them in, if so.
  • fc_adamfc_adam FoxyCart Team

    That's exactly right. The following should cover what you're after:
    {% if context == "checkout" %}<script>
    function poRefresh() {
    requiresApproval = (FC.json.total_order > 1000 || != "US");
    FC.json.config.supports_purchase_order = requiresApproval;
    FC.json.config.supports_pay_with_plastic = !requiresApproval;
    FC.json.show_paypal_express_payment_option = !requiresApproval;

    FC.client.on("ready.done", poRefresh);
    FC.client.on("cart-item-quantity-update.done", poRefresh);
    FC.client.on("cart-item-remove.done", poRefresh);
    FC.client.on("customer-address-change.done", poRefresh);
    FC.client.on("customer-login.done", poRefresh);
    FC.client.on("cart-coupon-add.done", poRefresh);
    FC.client.on("cart-coupon-remove.done", poRefresh);
    </script>{% endif %}
    Paste that code into the "Add custom header and footer code" of your store's configuration section in the admin, to the footer textarea.

    The code will then be inserted into the checkout for you, and will automatically update the payments section on page load, and whenever the address or cart total is altered to ensure it's always up to date with the current cart.
  • @fc_adam,

    That appears to do what we need. Thanks for the help! :)
  • @fc_adam

    How can I cause the purchase order radio button to be pre-selected when the purchase order option becomes available?
  • fc_adamfc_adam FoxyCart Team

    Could you whisper me your store domain please so I can take a quick look at your checkout? I'd like to check something before I reply.
  • fc_adamfc_adam FoxyCart Team
    edited June 2015

    Thanks for whispering that information. Update the poRefresh() function to look like this:
    function poRefresh() {
    requiresApproval = (FC.json.total_order > 10 || != "US");
    FC.json.config.supports_purchase_order = requiresApproval;
    FC.json.config.supports_pay_with_plastic = !requiresApproval;
    FC.json.show_paypal_express_payment_option = !requiresApproval;
    FC.json.config.has_multiple_payment_options = !requiresApproval;
  • Hi @fc_adam,

    If we were looking for something similar, but only allowing PO Payments if a custom field "enterprise" were passed in with the cart (shockingly, to indicate an Enterprise customer was checking out), what would that look like? Is there some form of protection so a clever person didn't figure out the flag and tried to sneak in an order?
  • fc_adamfc_adam FoxyCart Team

    Good question. I'm assuming you're meaning that if someone looked at the source code they would see the flag that was necessary to trigger it? If so - you could instead use Twig logic rather than straight javascript which would obscure it a bit more. The twig template is still included within the javascript to allow client-side rendering, but it would be embedded within the template so would be a bit harder for the clever users to find it.

    If you wanted to completely obscure it, you could send a request off to a secure endpoint on your side to decide, but that might be overkill for what you're needing.
  • A secure endpoint would actually be ideal, and I don't think too hard to sort out, if that means you post back to use to ask if the customer is an Enterprise user or not. Happy to hop on Skype if need be for clarity or to answer any questions.

    What would the twig template tweaks look like as that is definitely preferred over easier to see JS-trickery?
  • fc_adamfc_adam FoxyCart Team

    The secure endpoint would simply be a script you set up on your side, and then you'd set up an ajax call on the checkout that sends over the necessary information to your endpoint - which in turn responds if the user is enterprise or not. It'd be something you'd configure purely on the checkout.

    For the Twig template changes - you'd basically approach what I detailed above but just within Twig logic instead. You'd overwrite the payments block and alter the needed variables. Something like this:
    {% block payment_method %}
    {# logic to set is_enterprise here #}
    {% if is_enterprise %}
    <fieldset id="fc-payment" data-fc-container="payment">
    <legend><span class="fc-section-counter"></span> {{ config.lang.checkout_payment_method|raw }}</legend>
    <input type="hidden" name="fc_payment_method" value="purchase_order" />
    <input type="hidden" name="purchase_order" value="Custom value for Purchase Order" />

    <div class="fc-form-group">
    <div id="fc-payment-method-no-payment-needed" class="fc-container__grid--payment-method fc-payment-method--no-payment fc-payment-method col-md-8 col-md-offset-3">
    <p>Custom message to show to the customer</p>
    {% else %}
    {% set config = config|merge({ supports_purchase_order: false }) %}
    {{ parent() }}
    {% endif %}
    {% endblock %}
    You'd paste that inside the {% embed '' %}{% endembed %} tags in the checkout template. What it does - once you've added in the custom Twig logic to check if it's an enterprise user, is displays the purchase order option if it's the only one present, otherwise it displays the normal payment options - but removes purchase orders from being displayed. You'd still need to have some value or condition that the Twig can check against - but the logic to show that it's using that is slightly more obscured from view.
Sign In or Register to comment.