Skip to content

Commit

Permalink
Merge pull request #37 from avarda-ab/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
juhanihaapala authored Nov 8, 2023
2 parents e50a2b7 + 3159a05 commit 7aa023c
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 28 deletions.
10 changes: 9 additions & 1 deletion Api/QuotePaymentManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ public function updatePaymentStatus($cartId);
public function updateOnlyPaymentStatus($quote);

/**
* Update order payment status from Avarda.
* Update order payment status and info from Avarda.
*
* @param OrderInterface $order
* @return void
*/
public function updateOrderPaymentStatus($order);

/**
* Update order payment status from Avarda.
*
* @param OrderInterface $order
* @return void
*/
public function updateOnlyOrderPaymentStatus($order);

/**
* Get quote ID by Avarda purchase ID
*
Expand Down
7 changes: 4 additions & 3 deletions Gateway/Client/AvardaGatewayClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Avarda\Checkout3\Gateway\Client;

use Laminas\Http\Request;
use Magento\Framework\Webapi\Exception as WebapiException;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\ConverterInterface;
Expand Down Expand Up @@ -50,14 +51,14 @@ public function placeRequest(TransferInterface $transferObject)

try {
switch ($transferObject->getMethod()) {
case \Zend_Http_Client::GET:
case Request::METHOD_GET:
$result = $client->get($uri, $headers);
break;
case \Zend_Http_Client::POST:
case Request::METHOD_POST:
$response = $client->post($uri, $body, $headers);
$result = $this->converter->convert($response);
break;
case \Zend_Http_Client::PUT:
case Request::METHOD_PUT:
$response = $client->put($uri, $body, $headers);
$result = $this->converter->convert($response);
break;
Expand Down
3 changes: 2 additions & 1 deletion Gateway/Client/TransferFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Avarda\Checkout3\Gateway\Client;

use Avarda\Checkout3\Gateway\Config\Config;
use Laminas\Http\Request;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Payment\Gateway\Http\TransferBuilder;
use Magento\Payment\Gateway\Http\TransferFactoryInterface;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function __construct(
EncryptorInterface $encryptor,
TransferBuilder $transferBuilder,
Config $config,
$method = \Zend_Http_Client::POST,
$method = Request::METHOD_GET,
$uri = ''
) {
$this->encryptor = $encryptor;
Expand Down
10 changes: 3 additions & 7 deletions Gateway/Response/GetOnlyStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\AddressInterfaceFactory;
use Magento\Quote\Model\Quote\PaymentFactory;

class GetOnlyStatusHandler implements HandlerInterface
{
Expand All @@ -36,20 +34,18 @@ public function __construct(
public function handle(array $handlingSubject, array $response)
{
$paymentDO = SubjectReader::readPayment($handlingSubject);
$order = $paymentDO->getOrder();
$payment = $paymentDO->getPayment();

$entityId = $order->getId();
$quote = $this->quoteRepository->get($entityId);
$mode = $response['mode'] == 'B2B' ? 'b2B' : 'b2C';

// Set payment method
if (isset($response['paymentMethods']['selectedPayment']['type'])) {
$paymentMethod = $this->methodHelper->getPaymentMethod($response['paymentMethods']['selectedPayment']['type']);
$quote->getPayment()->setMethod($paymentMethod);
$payment->setMethod($paymentMethod);
}

// Set payment state
$quote->getPayment()->setAdditionalInformation(
$payment->setAdditionalInformation(
PaymentData::STATE,
$response[$mode]['step']['current']
)->setAdditionalInformation('renew', false);
Expand Down
10 changes: 5 additions & 5 deletions Helper/PaymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public function isAvardaPayment(InfoInterface $payment)
$purchaseData = $this->getPurchaseData($payment);

return $purchaseData && count($purchaseData)>=1 && (
!$paymentCode ||
strpos($paymentCode, 'avarda_checkout3') !== false ||
// free method is automatically set in checkout, but it will be changed to avarda zero_sum on status update
$paymentCode == Free::PAYMENT_METHOD_FREE_CODE
);
!$paymentCode ||
strpos($paymentCode, 'avarda_checkout3') !== false ||
// free method is automatically set in checkout, but it will be changed to avarda zero_sum on status update
$paymentCode == Free::PAYMENT_METHOD_FREE_CODE
);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions Model/QuotePaymentManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ public function updateOrderPaymentStatus($order)
$this->executeCommand('avarda_update_order_status', $order);
}

/**
* {@inheritdoc}
*/
public function updateOnlyOrderPaymentStatus($order)
{
$this->executeCommand('avarda_get_only_status', $order);
}

/**
* @param $order OrderInterface|Order
* @return void
Expand Down
12 changes: 11 additions & 1 deletion Plugin/PrepareItems/Quote/QuoteCollectTotalsPrepareItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Avarda\Checkout3\Gateway\Data\ItemAdapter\QuoteItemFactory;
use Avarda\Checkout3\Gateway\Data\ItemDataObjectFactory;
use Avarda\Checkout3\Helper\PaymentData;
use Magento\Payment\Gateway\ConfigInterface;
use Magento\Quote\Api\Data\CartInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -46,11 +47,14 @@ class QuoteCollectTotalsPrepareItems
*/
protected $paymentDataHelper;

protected ConfigInterface $config;

/**
* @var bool
*/
protected $collectTotalsFlag = false;


/**
* QuoteCollectTotals constructor.
*
Expand All @@ -67,14 +71,16 @@ public function __construct(
ItemDataObjectFactory $itemDataObjectFactory,
QuoteItemFactory $quoteItemAdapterFactory,
ArrayDataItemFactory $arrayDataItemAdapterFactory,
PaymentData $paymentDataHelper
PaymentData $paymentDataHelper,
ConfigInterface $config
) {
$this->logger = $logger;
$this->itemStorage = $itemStorage;
$this->itemDataObjectFactory = $itemDataObjectFactory;
$this->quoteItemAdapterFactory = $quoteItemAdapterFactory;
$this->arrayDataItemAdapterFactory = $arrayDataItemAdapterFactory;
$this->paymentDataHelper = $paymentDataHelper;
$this->config = $config;
}

/**
Expand All @@ -86,6 +92,10 @@ public function __construct(
*/
public function afterCollectTotals(CartInterface $subject, CartInterface $result)
{
if (!$this->config->isActive()) {
return $result;
}

try {
if (!$this->collectTotalsFlag &&
$subject->getItemsCount() > 0 &&
Expand Down
22 changes: 13 additions & 9 deletions Plugin/PrepareItems/Quote/QuoteCollectTotalsUpdateItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@
use Magento\Framework\App\Request\Http;
use Magento\Framework\Exception\PaymentException;
use Magento\Framework\Webapi\Exception as WebapiException;
use Magento\Payment\Gateway\ConfigInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote;

class QuoteCollectTotalsUpdateItems
{
/** @var QuotePaymentManagementInterface */
protected $quotePaymentManagement;

/** @var PaymentData */
protected $paymentDataHelper;

/** @var PurchaseState */
protected $purchaseStateHelper;
protected QuotePaymentManagementInterface $quotePaymentManagement;
protected PaymentData $paymentDataHelper;
protected PurchaseState $purchaseStateHelper;
protected ConfigInterface $config;

/** @var bool */
static $collectTotalsFlag = false;

/** @var Http */
protected $request;


public function __construct(
QuotePaymentManagementInterface $quotePaymentManagement,
PaymentData $paymentDataHelper,
PurchaseState $purchaseStateHelper,
Http $request
Http $request,
ConfigInterface $config
) {
$this->quotePaymentManagement = $quotePaymentManagement;
$this->paymentDataHelper = $paymentDataHelper;
$this->purchaseStateHelper = $purchaseStateHelper;
$this->request = $request;
$this->config = $config;
}

/**
Expand All @@ -56,6 +56,10 @@ public function __construct(
*/
public function afterCollectTotals(CartInterface $subject, CartInterface $result)
{
if (!$this->config->isActive()) {
return $result;
}

$payment = $subject->getPayment();
if (!self::$collectTotalsFlag &&
$subject->getItemsCount() > 0 &&
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "avarda/checkout3",
"description": "Avarda Checkout V3 module for Magento 2 module.",
"type": "magento2-module",
"version": "1.3.9",
"version": "1.3.10",
"require": {
"ext-json": "*",
"magento/module-backend": "*",
Expand Down
10 changes: 10 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,14 @@
<argument name="methodCode" xsi:type="const">Avarda\Checkout3\Model\Ui\ConfigProviderZeroAmount::CODE</argument>
</arguments>
</virtualType>
<type name="Avarda\Checkout3\Plugin\PrepareItems\Quote\QuoteCollectTotalsUpdateItems">
<arguments>
<argument name="config" xsi:type="object">Avarda\Checkout3\Gateway\Config\Config</argument>
</arguments>
</type>
<type name="Avarda\Checkout3\Plugin\PrepareItems\Quote\QuoteCollectTotalsPrepareItems">
<arguments>
<argument name="config" xsi:type="object">Avarda\Checkout3\Gateway\Config\Config</argument>
</arguments>
</type>
</config>

0 comments on commit 7aa023c

Please sign in to comment.