Skip to content

Commit

Permalink
Remove wc methods from deprecated gateway and fix around
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Dec 18, 2024
1 parent e26ae66 commit f8d7085
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 540 deletions.
17 changes: 9 additions & 8 deletions src/Assets/MollieCheckoutBlocksSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public static function localizeWCBlocksData($dataService, $gatewayInstances)
);
}

public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayInstances): array
public static function gatewayDataForWCBlocks(Data $dataService, array $deprecatedGatewayHelpers): array
{
$filters = $dataService->wooCommerceFiltersForCheckout();
$availableGateways = WC()->payment_gateways()->get_available_payment_gateways();
$availablePaymentMethods = [];

/**
* @var MolliePaymentGatewayI $gateway
* @var $gateway
* psalm-suppress UnusedForeachValue
*/
foreach ($availableGateways as $key => $gateway) {
Expand Down Expand Up @@ -113,10 +113,11 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI
],
];
$gatewayData = [];
$isSepaEnabled = isset($gatewayInstances['mollie_wc_gateway_directdebit']) && $gatewayInstances['mollie_wc_gateway_directdebit']->enabled === 'yes';
/** @var MolliePaymentGatewayHandler $gateway */
foreach ($gatewayInstances as $gatewayKey => $gateway) {
$method = $gateway->paymentMethod();
$isSepaEnabled = isset($deprecatedGatewayHelpers['mollie_wc_gateway_directdebit']) && $deprecatedGatewayHelpers['mollie_wc_gateway_directdebit']->enabled === 'yes';
/** @var PaymentGateway $gateway */
foreach ($availableGateways as $gatewayKey => $gateway) {
$deprecatedGateway = $deprecatedGatewayHelpers[$gatewayKey];
$method = $deprecatedGateway->paymentMethod();
$gatewayId = is_string($method->getProperty('id')) ? $method->getProperty('id') : "";

if ($gateway->enabled !== 'yes' || ($gatewayId === 'directdebit' && !is_admin())) {
Expand All @@ -127,14 +128,14 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI
if ($method->getProperty('paymentFields') === true) {
$paymentFieldsService = $method->paymentFieldsService();
$paymentFieldsService->setStrategy($method);
$issuers = $method->paymentFieldsService()->getStrategyMarkup($gateway);
$issuers = $method->paymentFieldsService()->getStrategyMarkup($deprecatedGateway);
}
if ($gatewayId === 'creditcard') {
$content .= $issuers;
$issuers = false;
}
$title = $method->title();
$labelMarkup = "<span style='margin-right: 1em'>{$title}</span>{$gateway->icon}";
$labelMarkup = "<span style='margin-right: 1em'>{$title}</span>{$gateway->get_icon()}";
$hasSurcharge = $method->hasSurcharge();
$countryCodes = [
'BE' => '+32xxxxxxxxx',
Expand Down
12 changes: 6 additions & 6 deletions src/Buttons/ApplePayButton/ResponsesToApple.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class ResponsesToApple
*/
protected $logger;
/**
* @var MolliePaymentGatewayI
* @var
*/
protected $gateway;
protected $deprecatedAppleHelper;

/**
* ResponsesToApple constructor.
*/
public function __construct(Logger $logger, MolliePaymentGatewayI $appleGateway)
public function __construct(Logger $logger, $deprecatedAppleHelper)
{
$this->logger = $logger;
$this->gateway = $appleGateway;
$this->deprecatedAppleHelper = $deprecatedAppleHelper;
}

/**
Expand Down Expand Up @@ -238,15 +238,15 @@ protected function appleNewLineItemsResponse(array $paymentDetails): array
protected function redirectUrlOnSuccessfulPayment($orderId)
{
$order = wc_get_order($orderId);
$redirect_url = $this->gateway->getReturnRedirectUrlForOrder($order);
$redirect_url = $this->deprecatedAppleHelper->getReturnRedirectUrlForOrder($order);
// Add utm_nooverride query string
$redirect_url = add_query_arg(['utm_nooverride' => 1], $redirect_url);

$this->logger->debug(
__METHOD__
. sprintf(
': Redirect url on return order %s, order %s: %s',
$this->gateway->paymentMethod()->getProperty('id'),
$this->deprecatedAppleHelper->paymentMethod()->getProperty('id'),
$orderId,
$redirect_url
)
Expand Down
Loading

0 comments on commit f8d7085

Please sign in to comment.