Skip to content

Commit

Permalink
Fix description with surcharge
Browse files Browse the repository at this point in the history
Now we send the description of the new gateway to the default strategy
  • Loading branch information
mmaymo committed Jan 2, 2025
1 parent 8a89466 commit a730b03
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/Gateway/inc/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ function ($order, $sent_to_admin, $plain_text) use ($instructionsManager, $payme
if (!isset($oldGatewayInstances[$gatewayId])) {
return new NoopPaymentFieldsRenderer();
}
//TODO im passing the deprecated gateway
$gateway = $oldGatewayInstances[$gatewayId];
return new PaymentFieldsRenderer($paymentMethod, $gateway);
$deprecatedGatewayHelper = $oldGatewayInstances[$gatewayId];
$gatewayDescription = $container->get('payment_gateway.' . $gatewayId . '.description');
return new PaymentFieldsRenderer($paymentMethod, $deprecatedGatewayHelper, $gatewayDescription);
};

$dynamicServices["payment_gateway.$gatewayId.title"] = static function (ContainerInterface $container) use ($gatewayId) {
Expand Down
6 changes: 3 additions & 3 deletions src/PaymentMethods/AbstractPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ public function getAllFormFields()

/**
* Sets the gateway's payment fields strategy based on payment method
* @param $gateway
* @param $deprecatedHelperGateway
* @return string
*/
public function paymentFieldsStrategy($gateway)
public function paymentFieldsStrategy($deprecatedHelperGateway, $gatewayDescription)
{
$this->paymentFieldsService->setStrategy($this);
return $this->paymentFieldsService->executeStrategy($gateway);
return $this->paymentFieldsService->executeStrategy($deprecatedHelperGateway, $gatewayDescription);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BancomatpayFieldsStrategy implements PaymentFieldsStrategyI
{
const FIELD_PHONE = "billing_phone_bancomatpay";

public function execute($gateway, $dataHelper)
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper)
{
$showPhoneField = false;
$isPhoneRequired = get_option('mollie_wc_is_phone_required_flag');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BillieFieldsStrategy implements PaymentFieldsStrategyI
{
const FIELD_COMPANY = "billing_company";

public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
$showCompanyField = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class CreditcardFieldsStrategy implements PaymentFieldsStrategyI
{
public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
if (!$this->isMollieComponentsEnabled($gateway->paymentMethod())) {
if (!$this->isMollieComponentsEnabled($deprecatedHelperGateway->paymentMethod())) {
return '';
}
$gateway->has_fields = true;
$deprecatedHelperGateway->has_fields = true;
$allowedHtml = $this->svgAllowedHtml();

$output = '<div class="mollie-components"></div>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class DefaultFieldsStrategy implements PaymentFieldsStrategyI
{
public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
return '';
return $gatewayDescription;
}

public function getFieldMarkup($gateway, $dataHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ class GiftcardFieldsStrategy implements PaymentFieldsStrategyI
{
use IssuersDropdownBehavior;

public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
if (!$this->dropDownEnabled($gateway)) {
return '';
if (!$this->dropDownEnabled($deprecatedHelperGateway)) {
return $gatewayDescription;
}

$issuers = $this->getIssuers($gateway, $dataHelper);
$issuers = $this->getIssuers($deprecatedHelperGateway, $dataHelper);
if (empty($issuers)) {
return '';
return $gatewayDescription;
}
$selectedIssuer = $gateway->paymentMethod()->getSelectedIssuer();
$selectedIssuer = $deprecatedHelperGateway->paymentMethod()->getSelectedIssuer();

$html = '';

Expand All @@ -35,7 +35,7 @@ public function execute($gateway, $dataHelper): string
return wpautop(wptexturize($html));
}

return $this->renderIssuers($gateway, $issuers, $selectedIssuer);
return $this->renderIssuers($deprecatedHelperGateway, $issuers, $selectedIssuer);
}

public function getFieldMarkup($gateway, $dataHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class In3FieldsStrategy implements PaymentFieldsStrategyI
const FIELD_BIRTHDATE = "billing_birthdate_in3";
const FIELD_PHONE = "billing_phone_in3";

public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
$showBirthdateField = false;
$showPhoneField = false;
Expand Down
10 changes: 5 additions & 5 deletions src/PaymentMethods/PaymentFieldsStrategies/KbcFieldsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ class KbcFieldsStrategy implements PaymentFieldsStrategyI
{
use IssuersDropdownBehavior;

public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
if (!$this->dropDownEnabled($gateway)) {
if (!$this->dropDownEnabled($deprecatedHelperGateway)) {
return '';
}

$issuers = $this->getIssuers($gateway, $dataHelper);
$issuers = $this->getIssuers($deprecatedHelperGateway, $dataHelper);

$selectedIssuer = $gateway->paymentMethod()->getSelectedIssuer();
$selectedIssuer = $deprecatedHelperGateway->paymentMethod()->getSelectedIssuer();

return $this->renderIssuers($gateway, $issuers, $selectedIssuer);
return $this->renderIssuers($deprecatedHelperGateway, $issuers, $selectedIssuer);
}

public function getFieldMarkup($gateway, $dataHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function setStrategy($paymentMethod)
}
}

public function executeStrategy($gateway)
public function executeStrategy($deprecatedHelperGateway, $gatewayDescription)
{
return $this->strategy->execute($gateway, $this->dataHelper);
return $this->strategy->execute($deprecatedHelperGateway, $gatewayDescription, $this->dataHelper);
}

public function getStrategyMarkup($gateway)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;

use Inpsyde\PaymentGateway\PaymentFieldsRendererInterface;
use Inpsyde\PaymentGateway\PaymentGateway;
use Mollie\WooCommerce\Gateway\MolliePaymentGatewayHandler;
use Mollie\WooCommerce\PaymentMethods\PaymentMethodI;

class PaymentFieldsRenderer implements PaymentFieldsRendererInterface
{
private PaymentMethodI $paymentMethod;
private MolliePaymentGatewayHandler $gateway;
private MolliePaymentGatewayHandler $deprecatedGatewayHelper;

public function __construct($paymentMethod, $gateway)
private string $gatewayDescription;

public function __construct($paymentMethod, $deprecatedGatewayHelper, $gateway)
{
$this->paymentMethod = $paymentMethod;
$this->gateway = $gateway;
$this->deprecatedGatewayHelper = $deprecatedGatewayHelper;
$this->gatewayDescription = $gateway;
}

/**
* @inheritDoc
*/
public function renderFields(): string
{
return $this->paymentMethod->paymentFieldsStrategy($this->gateway);
return $this->paymentMethod->paymentFieldsStrategy($this->deprecatedGatewayHelper, $this->gatewayDescription);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface PaymentFieldsStrategyI
{
public function execute($gateway, $dataHelper): string;
public function execute($deprecatedHelperDeprecatedHelperGateway, $gatewayDescription, $dataHelper): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RivertyFieldsStrategy implements PaymentFieldsStrategyI
const FIELD_BIRTHDATE = "billing_birthdate_riverty";
const FIELD_PHONE = "billing_phone_riverty";

public function execute($gateway, $dataHelper): string
public function execute($deprecatedHelperGateway, $gatewayDescription, $dataHelper): string
{
$showBirthdateField = false;
$showPhoneField = false;
Expand Down

0 comments on commit a730b03

Please sign in to comment.