Skip to content

Commit fbfb789

Browse files
authored
[ECP-9917] Remove giftcard related merchant risk indicators (#3252)
1 parent 1fea5c6 commit fbfb789

File tree

2 files changed

+1
-117
lines changed

2 files changed

+1
-117
lines changed

Gateway/Request/MerchantRiskIndicatorDataBuilder.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111

1212
namespace Adyen\Payment\Gateway\Request;
1313

14-
use Adyen\Payment\Helper\ChargedCurrency;
15-
use Adyen\Payment\Helper\GiftcardPayment;
1614
use Adyen\Payment\Logger\AdyenLogger;
1715
use Exception;
1816
use Magento\Framework\Exception\NoSuchEntityException;
1917
use Magento\Payment\Gateway\Data\PaymentDataObject;
2018
use Magento\Payment\Gateway\Helper\SubjectReader;
2119
use Magento\Payment\Gateway\Request\BuilderInterface;
2220
use Magento\Quote\Api\CartRepositoryInterface;
23-
use Magento\Quote\Api\Data\CartInterface;
2421
use Magento\Sales\Model\Order;
2522

2623
class MerchantRiskIndicatorDataBuilder implements BuilderInterface
@@ -32,14 +29,10 @@ class MerchantRiskIndicatorDataBuilder implements BuilderInterface
3229

3330
/**
3431
* @param CartRepositoryInterface $cartRepository
35-
* @param ChargedCurrency $chargeCurrency
36-
* @param GiftcardPayment $giftcardPaymentHelper
3732
* @param AdyenLogger $adyenLogger
3833
*/
3934
public function __construct(
4035
private readonly CartRepositoryInterface $cartRepository,
41-
private readonly ChargedCurrency $chargeCurrency,
42-
private readonly GiftcardPayment $giftcardPaymentHelper,
4336
private readonly AdyenLogger $adyenLogger
4437
) { }
4538

@@ -73,12 +66,6 @@ public function build(array $buildSubject): array
7366
self::ADDRESS_INDICATOR_SHIP_TO_BILLING_ADDRESS :
7467
self::ADDRESS_INDICATOR_SHIP_TO_NEW_ADDRESS;
7568
}
76-
77-
// Build giftcard related risk indicators
78-
$merchantRiskIndicatorFields = array_merge(
79-
$merchantRiskIndicatorFields,
80-
$this->buildGiftcardRiskIndicatorFields($quote)
81-
);
8269
} catch (Exception $e) {
8370
$message = __(
8471
"An error occurred while building the merchantRiskIndicator field: %1",
@@ -99,30 +86,4 @@ public function build(array $buildSubject): array
9986

10087
return $request ?? [];
10188
}
102-
103-
/**
104-
* @param CartInterface $quote
105-
* @return array
106-
*/
107-
private function buildGiftcardRiskIndicatorFields(CartInterface $quote): array
108-
{
109-
$quoteAmountCurrency = $this->chargeCurrency->getQuoteAmountCurrency($quote);
110-
111-
$savedGiftcards = json_decode(
112-
$this->giftcardPaymentHelper->fetchRedeemedGiftcards($quote->getId()),
113-
true
114-
);
115-
116-
// Validate JSON that has just been parsed if it was in a valid format
117-
if (json_last_error() === JSON_ERROR_NONE && !empty($savedGiftcards['redeemedGiftcards'])) {
118-
$giftcardRiskIndicatorFields['giftCardAmount'] = [
119-
'currency' => $quoteAmountCurrency->getCurrencyCode(),
120-
'value' => $this->giftcardPaymentHelper->getQuoteGiftcardDiscount($quote)
121-
];
122-
$giftcardRiskIndicatorFields['giftCardCurr'] = $quoteAmountCurrency->getCurrencyCode();
123-
$giftcardRiskIndicatorFields['giftCardCount'] = count($savedGiftcards['redeemedGiftcards']);
124-
}
125-
126-
return $giftcardRiskIndicatorFields ?? [];
127-
}
12889
}

Test/Unit/Gateway/Request/MerchantRiskIndicatorDataBuilderTest.php

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
namespace Adyen\Payment\Test\Gateway\Request;
44

55
use Adyen\Payment\Gateway\Request\MerchantRiskIndicatorDataBuilder;
6-
use Adyen\Payment\Helper\ChargedCurrency;
7-
use Adyen\Payment\Helper\GiftcardPayment;
86
use Adyen\Payment\Logger\AdyenLogger;
9-
use Adyen\Payment\Model\AdyenAmountCurrency;
107
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
118
use Magento\Framework\Exception\NoSuchEntityException;
129
use Magento\Payment\Gateway\Data\PaymentDataObject;
@@ -21,8 +18,6 @@ class MerchantRiskIndicatorDataBuilderTest extends AbstractAdyenTestCase
2118
{
2219
protected ?MerchantRiskIndicatorDataBuilder $merchantRiskIndicatorDataBuilder;
2320
protected CartRepositoryInterface|MockObject $cartRepositoryMock;
24-
protected ChargedCurrency|MockObject $chargedCurrencyMock;
25-
protected GiftcardPayment|MockObject $giftcardPaymentHelperMock;
2621
protected PaymentDataObject|MockObject $paymentDataObjectMock;
2722
protected Payment|MockObject $paymentMock;
2823
protected Order|MockObject $orderMock;
@@ -36,14 +31,12 @@ protected function setUp(): void
3631
{
3732
// Constructor arguments
3833
$this->cartRepositoryMock = $this->createMock(CartRepositoryInterface::class);
39-
$this->chargedCurrencyMock = $this->createMock(ChargedCurrency::class);
40-
$this->giftcardPaymentHelperMock = $this->createMock(GiftcardPayment::class);
34+
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
4135

4236
// Other mock objects
4337
$this->shippingAddressMock = $this->createMock(Address::class);
4438

4539
$this->quoteMock = $this->createMock(Quote::class);
46-
$this->quoteMock->expects($this->atLeastOnce())->method('getId')->willReturn($this->quoteId);
4740
$this->quoteMock->method('getShippingAddress')->willReturn($this->shippingAddressMock);
4841
$this->cartRepositoryMock->method('get')->with($this->quoteId)->willReturn($this->quoteMock);
4942

@@ -56,15 +49,11 @@ protected function setUp(): void
5649
$this->paymentDataObjectMock = $this->createMock(PaymentDataObject::class);
5750
$this->paymentDataObjectMock->method('getPayment')->willReturn($this->paymentMock);
5851

59-
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
60-
6152
$this->buildSubject = ['payment' => $this->paymentDataObjectMock];
6253

6354
// SUT generation
6455
$this->merchantRiskIndicatorDataBuilder = new MerchantRiskIndicatorDataBuilder(
6556
$this->cartRepositoryMock,
66-
$this->chargedCurrencyMock,
67-
$this->giftcardPaymentHelperMock,
6857
$this->adyenLoggerMock
6958
);
7059
}
@@ -133,70 +122,4 @@ public function testBuildWithoutGiftcards($isVirtual, $sameAsBillingAddress, $de
133122
$this->assertEquals($deliveryAddressIndicator,
134123
$result['body']['merchantRiskIndicator']['deliveryAddressIndicator']);
135124
}
136-
137-
/**
138-
* @return void
139-
* @throws NoSuchEntityException
140-
*/
141-
public function testBuildPhysicalGoodsWithGiftcard()
142-
{
143-
$totalGiftcardDiscount = 1000;
144-
$currency = 'EUR';
145-
$numberOfGiftcards = 2;
146-
147-
$this->orderMock->expects($this->once())->method('getIsVirtual')->willReturn(false);
148-
149-
$quoteAmountCurrency = $this->createMock(AdyenAmountCurrency::class);
150-
$quoteAmountCurrency->method('getCurrencyCode')->willReturn($currency);
151-
$this->chargedCurrencyMock->expects($this->once())->method('getQuoteAmountCurrency')
152-
->with($this->quoteMock)
153-
->willReturn($quoteAmountCurrency);
154-
155-
$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"}';
156-
157-
$this->giftcardPaymentHelperMock->expects($this->once())
158-
->method('getQuoteGiftcardDiscount')
159-
->with($this->quoteMock)
160-
->willReturn($totalGiftcardDiscount);
161-
$this->giftcardPaymentHelperMock->expects($this->once())
162-
->method('fetchRedeemedGiftcards')
163-
->with($this->quoteId)
164-
->willReturn($redeemedGiftcardsMock);
165-
166-
$result = $this->merchantRiskIndicatorDataBuilder->build($this->buildSubject);
167-
168-
$this->assertArrayHasKey('body', $result);
169-
$this->assertArrayHasKey('merchantRiskIndicator', $result['body']);
170-
$this->assertArrayHasKey('giftCardCurr', $result['body']['merchantRiskIndicator']);
171-
$this->assertArrayHasKey('giftCardCount', $result['body']['merchantRiskIndicator']);
172-
$this->assertEquals($numberOfGiftcards, $result['body']['merchantRiskIndicator']['giftCardCount']);
173-
$this->assertArrayHasKey('giftCardAmount', $result['body']['merchantRiskIndicator']);
174-
$this->assertArrayHasKey('currency', $result['body']['merchantRiskIndicator']['giftCardAmount']);
175-
$this->assertEquals($currency, $result['body']['merchantRiskIndicator']['giftCardAmount']['currency']);
176-
$this->assertArrayHasKey('value', $result['body']['merchantRiskIndicator']['giftCardAmount']);
177-
$this->assertEquals($totalGiftcardDiscount,
178-
$result['body']['merchantRiskIndicator']['giftCardAmount']['value']);
179-
}
180-
181-
/**
182-
* @return void
183-
* @throws NoSuchEntityException
184-
*/
185-
public function testBuildPhysicalGoodsWithGiftcardInvalidData()
186-
{
187-
$quoteAmountCurrency = $this->createMock(AdyenAmountCurrency::class);
188-
$quoteAmountCurrency->method('getCurrencyCode')->willReturn('EUR');
189-
$this->chargedCurrencyMock->expects($this->once())->method('getQuoteAmountCurrency')
190-
->with($this->quoteMock)
191-
->willReturn($quoteAmountCurrency);
192-
193-
$this->giftcardPaymentHelperMock->method('fetchRedeemedGiftcards')
194-
->willThrowException(new \Exception());
195-
196-
$this->adyenLoggerMock->expects($this->once())->method('error');
197-
$this->assertArrayNotHasKey(
198-
'body',
199-
$this->merchantRiskIndicatorDataBuilder->build($this->buildSubject)
200-
);
201-
}
202125
}

0 commit comments

Comments
 (0)