Skip to content
21 changes: 12 additions & 9 deletions Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,23 @@ public function build(array $buildSubject): array
]
];

if ($method === PaymentMethods::ADYEN_PAYPAL) {
$requiresCapturePspreference = $this->paymentMethodsHelper->getRefundRequiresCapturePspreference(
$paymentMethodInstance
);

/*
* Following section adds `capturePspReference` to the refund request if the payment method requires it.
* This is used to link the refund to the capture on Adyen on multiple partial capture cases. Note that,
* AdyenInvoice only exists if the capture mode is manual. Hence, checking the existence of AdyenInvoice
* is sufficient to determine the capture mode.
*/
if ($requiresCapturePspreference) {
$adyenInvoices = $this->adyenInvoiceCollection->getAdyenInvoicesLinkedToMagentoInvoice(
$creditMemo->getInvoiceId()
);
$firstAdyenInvoice = reset($adyenInvoices);

$isPaypalManualCapture = $this->configHelper->getConfigData(
'paypal_capture_mode',
'adyen_abstract',
$storeId,
true
);

if (!empty($adyenInvoices) && $isPaypalManualCapture) {
if ($firstAdyenInvoice !== false) {
$requestBody[0]['capturePspReference'] = $firstAdyenInvoice[InvoiceInterface::PSPREFERENCE];
}
}
Expand Down
12 changes: 12 additions & 0 deletions Helper/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PaymentMethods extends AbstractHelper
const ADYEN_GROUP_ALTERNATIVE_PAYMENT_METHODS = 'adyen-alternative-payment-method';
const CONFIG_FIELD_REQUIRES_LINE_ITEMS = 'requires_line_items';
const CONFIG_FIELD_IS_OPEN_INVOICE = 'is_open_invoice';
const CONFIG_FIELD_REFUND_REQUIRES_CAPTURE_PSPREFERENCE = 'refund_requires_capture_pspreference';
const VALID_CHANNELS = ["iOS", "Android", "Web"];

/*
Expand Down Expand Up @@ -999,6 +1000,17 @@ public function getRequiresLineItems(MethodInterface $paymentMethodInstance): bo
return $isOpenInvoice || $requiresLineItemsConfig;
}

/**
* Checks the requirement of `capturePspReference` for refund requests
*
* @param MethodInterface $paymentMethodInstance
* @return bool
*/
public function getRefundRequiresCapturePspreference(MethodInterface $paymentMethodInstance): bool
{
return boolval($paymentMethodInstance->getConfigData(self::CONFIG_FIELD_REFUND_REQUIRES_CAPTURE_PSPREFERENCE));
}

/**
* @return bool
*/
Expand Down
4 changes: 3 additions & 1 deletion Helper/Util/PaymentMethodUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class PaymentMethodUtil
'walley',
'walley_b2b',
'girocard',
'girocard_applepay'
'girocard_applepay',
'scalapay_3x',
'scalapay_4x'
];

/**
Expand Down
4 changes: 4 additions & 0 deletions Test/Unit/Gateway/Request/RefundDataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ public function testBuild(
->with($paymentMethodInstanceMock)
->willReturn(true);

$this->paymentMethodsHelperMock->method('getRefundRequiresCapturePspreference')
->with($paymentMethodInstanceMock)
->willReturn(true);

$this->openInvoiceHelperMock->method('getOpenInvoiceDataForCreditMemo')
->with($creditMemoMock)
->willReturn(['lineItems' => [['product_id' => 1]]]);
Expand Down
9 changes: 9 additions & 0 deletions Test/Unit/Helper/PaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ public function testGetRequiresLineItems_RequiresLineItemsTrue(): void
$this->assertTrue($this->helper->getRequiresLineItems($this->methodMock));
}

public function testGetRefundRequiresCapturePspreference(): void
{
$this->methodMock->method('getConfigData')
->with(PaymentMethods::CONFIG_FIELD_REFUND_REQUIRES_CAPTURE_PSPREFERENCE)
->willReturn(true);

$this->assertTrue($this->helper->getRefundRequiresCapturePspreference($this->methodMock));
}

public function testCheckPaymentMethodNegative(): void
{
$payment = $this->createConfiguredMock(Order\Payment::class, [
Expand Down
3 changes: 3 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<supports_auto_capture>1</supports_auto_capture>
<is_wallet>0</is_wallet>
<requires_line_items>1</requires_line_items>
<refund_requires_capture_pspreference>1</refund_requires_capture_pspreference>
<group>adyen-alternative-payment-method</group>
</adyen_paypal>
<adyen_paypal_vault>
Expand Down Expand Up @@ -2703,6 +2704,7 @@
<supports_auto_capture>1</supports_auto_capture>
<is_wallet>0</is_wallet>
<is_open_invoice>1</is_open_invoice>
<refund_requires_capture_pspreference>1</refund_requires_capture_pspreference>
<group>adyen-alternative-payment-method</group>
</adyen_scalapay_3x>
<adyen_scalapay_4x>
Expand All @@ -2727,6 +2729,7 @@
<supports_auto_capture>1</supports_auto_capture>
<is_wallet>0</is_wallet>
<is_open_invoice>1</is_open_invoice>
<refund_requires_capture_pspreference>1</refund_requires_capture_pspreference>
<group>adyen-alternative-payment-method</group>
</adyen_scalapay_4x>
<adyen_paynow>
Expand Down
Loading