Skip to content

Commit

Permalink
BP-2092 - Remove unused DataBuilder, Remove AbstractMethod and all pa…
Browse files Browse the repository at this point in the history
…yment methods, Remove Unit Tests, Change AbstractMethod with BuckarooAdapter

Trying to remove all afterCancel Order plugins and use virtualType instead but from 2.4.2 using virtualType as the class of the plugin doesn't work magento/magento2#33980
  • Loading branch information
LucianTuriacArnia committed Nov 1, 2022
1 parent 649d4a8 commit 41de195
Show file tree
Hide file tree
Showing 64 changed files with 137 additions and 10,992 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function shouldShowWarning()
}

/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $paymentMethodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $paymentMethodInstance
*/
$paymentMethodInstance = $payment->getMethodInstance();

Expand Down
6 changes: 2 additions & 4 deletions Controller/Redirect/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

use Buckaroo\Magento2\Api\PushRequestInterface;
use Buckaroo\Magento2\Logging\Log;
use Buckaroo\Magento2\Model\Method\BuckarooAdapter;
use Buckaroo\Magento2\Model\RequestPush\RequestPushFactory;
use Magento\Framework\App\Request\Http as Http;
use Magento\Sales\Api\Data\TransactionInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Buckaroo\Magento2\Model\Method\AbstractMethod;
use Buckaroo\Magento2\Model\Service\Order as OrderService;

class Process extends \Magento\Framework\App\Action\Action
Expand Down Expand Up @@ -419,9 +419,7 @@ public function addSuccessMessage(string $message)
*/
protected function setPaymentOutOfTransit(OrderPaymentInterface $payment)
{
$payment
->setAdditionalInformation(AbstractMethod::BUCKAROO_PAYMENT_IN_TRANSIT, false)
->save();
$payment->setAdditionalInformation(BuckarooAdapter::BUCKAROO_PAYMENT_IN_TRANSIT, false)->save();
}
protected function handleFailed($statusCode)
{
Expand Down
12 changes: 6 additions & 6 deletions Gateway/Http/TransactionBuilder/AbstractTransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ abstract class AbstractTransactionBuilder implements \Buckaroo\Magento2\Gateway\
* @param UrlInterface $urlBuilder
* @param FormKey $formKey
* @param Encryptor $encryptor
* @param AbstractMethod $abstractMethod
* @param BuckarooAdapter $abstractMethod
* @param Factory $configProviderMethodFactory
* @param null|int|float|double $amount
* @param null|string $currency
Expand Down Expand Up @@ -421,14 +421,14 @@ public function setReturnUrl($url)
*/
public function getReturnUrl()
{

$returnUrl = $this->getReturnUrlFromPayment();
if($returnUrl !== null) {
$this->setReturnUrl($returnUrl);
return $returnUrl;
}


if ($this->returnUrl === null) {
$url = $this->urlBuilder->setScope($this->order->getStoreId());
$url = $url->getRouteUrl('buckaroo/redirect/process') . '?form_key=' . $this->getFormKey();
Expand All @@ -442,15 +442,15 @@ public function getReturnUrl()
public function getReturnUrlFromPayment()
{
if(
$this->getOrder() === null ||
$this->getOrder() === null ||
$this->getOrder()->getPayment() === null ||
$this->getOrder()->getPayment()->getAdditionalInformation(self::ADDITIONAL_RETURN_URL) === null
) {
return;
}
$returnUrl = $this->getOrder()->getPayment()->getAdditionalInformation(self::ADDITIONAL_RETURN_URL);
if(
!filter_var($returnUrl, FILTER_VALIDATE_URL) === false &&
!filter_var($returnUrl, FILTER_VALIDATE_URL) === false &&
in_array(parse_url($returnUrl, PHP_URL_SCHEME), ['http','https'])
) {
return $returnUrl;
Expand Down Expand Up @@ -632,7 +632,7 @@ public function getAdditionalParameter($key)
{
return $this->additionaParameters[$key];
}

public function getAllAdditionalParameters()
{
return $this->additionaParameters;
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Http/TransactionBuilder/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private function filterBody($body)
private function getAllowedCurrencies()
{
/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $methodInstance
*/
$methodInstance = $this->order->getPayment()->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode ?? 'buckaroo_magento2_ideal';
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Http/TransactionBuilder/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Refund extends AbstractTransactionBuilder
protected function setRefundCurrencyAndAmount()
{
/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $methodInstance
*/
$methodInstance = $this->order->getPayment()->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode;
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/AbstractTransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ abstract class AbstractTransactionBuilder implements BuilderInterface
* @param UrlInterface $urlBuilder
* @param FormKey $formKey
* @param Encryptor $encryptor
* @param AbstractMethod $abstractMethod
* @param BuckarooAdapter $abstractMethod
* @param Factory $configProviderMethodFactory
* @param null|int|float|double $amount
* @param null|string $currency
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/AmountCreditDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function setCurrency($currency)
protected function setRefundCurrencyAndAmount()
{
/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $methodInstance
*/
$methodInstance = $this->order->getPayment()->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode;
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/AmountDebitDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private function setOrderAmount()
private function getAllowedCurrencies()
{
/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $methodInstance
*/
$methodInstance = $this->order->getPayment()->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode ?? 'buckaroo_magento2_ideal';
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/OrderDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private function filterBody($body)
private function getAllowedCurrencies()
{
/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $methodInstance
*/
$methodInstance = $this->order->getPayment()->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode ?? 'buckaroo_magento2_ideal';
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/PaymentMethodDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function build(array $buildSubject)
$payment = $buildSubject['payment']->getPayment();

/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var \Buckaroo\Magento2\Model\Method\BuckarooAdapter $methodInstance
*/
$methodInstance = $payment->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode ?? 'buckaroo_magento2_ideal';
Expand Down
24 changes: 17 additions & 7 deletions Gateway/Request/ShippingAddressDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,38 @@

namespace Buckaroo\Magento2\Gateway\Request;

use Buckaroo\Magento2\Model\Method\Klarna\Klarnain;
use Buckaroo\Magento2\Plugin\Method\Klarna;
use Buckaroo\Magento2\Model\ConfigProvider\Method\Klarnain;
use Buckaroo\Magento2\Model\ConfigProvider\Method\Klarna;
use Magento\Sales\Model\Order\Address;

class ShippingAddressDataBuilder extends AbstractAddressDataBuilder
{
/**
* @var AddressHandlerPool
*/
private AddressHandlerPool $addressHandlerPool;

/**
* @param AddressHandlerPool $addressHandlerPool
*/
public function __construct(
AddressHandlerPool $addressHandlerPool
) {
$this->addressHandlerPool = $addressHandlerPool;
}

/**
* Get Shipping Address
*
* @return Address
* @throws \Exception
*/
protected function getAddress(): Address
{
if (
$this->isAddressDataDifferent($this->getPayment()) ||
is_null($this->getOrder()->getShippingAddress()) ||
$this->getPayment()->getMethod() === Klarna::KLARNA_METHOD_NAME ||
$this->getPayment()->getMethod() === Klarnain::PAYMENT_METHOD_CODE
if ($this->isAddressDataDifferent($this->getPayment()) ||
$this->getOrder()->getShippingAddress() === null ||
$this->getPayment()->getMethod() === Klarna::CODE ||
$this->getPayment()->getMethod() === Klarnain::CODE
) {
return $this->addressHandlerPool->getShippingAddress($this->getOrder());
} else {
Expand All @@ -36,6 +43,7 @@ protected function getAddress(): Address

/**
* Method to compare two addresses from the payment.
*
* Returns true if they are the same.
*
* @param \Magento\Sales\Api\Data\OrderPaymentInterface|\Magento\Payment\Model\InfoInterface $payment
Expand All @@ -60,6 +68,8 @@ public function isAddressDataDifferent($payment): bool
}

/**
* Calculate differences between Billing and Shipping Address
*
* @param array $addressOne
* @param array $addressTwo
*
Expand Down
Loading

0 comments on commit 41de195

Please sign in to comment.