Skip to content

Commit

Permalink
[ECP-9112] Fix broken feature of obtaining state data from DB (#2583)
Browse files Browse the repository at this point in the history
* [ECP-9112] obtaining state data from DB and ignoring it for Giftcard type payment methods

* [ECP-9112] obtaining state data from DB and ignoring it for Giftcard type payment methods

* Solving Pipeline and Adding Giftcard payment method to graphql/di.xml

* Solving Pipeline for failing Unit test and making the namespace correct

---------

Co-authored-by: Rok Popov Ledinski <[email protected]>
  • Loading branch information
khushboo-singhvi and RokPopov authored Apr 18, 2024
1 parent cbf8bb5 commit d5e4c51
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
16 changes: 9 additions & 7 deletions Observer/AdyenCcDataAssignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,21 @@ public function execute(Observer $observer)

// JSON decode state data from the frontend or fetch it from the DB entity with the quote ID
if (!empty($additionalData[self::STATE_DATA])) {
$stateData = json_decode((string) $additionalData[self::STATE_DATA], true);
$stateData = json_decode((string)$additionalData[self::STATE_DATA], true);
} else {
$stateData = $this->stateDataCollection->getStateDataArrayWithQuoteId($paymentInfo->getData('quote_id'));
}

// Get validated state data array
if (!empty($stateData)) {
if (!empty($stateData) && $stateData['paymentMethod']['type'] != 'giftcard') {
$stateData = $this->checkoutStateDataValidator->getValidatedAdditionalData($stateData);
// Set stateData in a service and remove from payment's additionalData
$this->stateData->setStateData($stateData, $paymentInfo->getData('quote_id'));

// set storeCc
if (!empty($stateData[self::STORE_PAYMENT_METHOD])) {
$paymentInfo->setAdditionalInformation(self::STORE_CC, $stateData[self::STORE_PAYMENT_METHOD]);
}
}

unset($additionalData[self::STATE_DATA]);
Expand All @@ -144,10 +151,5 @@ public function execute(Observer $observer)
if (!empty($additionalData[self::CC_TYPE])) {
$paymentInfo->setCcType($additionalData[self::CC_TYPE]);
}

// set storeCc
if (!empty($stateData[self::STORE_PAYMENT_METHOD])) {
$paymentInfo->setAdditionalInformation(self::STORE_CC, $stateData[self::STORE_PAYMENT_METHOD]);
}
}
}
8 changes: 8 additions & 0 deletions Observer/AdyenPaymentMethodDataAssignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function __construct(
public function execute(Observer $observer)
{
$additionalDataToSave = [];
$stateData = null;
// Get request fields
$data = $this->readDataArgument($observer);
$paymentInfo = $this->readPaymentModelArgument($observer);
Expand All @@ -87,8 +88,15 @@ public function execute(Observer $observer)
if (!empty($additionalData[self::STATE_DATA])) {
$stateData = json_decode((string) $additionalData[self::STATE_DATA], true);
} elseif (!empty($additionalData[self::CC_NUMBER])) {
//This block goes for multi shipping scenarios
$stateData = json_decode((string) $additionalData[self::CC_NUMBER], true);
$paymentInfo->setAdditionalInformation(self::BRAND_CODE, $stateData['paymentMethod']['type']);
} elseif($paymentInfo->getData('method') != 'adyen_giftcard') {
$stateData = $this->stateDataCollection->getStateDataArrayWithQuoteId($paymentInfo->getData('quote_id'));
if(!empty($stateData) && $stateData['paymentMethod']['type'] == 'giftcard')
{
$stateData = null;
}
}

// Get validated state data array
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Model/Sales/OrderRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Test\Unit\Model;
namespace Adyen\Payment\Test\Unit\Model\Sales;

use Adyen\Payment\Model\Sales\OrderRepository;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
Expand Down
3 changes: 2 additions & 1 deletion etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<item name="adyen_vipps" xsi:type="object">Adyen\Payment\Model\Cart\Payment\AdditionalDataProvider\AdyenPm</item>
<item name="adyen_bizum" xsi:type="object">Adyen\Payment\Model\Cart\Payment\AdditionalDataProvider\AdyenPm</item>
<item name="adyen_ach" xsi:type="object">Adyen\Payment\Model\Cart\Payment\AdditionalDataProvider\AdyenPm</item>
<item name="adyen_giftcard" xsi:type="object">Adyen\Payment\Model\Cart\Payment\AdditionalDataProvider\AdyenPm</item>
</argument>
</arguments>
</type>
Expand All @@ -103,4 +104,4 @@
</argument>
</arguments>
</type>
</config>
</config>

0 comments on commit d5e4c51

Please sign in to comment.