Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 57 additions & 5 deletions src/Objects/Order/PaymentsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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')) {
Expand Down Expand Up @@ -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
Expand Down