From e40a17411e09e7284644e4657d3109cb0c1a4812 Mon Sep 17 00:00:00 2001 From: Jose Martinez Date: Sat, 5 Sep 2026 02:14:59 +0200 Subject: [PATCH] Let sites map custom payment gateways to their own Splash code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit encodePaymentMethod() matches six known gateway ids and sends everything else as "DirectDebit". A bank transfer, a holiday voucher and a card therefore reach the target as the same thing, and getGatewaysList() collapses every custom gateway under a single key. Targets are more capable than that. Dolibarr's PaymentMethods::getDoliCode(), for one, falls back to searching its own payment methods by code and by label when a code is not in its dictionary — so a site that sends "ANCV" gets its holiday-voucher method resolved. The information is lost before it leaves WooCommerce, not on arrival. Add two symmetrical filters: - splash_encode_payment_method($code, $gatewayId) - splash_decode_payment_method($gatewayId, $code) Symmetry matters: setPaymentsFields() compares the encoded method with the incoming one and writes back decodePaymentMethod(). Without the second filter, a custom code mapped on the way out would come back as "other" and overwrite the order's real gateway. The detection logic moves unchanged into detectPaymentMethod() and detectGateway(). Default behaviour is identical when no filter is registered. Co-Authored-By: Claude Opus 5 --- src/Objects/Order/PaymentsTrait.php | 62 ++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/Objects/Order/PaymentsTrait.php b/src/Objects/Order/PaymentsTrait.php index 402dd21..49ec6df 100644 --- a/src/Objects/Order/PaymentsTrait.php +++ b/src/Objects/Order/PaymentsTrait.php @@ -229,11 +229,9 @@ private function getGatewaysList(): array /** * Try To Detect Payment method Standardized Name * - * @param null|string $method + * @param null|string $method WooCommerce Gateway Id, Current Order Gateway if Null * * @return string - * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ private function encodePaymentMethod(string $method = null): string { @@ -242,6 +240,35 @@ private function encodePaymentMethod(string $method = null): string $method = $this->object->get_payment_method(); } + //====================================================================// + // Filter the Splash code detected for a WooCommerce Gateway + // + // Gateways this connector does not know about fall back to + // "DirectDebit", so a bank transfer, a voucher and a card all reach the + // target as the same thing. Use this filter to give a custom gateway a + // code of its own — targets resolve unknown codes against their own + // payment methods. + // + // @param string $code Splash payment method code + // @param string $method WooCommerce gateway id + return (string) apply_filters( + 'splash_encode_payment_method', + $this->detectPaymentMethod($method), + $method + ); + } + + /** + * Detect Payment method Standardized Name from Known Gateways + * + * @param string $method WooCommerce Gateway Id + * + * @return string + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + private function detectPaymentMethod(string $method): string + { //====================================================================// // Detect All Paypal Payment Methods if (false !== strpos($method, 'paypal')) { @@ -274,13 +301,38 @@ private function encodePaymentMethod(string $method = null): string } /** - * Try To Detect Payment method Standardized Name + * Try To Detect WooCommerce Gateway Id from Standardized Name * - * @param string $method + * @param string $method Splash Payment Method Code * * @return string */ private function decodePaymentMethod(string $method): string + { + //====================================================================// + // Filter the WooCommerce Gateway used for a Splash code + // + // Kept symmetrical with splash_encode_payment_method: a custom code + // mapped on the way out must map back on the way in, otherwise writing + // an order would replace its real gateway with "other". + // + // @param string $gateway WooCommerce gateway id + // @param string $method Splash payment method code + return (string) apply_filters( + 'splash_decode_payment_method', + $this->detectGateway($method), + $method + ); + } + + /** + * Detect WooCommerce Gateway Id from Known Standardized Names + * + * @param string $method Splash Payment Method Code + * + * @return string + */ + private function detectGateway(string $method): string { //====================================================================// // Detect Payment Method Type from Default Payment "known" methods