Skip to content

Commit

Permalink
Merge pull request #2412 from Adyen/develop-8
Browse files Browse the repository at this point in the history
Release 8.22.6
  • Loading branch information
candemiralp authored Dec 28, 2023
2 parents 3c72c56 + ea3b60c commit f597689
Show file tree
Hide file tree
Showing 12 changed files with 485 additions and 253 deletions.
45 changes: 23 additions & 22 deletions Gateway/Http/Client/TransactionPosCloudSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Checkout\Model\Session;
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Quote\Api\Data\CartInterface;
use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider;
Expand Down Expand Up @@ -106,16 +107,18 @@ public function placeRequest(TransferInterface $transferObject): array
$newServiceID = date("dHis");
$statusDate = date("U");
$terminalId = $request['terminalID'];
$order = $request['order'];

if (array_key_exists('chainCalls', $request)) {
$quote = $this->initiatePosPayment(
$order = $this->initiatePosPayment(
$order,
$terminalId,
$request['fundingSource'],
$request['numberOfInstallments']
);
$quoteInfoInstance = $quote->getPayment()->getMethodInstance()->getInfoInstance();
$timeDiff = (int)$statusDate - (int)$quoteInfoInstance->getAdditionalInformation('initiateDate');
$serviceId = $quoteInfoInstance->getAdditionalInformation('serviceID');
$payment = $order->getPayment();
$timeDiff = (int)$statusDate - (int)$payment->getAdditionalInformation('initiateDate');
$serviceId = $payment->getAdditionalInformation('serviceID');
} else {
$timeDiff = (int)$statusDate - (int)$request['initiateDate'];
$serviceId = $request['serviceID'];
Expand Down Expand Up @@ -182,19 +185,20 @@ public function placeRequest(TransferInterface $transferObject): array
/**
* Initiate a POS payment by sending a /sync call to Adyen
*
* @param OrderInterface $order
* @param string $terminalId
* @param string $fundingSource
* @param string|null $numberOfInstallments
* @return CartInterface
* @return OrderInterface
* @throws AdyenException
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function initiatePosPayment(
OrderInterface $order,
string $terminalId,
string $fundingSource,
?string $numberOfInstallments
): CartInterface {
): OrderInterface {
// Validate JSON that has just been parsed if it was in a valid format
if (json_last_error() !== JSON_ERROR_NONE) {
throw new LocalizedException(
Expand All @@ -203,13 +207,10 @@ public function initiatePosPayment(
}

$poiId = $terminalId;

/** @var CartInterface $quote */
$quote = $this->session->getQuote();
$payment = $quote->getPayment();
$adyenAmountCurrency = $this->chargedCurrency->getQuoteAmountCurrency($quote);
$payment = $order->getPayment();
$adyenAmountCurrency = $this->chargedCurrency->getOrderAmountCurrency($order);
$payment->setMethod(AdyenPosCloudConfigProvider::CODE);
$reference = $quote->reserveOrderId()->getReservedOrderId();
$reference = $order->getIncrementId();

$service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$transactionType = \Adyen\TransactionType::NORMAL;
Expand Down Expand Up @@ -285,15 +286,14 @@ public function initiatePosPayment(
];
}

$request = $this->pointOfSale->addSaleToAcquirerData($request, $quote);
$paymentInfoInstance = $quote->getPayment()->getMethodInstance()->getInfoInstance();
$request = $this->pointOfSale->addSaleToAcquirerData($request, null, $order);

$paymentInfoInstance->setAdditionalInformation(
$payment->setAdditionalInformation(
'serviceID',
$serviceID
);

$paymentInfoInstance->setAdditionalInformation(
$payment->setAdditionalInformation(
'initiateDate',
$initiateDate
);
Expand All @@ -306,21 +306,22 @@ public function initiatePosPayment(
$this->adyenLogger->addAdyenDebug($response['error'] = $e->getMessage());
} catch (\Exception $e) {
//Probably timeout
$paymentInfoInstance->setAdditionalInformation(
$payment->setAdditionalInformation(
'terminalResponse',
null
);
$quote->save();

$response['error'] = $e->getMessage();
throw $e;
}
$this->adyenHelper->logResponse($response);
$paymentInfoInstance->setAdditionalInformation(
$payment->setAdditionalInformation(
'terminalResponse',
$response
);

$quote->save();
return $quote;
$order->save();

return $order;
}
}
4 changes: 2 additions & 2 deletions Gateway/Request/CaptureDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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 @@ -227,7 +227,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 @@ -128,7 +128,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
4 changes: 3 additions & 1 deletion Gateway/Request/PosCloudBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Adyen\Payment\Gateway\Request;

use Adyen\Payment\Helper\PaymentMethods;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;

Expand All @@ -36,7 +37,8 @@ public function build(array $buildSubject)
'terminalID' => $payment->getAdditionalInformation('terminal_id'),
'numberOfInstallments' => $payment->getAdditionalInformation('number_of_installments'),
'chainCalls' => $payment->getAdditionalInformation('chain_calls'),
'fundingSource' => $payment->getAdditionalInformation('funding_source')
'fundingSource' => $payment->getAdditionalInformation('funding_source') ?? PaymentMethods::FUNDING_SOURCE_CREDIT,
'order' => $payment->getOrder()
];
} else {
$body = [
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ 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);
}
Expand Down
4 changes: 4 additions & 0 deletions Gateway/Response/PaymentPosCloudHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function handle(array $handlingSubject, array $paymentResponse)
// do not send order confirmation mail
$payment->getOrder()->setCanSendNewEmailFlag(false);

if (!empty($paymentResponse) && isset($paymentResponse['Response']['Result'])) {
$payment->setAdditionalInformation('resultCode', $paymentResponse['Response']['Result']);
}

if (!empty($paymentResponse['Response']['AdditionalResponse'])
) {
$pairs = \explode('&', $paymentResponse['Response']['AdditionalResponse']);
Expand Down
Loading

0 comments on commit f597689

Please sign in to comment.