I've got a multiple sites setup in Craft, with Craft Commerce running on top.

What I need to do is for one of the Payment Gateways, send a different API Key, based on the site that's being accessed.

My intent was to define each of the API Keys in the env config, so SITE_1_API_KEY etc, then add a conditional into the commerce-gateways.php config file, that would set a different env var based on the site handle being accessed.

I can't find any documented way of setting a conditional for this though, either by site handle or hostname.

1 Answer 1


Minutes after posting, came up with the answer, why didn't I think of this solution before.

Rather than switching out API Keys, instead, I'm creating multiple payment gateways. Then conditionally loading the gateways in the template based on the site handle.

This has the added benefit of ensuring when we do refunds, it will refund against the correct gateway.

Would be nice if Payment Gateways could be associated with a store in the future, guess that will come with multi site support in Commerce 5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.