diff --git a/Gateway/Request/MerchantRiskIndicatorDataBuilder.php b/Gateway/Request/MerchantRiskIndicatorDataBuilder.php index 2f66413ab..b3ab95823 100644 --- a/Gateway/Request/MerchantRiskIndicatorDataBuilder.php +++ b/Gateway/Request/MerchantRiskIndicatorDataBuilder.php @@ -11,8 +11,6 @@ namespace Adyen\Payment\Gateway\Request; -use Adyen\Payment\Helper\ChargedCurrency; -use Adyen\Payment\Helper\GiftcardPayment; use Adyen\Payment\Logger\AdyenLogger; use Exception; use Magento\Framework\Exception\NoSuchEntityException; @@ -20,7 +18,6 @@ use Magento\Payment\Gateway\Helper\SubjectReader; use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Quote\Api\CartRepositoryInterface; -use Magento\Quote\Api\Data\CartInterface; use Magento\Sales\Model\Order; class MerchantRiskIndicatorDataBuilder implements BuilderInterface @@ -32,14 +29,10 @@ class MerchantRiskIndicatorDataBuilder implements BuilderInterface /** * @param CartRepositoryInterface $cartRepository - * @param ChargedCurrency $chargeCurrency - * @param GiftcardPayment $giftcardPaymentHelper * @param AdyenLogger $adyenLogger */ public function __construct( private readonly CartRepositoryInterface $cartRepository, - private readonly ChargedCurrency $chargeCurrency, - private readonly GiftcardPayment $giftcardPaymentHelper, private readonly AdyenLogger $adyenLogger ) { } @@ -73,12 +66,6 @@ public function build(array $buildSubject): array self::ADDRESS_INDICATOR_SHIP_TO_BILLING_ADDRESS : self::ADDRESS_INDICATOR_SHIP_TO_NEW_ADDRESS; } - - // Build giftcard related risk indicators - $merchantRiskIndicatorFields = array_merge( - $merchantRiskIndicatorFields, - $this->buildGiftcardRiskIndicatorFields($quote) - ); } catch (Exception $e) { $message = __( "An error occurred while building the merchantRiskIndicator field: %1", @@ -99,30 +86,4 @@ public function build(array $buildSubject): array return $request ?? []; } - - /** - * @param CartInterface $quote - * @return array - */ - private function buildGiftcardRiskIndicatorFields(CartInterface $quote): array - { - $quoteAmountCurrency = $this->chargeCurrency->getQuoteAmountCurrency($quote); - - $savedGiftcards = json_decode( - $this->giftcardPaymentHelper->fetchRedeemedGiftcards($quote->getId()), - true - ); - - // Validate JSON that has just been parsed if it was in a valid format - if (json_last_error() === JSON_ERROR_NONE && !empty($savedGiftcards['redeemedGiftcards'])) { - $giftcardRiskIndicatorFields['giftCardAmount'] = [ - 'currency' => $quoteAmountCurrency->getCurrencyCode(), - 'value' => $this->giftcardPaymentHelper->getQuoteGiftcardDiscount($quote) - ]; - $giftcardRiskIndicatorFields['giftCardCurr'] = $quoteAmountCurrency->getCurrencyCode(); - $giftcardRiskIndicatorFields['giftCardCount'] = count($savedGiftcards['redeemedGiftcards']); - } - - return $giftcardRiskIndicatorFields ?? []; - } } diff --git a/Test/Unit/Gateway/Request/MerchantRiskIndicatorDataBuilderTest.php b/Test/Unit/Gateway/Request/MerchantRiskIndicatorDataBuilderTest.php index 8ef4ae039..20c2cd5fe 100644 --- a/Test/Unit/Gateway/Request/MerchantRiskIndicatorDataBuilderTest.php +++ b/Test/Unit/Gateway/Request/MerchantRiskIndicatorDataBuilderTest.php @@ -3,10 +3,7 @@ namespace Adyen\Payment\Test\Gateway\Request; use Adyen\Payment\Gateway\Request\MerchantRiskIndicatorDataBuilder; -use Adyen\Payment\Helper\ChargedCurrency; -use Adyen\Payment\Helper\GiftcardPayment; use Adyen\Payment\Logger\AdyenLogger; -use Adyen\Payment\Model\AdyenAmountCurrency; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Payment\Gateway\Data\PaymentDataObject; @@ -21,8 +18,6 @@ class MerchantRiskIndicatorDataBuilderTest extends AbstractAdyenTestCase { protected ?MerchantRiskIndicatorDataBuilder $merchantRiskIndicatorDataBuilder; protected CartRepositoryInterface|MockObject $cartRepositoryMock; - protected ChargedCurrency|MockObject $chargedCurrencyMock; - protected GiftcardPayment|MockObject $giftcardPaymentHelperMock; protected PaymentDataObject|MockObject $paymentDataObjectMock; protected Payment|MockObject $paymentMock; protected Order|MockObject $orderMock; @@ -36,14 +31,12 @@ protected function setUp(): void { // Constructor arguments $this->cartRepositoryMock = $this->createMock(CartRepositoryInterface::class); - $this->chargedCurrencyMock = $this->createMock(ChargedCurrency::class); - $this->giftcardPaymentHelperMock = $this->createMock(GiftcardPayment::class); + $this->adyenLoggerMock = $this->createMock(AdyenLogger::class); // Other mock objects $this->shippingAddressMock = $this->createMock(Address::class); $this->quoteMock = $this->createMock(Quote::class); - $this->quoteMock->expects($this->atLeastOnce())->method('getId')->willReturn($this->quoteId); $this->quoteMock->method('getShippingAddress')->willReturn($this->shippingAddressMock); $this->cartRepositoryMock->method('get')->with($this->quoteId)->willReturn($this->quoteMock); @@ -56,15 +49,11 @@ protected function setUp(): void $this->paymentDataObjectMock = $this->createMock(PaymentDataObject::class); $this->paymentDataObjectMock->method('getPayment')->willReturn($this->paymentMock); - $this->adyenLoggerMock = $this->createMock(AdyenLogger::class); - $this->buildSubject = ['payment' => $this->paymentDataObjectMock]; // SUT generation $this->merchantRiskIndicatorDataBuilder = new MerchantRiskIndicatorDataBuilder( $this->cartRepositoryMock, - $this->chargedCurrencyMock, - $this->giftcardPaymentHelperMock, $this->adyenLoggerMock ); } @@ -133,70 +122,4 @@ public function testBuildWithoutGiftcards($isVirtual, $sameAsBillingAddress, $de $this->assertEquals($deliveryAddressIndicator, $result['body']['merchantRiskIndicator']['deliveryAddressIndicator']); } - - /** - * @return void - * @throws NoSuchEntityException - */ - public function testBuildPhysicalGoodsWithGiftcard() - { - $totalGiftcardDiscount = 1000; - $currency = 'EUR'; - $numberOfGiftcards = 2; - - $this->orderMock->expects($this->once())->method('getIsVirtual')->willReturn(false); - - $quoteAmountCurrency = $this->createMock(AdyenAmountCurrency::class); - $quoteAmountCurrency->method('getCurrencyCode')->willReturn($currency); - $this->chargedCurrencyMock->expects($this->once())->method('getQuoteAmountCurrency') - ->with($this->quoteMock) - ->willReturn($quoteAmountCurrency); - - $redeemedGiftcardsMock = '{"redeemedGiftcards":[{"stateDataId":"51","brand":"svs","title":"SVS","balance":{"currency":"EUR","value":5000},"deductedAmount":"50,00\u00a0\u20ac"},{"stateDataId":"52","brand":"svs","title":"SVS","balance":{"currency":"EUR","value":5000},"deductedAmount":"50,00\u00a0\u20ac"}],"remainingAmount":"8,00\u00a0\u20ac","totalDiscount":"100,00\u00a0\u20ac"}'; - - $this->giftcardPaymentHelperMock->expects($this->once()) - ->method('getQuoteGiftcardDiscount') - ->with($this->quoteMock) - ->willReturn($totalGiftcardDiscount); - $this->giftcardPaymentHelperMock->expects($this->once()) - ->method('fetchRedeemedGiftcards') - ->with($this->quoteId) - ->willReturn($redeemedGiftcardsMock); - - $result = $this->merchantRiskIndicatorDataBuilder->build($this->buildSubject); - - $this->assertArrayHasKey('body', $result); - $this->assertArrayHasKey('merchantRiskIndicator', $result['body']); - $this->assertArrayHasKey('giftCardCurr', $result['body']['merchantRiskIndicator']); - $this->assertArrayHasKey('giftCardCount', $result['body']['merchantRiskIndicator']); - $this->assertEquals($numberOfGiftcards, $result['body']['merchantRiskIndicator']['giftCardCount']); - $this->assertArrayHasKey('giftCardAmount', $result['body']['merchantRiskIndicator']); - $this->assertArrayHasKey('currency', $result['body']['merchantRiskIndicator']['giftCardAmount']); - $this->assertEquals($currency, $result['body']['merchantRiskIndicator']['giftCardAmount']['currency']); - $this->assertArrayHasKey('value', $result['body']['merchantRiskIndicator']['giftCardAmount']); - $this->assertEquals($totalGiftcardDiscount, - $result['body']['merchantRiskIndicator']['giftCardAmount']['value']); - } - - /** - * @return void - * @throws NoSuchEntityException - */ - public function testBuildPhysicalGoodsWithGiftcardInvalidData() - { - $quoteAmountCurrency = $this->createMock(AdyenAmountCurrency::class); - $quoteAmountCurrency->method('getCurrencyCode')->willReturn('EUR'); - $this->chargedCurrencyMock->expects($this->once())->method('getQuoteAmountCurrency') - ->with($this->quoteMock) - ->willReturn($quoteAmountCurrency); - - $this->giftcardPaymentHelperMock->method('fetchRedeemedGiftcards') - ->willThrowException(new \Exception()); - - $this->adyenLoggerMock->expects($this->once())->method('error'); - $this->assertArrayNotHasKey( - 'body', - $this->merchantRiskIndicatorDataBuilder->build($this->buildSubject) - ); - } }