Skip to content

Commit

Permalink
Fix cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Dec 27, 2024
1 parent 078b27c commit 31e7c62
Show file tree
Hide file tree
Showing 35 changed files with 145 additions and 193 deletions.
6 changes: 4 additions & 2 deletions inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ function mollieWooCommerceIsVoucherEnabled()
*/
function mollieWooCommerceIsMollieGateway($gateway)
{
if ((is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false)
|| (is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false)) {
if (
(is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false)
|| (is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false)
) {
return true;
}
return false;
Expand Down
1 change: 0 additions & 1 deletion src/Buttons/ApplePayButton/ResponsesToApple.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ private function reorderShippingMethods(array $methods, array $selectedShippingM
return array_merge($reordered_methods, array_values($methods));
}


/**
* Returns a success response to be handled by the script
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Buttons/PayPalButton/PayPalAjaxRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Mollie\WooCommerce\Buttons\PayPalButton;

use Inpsyde\PaymentGateway\PaymentGateway;
use Mollie\WooCommerce\Gateway\Surcharge;
use Mollie\WooCommerce\Notice\NoticeInterface;
use Mollie\WooCommerce\Shared\GatewaySurchargeHandler;
Expand Down Expand Up @@ -31,7 +32,7 @@ class PayPalAjaxRequests
*
* @param $gateway
*/
public function __construct($gateway, NoticeInterface $notice, Logger $logger)
public function __construct(PaymentGateway $gateway, NoticeInterface $notice, Logger $logger)
{
$this->gateway = $gateway;
$this->notice = $notice;
Expand Down
1 change: 0 additions & 1 deletion src/Gateway/DeprecatedGatewayBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,4 @@ public function instantiatePaymentMethodGateways(ContainerInterface $container):
}
return $gateways;
}

}
23 changes: 10 additions & 13 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,17 @@ public function run(ContainerInterface $container): bool
static function ($gateways) use ($container) {
$deprecatedGatewayHelpers = $container->get('__deprecated.gateway_helpers');
foreach ($gateways as $gateway) {
$isMolliegateway = is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false
|| is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false;
if (!$isMolliegateway) {
continue;
}

$isMolliegateway = is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false
|| is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false;
if (!$isMolliegateway) {
continue;
}

$isSubscriptiongateway = $gateway->supports('subscriptions');
if ($isSubscriptiongateway) {
$deprecatedGatewayHelpers[$gateway->id]->addSubscriptionFilters($gateway);
}
}
$isSubscriptiongateway = $gateway->supports('subscriptions');
if ($isSubscriptiongateway) {
$deprecatedGatewayHelpers[$gateway->id]->addSubscriptionFilters($gateway);
}
}
return $gateways;
},
30
Expand Down Expand Up @@ -149,7 +148,6 @@ static function () {
// Set order to paid and processed when eventually completed without Mollie
add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1);


$surchargeService = $container->get(Surcharge::class);
assert($surchargeService instanceof Surcharge);
$this->gatewaySurchargeHandling($surchargeService);
Expand Down Expand Up @@ -194,7 +192,6 @@ public function services(): array
static $services;

if ($services === null) {

$services = require_once __DIR__ . '/inc/services.php';
}

Expand Down
55 changes: 6 additions & 49 deletions src/Gateway/MolliePaymentGatewayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class MolliePaymentGatewayHandler
/**
* Recurring total, zero does not define a recurring total
*
* @var int
* @var array
*/
protected $recurring_totals = 0;
protected $recurring_totals = [];
/**
* @var PaymentMethodI
*/
Expand Down Expand Up @@ -82,6 +82,9 @@ class MolliePaymentGatewayHandler
*/
protected $pluginId;

protected string $enabled;
protected string $id;

/**
*
*/
Expand Down Expand Up @@ -114,7 +117,6 @@ public function __construct(
// Use gateway class name as gateway id
$this->gatewayId();


if (!has_action('woocommerce_thankyou_' . $this->id)) {
add_action(
'woocommerce_thankyou_' . $this->id,
Expand All @@ -140,8 +142,6 @@ public function __construct(
[$this->mollieOrderService, 'onWebhookAction']
);



// Adjust title and text on Order Received page in some cases, see issue #166
add_filter('the_title', [$this, 'onOrderReceivedTitle'], 10, 2);
add_filter(
Expand All @@ -151,13 +151,12 @@ public function __construct(
2
);


$isEnabledAtWoo = $this->paymentMethod->getProperty('enabled') ?
$this->paymentMethod->getProperty('enabled') :
'yes';
$this->enabled = $isEnabledAtWoo;

if ($this->enabled && $this->paymentMethod->getProperty('filtersOnBuild')) {
if ($this->enabled === 'yes' && $this->paymentMethod->getProperty('filtersOnBuild')) {
$this->paymentMethod->filtersOnBuild();
}
//$this->refundProcessor = new RefundProcessor($this);
Expand All @@ -183,15 +182,13 @@ public function pluginId()
return $this->pluginId;
}


protected function gatewayId()
{
$paymentMethodId = $this->paymentMethod->getProperty('id');
$this->id = 'mollie_wc_gateway_' . $paymentMethodId;
return $this->id;
}


/**
* Check if the gateway is available for use
*
Expand Down Expand Up @@ -283,23 +280,6 @@ public function get_recurring_total()
return $this->recurring_totals;
}

/**
* @param int $orderId
*
* @return array
*/
public function process_payment($orderId)
{
$order = wc_get_order($orderId);
if (!$order) {
return $this->noOrderPaymentFailure($orderId);
}
$paymentMethod = $this->paymentMethod;
$redirectUrl = $this->get_return_url($order);
$this->paymentProcessor->setGateway($this);
return $this->paymentProcessor->processPayment($orderId, $order, $paymentMethod, $redirectUrl);
}

/**
* @param $order
* @param $payment
Expand Down Expand Up @@ -409,30 +389,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string
*/
return $returnRedirect;
}
/**
* @param $orderId
* @return string[]
*/
protected function noOrderPaymentFailure($orderId): array
{
$this->logger->debug(
$this->id . ': Could not process payment, order ' . $orderId . ' not found.'
);

$this->notice->addNotice(
'error',
sprintf(
/* translators: Placeholder 1: order id. */
__(
'Could not load order %s',
'mollie-payments-for-woocommerce'
),
$orderId
)
);

return ['result' => 'failure'];
}
/**
* Retrieve the payment object
*
Expand Down
10 changes: 5 additions & 5 deletions src/Gateway/Refund/RefundProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RefundProcessor implements RefundProcessorInterface
{
private $deprecatedGatewayHelper;

public function __construct( $deprecatedGatewayHelper)
public function __construct($deprecatedGatewayHelper)
{
$this->deprecatedGatewayHelper = $deprecatedGatewayHelper;
}
Expand Down Expand Up @@ -44,10 +44,10 @@ public function refundOrderPayment(WC_Order $wcOrder, $amount = null, $reason =

// Mollie Payment object not found
if (!$payment_object_id) {
$error_message = __("Can\'t process refund. Could not find Mollie Payment object id for order $order_id.", 'mollie-payments-for-woocommerce');
$error_message = __("Can\'t process refund. Could not find Mollie Payment object id for order %s.", 'mollie-payments-for-woocommerce');

$this->deprecatedGatewayHelper->getLogger()->debug(
__METHOD__ . ' - ' . $error_message
__METHOD__ . ' - ' . sprintf($error_message, $order_id)
);

throw new Exception($error_message);
Expand All @@ -66,9 +66,9 @@ public function refundOrderPayment(WC_Order $wcOrder, $amount = null, $reason =
}

if (!$payment_object || !is_object($payment_object)) {
$error_message = __("Can\'t process refund. Could not find Mollie Payment object data for order $order_id.", 'mollie-payments-for-woocommerce');
$error_message = __("Can\'t process refund. Could not find Mollie Payment object data for order %s.", 'mollie-payments-for-woocommerce');
$this->deprecatedGatewayHelper->getLogger()->debug(
__METHOD__ . ' - ' . $error_message
__METHOD__ . ' - ' . sprintf($error_message, $order_id)
);

throw new Exception($error_message);
Expand Down
12 changes: 4 additions & 8 deletions src/Gateway/inc/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@
assert($notice instanceof AdminNotice);
$logger = $container->get(Logger::class);
assert($logger instanceof Logger);
$paypalGateway = isset($container->get('__deprecated.gateway_helpers')['mollie_wc_gateway_paypal']) ? $container->get(
'__deprecated.gateway_helpers'
)['mollie_wc_gateway_paypal'] : false;
$paymentGateways = $container->get('payment_gateways');
$paypalGateway = $paymentGateways['mollie_wc_gateway_paypal'];
$pluginUrl = $container->get('shared.plugin_url');
$ajaxRequests = new PayPalAjaxRequests($paypalGateway, $notice, $logger);
$data = new DataToPayPal($pluginUrl);
Expand Down Expand Up @@ -283,7 +282,6 @@
];
$paymentMethods = SharedDataDictionary::GATEWAY_CLASSNAMES;


$dynamicServices = [];
foreach ($paymentMethods as $paymentMethod) {
$gatewayId = strtolower($paymentMethod);
Expand All @@ -298,8 +296,7 @@
$paymentProcessor->setGateway($deprecatedGatewayHelper);
return $paymentProcessor;
};
$dynamicServices["payment_gateway.$gatewayId.refund_processor"] = static function (ContainerInterface $container
) use ($gatewayId): RefundProcessorInterface {
$dynamicServices["payment_gateway.$gatewayId.refund_processor"] = static function (ContainerInterface $container) use ($gatewayId): RefundProcessorInterface {
$getProperty = $container->get('gateway.getMethodPropertyByGatewayId');
$supports = $getProperty($gatewayId, 'supports');
$supportsRefunds = $supports && in_array('refunds', $supports, true);
Expand Down Expand Up @@ -370,7 +367,7 @@
};
$dynamicServices["payment_gateway.$gatewayId.availability_callback"] = new Factory(
['__deprecated.gateway_helpers'],
static function (array $gatewayInstances) use($gatewayId): callable {
static function (array $gatewayInstances) use ($gatewayId): callable {
return static function ($gateway) use ($gatewayInstances, $gatewayId): bool {
return $gatewayInstances[$gatewayId]->is_available($gateway);
};
Expand All @@ -397,7 +394,6 @@ static function (array $gatewayInstances) use($gatewayId): callable {
$supports = array_merge($supports, $subscriptionHooks);
}
return $supports;

};
$dynamicServices["payment_gateway.$gatewayId.settings_field_renderer.multi_select_countries"] = static function (ContainerInterface $container) use ($gatewayId) {
$paymentMethods = $container->get('gateway.paymentMethods');
Expand Down
7 changes: 3 additions & 4 deletions src/Payment/MollieObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function __construct(
Settings $settingsHelper,
string $pluginId,
RequestFactory $requestFactory
)
{
) {

$this->data = $data;
$this->logger = $logger;
$this->paymentFactory = $paymentFactory;
Expand Down Expand Up @@ -414,8 +414,7 @@ public function getActiveMolliePayment($order_id, $use_cache = true)

try {
$mollie_order = $this->paymentFactory->getPaymentObject(
$mollie_order,
$this->paymentMethod
$mollie_order
);
} catch (ApiException $exception) {
$this->logger->debug($exception->getMessage());
Expand Down
18 changes: 12 additions & 6 deletions src/Payment/MollieOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Mollie\WooCommerce\Shared\Data;
use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Log\LoggerInterface as Logger;

use Psr\Log\LogLevel;
use WC_Order;
use WP_Error;
Expand Down Expand Up @@ -60,8 +59,8 @@ public function __construct(
Logger $logger,
OrderLines $orderLines,
RequestFactory $requestFactory
)
{
) {

$this->data = $data;
$this->orderItemsRefunder = $orderItemsRefunder;
$this->pluginId = $pluginId;
Expand Down Expand Up @@ -99,7 +98,6 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego
return $this->requestFactory->createRequest('order', $order, $customerId);
}


public function setActiveMolliePayment($orderId)
{
self::$paymentId = $this->getMolliePaymentIdFromPaymentObject();
Expand Down Expand Up @@ -157,7 +155,15 @@ public function getMollieCustomerIbanDetailsFromPaymentObject($payment = null)
$ibanDetails = [];

if (isset($payment->_embedded->payments[0]->id)) {
$actualPayment = new MolliePayment($payment->_embedded->payments[0]->id, $this->pluginId, $this->apiHelper, $this->settingsHelper, $this->dataHelper, $this->logger);
$actualPayment = new MolliePayment(
$payment->_embedded->payments[0]->id,
$this->pluginId,
$this->apiHelper,
$this->settingsHelper,
$this->dataHelper,
$this->logger,
$this->requestFactory
);
$actualPayment = $actualPayment->getPaymentObject($actualPayment->data);
/**
* @var Payment $actualPayment
Expand Down Expand Up @@ -921,7 +927,7 @@ protected function processOrderItemsRefund(
unset($items[$item->get_id()]);
}

public function setOrder( $data)
public function setOrder($data)
{
$this->data = $data;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Payment/MollieOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public function onWebhookAction()
// Load the payment from Mollie, do not use cache
try {
$payment_object = $this->paymentFactory->getPaymentObject(
$payment_object_id,
null
$payment_object_id
);
} catch (ApiException $exception) {
$this->httpResponse->setHttpResponseCode(400);
Expand Down
Loading

0 comments on commit 31e7c62

Please sign in to comment.