Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-8799] [V9] Fix refund openinvoice after cart expired #2385

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gateway/Request/CaptureDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function build(array $buildSubject): array

//Check additionaldata
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceData($order);
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForOrder($order);
$requestBody = array_merge($requestBody, $openInvoiceFields);
}
$request['body'] = $requestBody;
Expand Down Expand Up @@ -179,7 +179,7 @@ public function buildPartialOrMultipleCaptureData($payment, $currency, $adyenOrd
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod(
$adyenOrderPayment[OrderPaymentInterface::PAYMENT_METHOD]
)) {
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceData($payment);
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForLastInvoice($payment);
$authToCapture = array_merge($authToCapture, $openInvoiceFields);
}

Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function build(array $buildSubject): array
$payment->getMethod() === AdyenPayByLinkConfigProvider::CODE
) {

$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceData($order);
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForOrder($order);
$requestBody = array_merge($requestBody, $openInvoiceFields);

if (isset($brandCode) &&
Expand Down
11 changes: 4 additions & 7 deletions Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
use Adyen\Payment\Model\ResourceModel\Invoice\CollectionFactory;
use Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory as PaymentCollectionFactory;
use Adyen\Payment\Observer\AdyenPaymentMethodDataAssignObserver;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Payment\Model\InfoInterface;
use Magento\Sales\Model\Order\Creditmemo;
use Magento\Sales\Model\Order\Payment;

/**
* Class CustomerDataBuilder
Expand All @@ -36,20 +34,17 @@ class RefundDataBuilder implements BuilderInterface
private Data $adyenHelper;
private Config $configHelper;
private PaymentCollectionFactory $orderPaymentCollectionFactory;
protected CollectionFactory $adyenInvoiceCollectionFactory;
private ChargedCurrency $chargedCurrency;

public function __construct(
Data $adyenHelper,
PaymentCollectionFactory $orderPaymentCollectionFactory,
CollectionFactory $adyenInvoiceCollectionFactory,
ChargedCurrency $chargedCurrency,
Config $configHelper,
OpenInvoice $openInvoiceHelper
) {
$this->adyenHelper = $adyenHelper;
$this->orderPaymentCollectionFactory = $orderPaymentCollectionFactory;
$this->adyenInvoiceCollectionFactory = $adyenInvoiceCollectionFactory;
$this->chargedCurrency = $chargedCurrency;
$this->configHelper = $configHelper;
$this->openInvoiceHelper = $openInvoiceHelper;
Expand All @@ -60,6 +55,7 @@ public function build(array $buildSubject): array
$paymentDataObject = SubjectReader::readPayment($buildSubject);

$order = $paymentDataObject->getOrder();
/** @var Payment $payment */
$payment = $paymentDataObject->getPayment();
$orderAmountCurrency = $this->chargedCurrency->getOrderAmountCurrency($payment->getOrder(), false);

Expand Down Expand Up @@ -168,11 +164,12 @@ public function build(array $buildSubject): array
);

if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$openInvoiceFieldsCreditMemo = $this->openInvoiceHelper->getOpenInvoiceData($creditMemo->getOrder());
$openInvoiceFieldsCreditMemo = $this->openInvoiceHelper->getOpenInvoiceDataForCreditMemo($payment);
//There is only one payment, so we add the fields to the first(and only) result
$requestBody[0] = array_merge($requestBody[0], $openInvoiceFieldsCreditMemo);
}
}

$request['clientConfig'] = ["storeId" => $payment->getOrder()->getStoreId()];
$request['body'] = $requestBody;

Expand Down
Loading
Loading