Skip to content

Commit

Permalink
Move refund files to its folder and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Dec 24, 2024
1 parent 863b1c9 commit 6a3fa30
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 23 deletions.
3 changes: 2 additions & 1 deletion inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ function mollieWooCommerceIsVoucherEnabled()
*/
function mollieWooCommerceIsMollieGateway($gateway)
{
if (strpos($gateway, '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
11 changes: 8 additions & 3 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ public function run(ContainerInterface $container): bool
'woocommerce_payment_gateways',
static function ($gateways) use ($container) {
$deprecatedGatewayHelpers = $container->get('__deprecated.gateway_helpers');

foreach ($gateways as $gateway) {
$isMolliegateway = strpos($gateway, 'mollie_wc_gateway_') !== false;

$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 ($isMolliegateway && $isSubscriptiongateway) {
if ($isSubscriptiongateway) {
$deprecatedGatewayHelpers[$gateway->id]->addSubscriptionFilters($gateway);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\Payment;
namespace Mollie\WooCommerce\Gateway\Refund;

use Mollie\Api\Endpoints\OrderEndpoint;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Plugin;
use Mollie\WooCommerce\Shared\Data;
use UnexpectedValueException;
use WC_Order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\Payment;
namespace Mollie\WooCommerce\Gateway\Refund;

use Mollie\Api\Types\OrderLineStatus as ApiOrderLineStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\Payment;
namespace Mollie\WooCommerce\Gateway\Refund;

use UnexpectedValueException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\Payment;
namespace Mollie\WooCommerce\Gateway\Refund;

use Mollie\WooCommerce\Shared\Data;
use stdClass;
Expand Down
1 change: 0 additions & 1 deletion src/Gateway/Refund/RefundProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Exception;
use Inpsyde\PaymentGateway\RefundProcessorInterface;
use Mollie\Api\Exceptions\ApiException;
use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI;
use WC_Order;

class RefundProcessor implements RefundProcessorInterface
Expand Down
15 changes: 15 additions & 0 deletions src/Gateway/inc/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Inpsyde\PaymentGateway\RefundProcessorInterface;
use Mollie\WooCommerce\Gateway\DeprecatedGatewayBuilder;
use Mollie\WooCommerce\Gateway\OrderMandatoryGatewayDisabler;
use Mollie\WooCommerce\Gateway\Refund\OrderItemsRefunder;
use Mollie\WooCommerce\Gateway\Refund\RefundLineItemsBuilder;
use Mollie\WooCommerce\Gateway\Refund\RefundProcessor;
use Mollie\WooCommerce\Gateway\Surcharge;
use Mollie\WooCommerce\Notice\AdminNotice;
Expand Down Expand Up @@ -110,6 +112,19 @@
$pluginPath = $container->get('shared.plugin_path');
return new IconFactory($pluginUrl, $pluginPath);
},
RefundLineItemsBuilder::class => static function (ContainerInterface $container): RefundLineItemsBuilder {
$data = $container->get('settings.data_helper');
return new RefundLineItemsBuilder($data);
},
OrderItemsRefunder::class => static function (ContainerInterface $container): OrderItemsRefunder {
$data = $container->get('settings.data_helper');
$refundLineItemsBuilder = $container->get(RefundLineItemsBuilder::class);
$apiHelper = $container->get('SDK.api_helper');
$apiKey = $container->get('settings.settings_helper')->getApiKey();
$orderEndpoint = $apiHelper->getApiClient($apiKey)->orders;

return new OrderItemsRefunder($refundLineItemsBuilder, $data, $orderEndpoint);
},
PaymentService::class => static function (ContainerInterface $container): PaymentService {
$logger = $container->get(Logger::class);
assert($logger instanceof Logger);
Expand Down
4 changes: 0 additions & 4 deletions src/Payment/MollieObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

class MollieObject
{
public const MAXIMAL_LENGHT_ADDRESS = 100;
public const MAXIMAL_LENGHT_POSTALCODE = 20;
public const MAXIMAL_LENGHT_CITY = 200;
public const MAXIMAL_LENGHT_REGION = 200;
protected $data;
/**
* @var string[]
Expand Down
2 changes: 2 additions & 0 deletions src/Payment/MollieOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Gateway\Refund\OrderItemsRefunder;
use Mollie\WooCommerce\Gateway\Refund\PartialRefundException;
use Mollie\WooCommerce\Payment\Request\RequestFactory;
use Mollie\WooCommerce\PaymentMethods\Voucher;
use Mollie\WooCommerce\SDK\Api;
Expand Down
2 changes: 0 additions & 2 deletions src/Payment/MollieSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Mollie\WooCommerce\Payment;

use Inpsyde\PaymentGateway\PaymentGateway;
use Mollie\Api\Types\SequenceType;
use Mollie\WooCommerce\Gateway\MolliePaymentGatewayHandler;
use Mollie\WooCommerce\SDK\Api;
use Mollie\WooCommerce\Subscription\MollieSubscriptionGatewayHandler;

Expand Down
5 changes: 1 addition & 4 deletions src/Payment/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
use Inpsyde\Modularity\Module\ExecutableModule;
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
use Inpsyde\Modularity\Module\ServiceModule;
use Inpsyde\PaymentGateway\PaymentGateway;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Gateway\MolliePaymentGatewayHandler;
use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI;
use Mollie\WooCommerce\Gateway\Refund\OrderItemsRefunder;
use Mollie\WooCommerce\SDK\Api;
use Mollie\WooCommerce\SDK\HttpResponse;
use Mollie\WooCommerce\Settings\Settings;
use Mollie\WooCommerce\Shared\Data;
use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface as Logger;
use Psr\Log\LogLevel;
use RuntimeException;
use WC_Order;

Expand Down
5 changes: 5 additions & 0 deletions src/Payment/Request/Decorators/AddressDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

namespace Mollie\WooCommerce\Payment\Request\Decorators;

use stdClass;
use WC_Order;

class AddressDecorator implements RequestDecoratorInterface
{
public const MAXIMAL_LENGHT_ADDRESS = 100;
public const MAXIMAL_LENGHT_POSTALCODE = 20;
public const MAXIMAL_LENGHT_CITY = 200;
public const MAXIMAL_LENGHT_REGION = 200;
public function decorate(array $requestData, WC_Order $order, $context = null): array
{
$isPayPalExpressOrder = $order->get_meta('_mollie_payment_method_button') === 'PayPalButton';
Expand Down
4 changes: 2 additions & 2 deletions src/Payment/inc/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
declare(strict_types=1);



use Mollie\WooCommerce\Gateway\Refund\OrderItemsRefunder;
use Mollie\WooCommerce\Payment\MollieObject;
use Mollie\WooCommerce\Payment\MollieOrder;
use Mollie\WooCommerce\Payment\MolliePayment;
use Mollie\WooCommerce\Payment\OrderItemsRefunder;
use Mollie\WooCommerce\Payment\OrderLines;
use Mollie\WooCommerce\Payment\PaymentFactory;
use Mollie\WooCommerce\Payment\Request\Decorators\AddCustomRequestFieldsDecorator;
Expand Down Expand Up @@ -53,6 +52,7 @@
$pluginId = $container->get('shared.plugin_id');
return new OrderLines($data, $pluginId);
},

PaymentFactory::class => static function (ContainerInterface $container): PaymentFactory {
return new PaymentFactory(
function () use ($container) {
Expand Down
2 changes: 1 addition & 1 deletion src/Subscription/MollieSubscriptionGatewayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(
);
}

public function addSubscriptionFiters($gateway) {
public function addSubscriptionFilters($gateway) {
if (class_exists('WC_Subscriptions_Order')) {
add_action('woocommerce_scheduled_subscription_payment_' . $gateway->id,
static function ($renewal_total, WC_Order $renewal_order) use ($gateway) {
Expand Down

0 comments on commit 6a3fa30

Please sign in to comment.