Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop-8' into develop-8
Browse files Browse the repository at this point in the history
  • Loading branch information
candemiralp committed Dec 28, 2023
2 parents 066ceb7 + d085467 commit ea3b60c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 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: 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
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
2 changes: 2 additions & 0 deletions Helper/PaymentResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PaymentResponseHandler
const CANCELLED = 'Cancelled';
const ADYEN_TOKENIZATION = 'Adyen Tokenization';
const VAULT = 'Magento Vault';
const POS_SUCCESS = 'Success';

/**
* @var AdyenLogger
Expand Down Expand Up @@ -118,6 +119,7 @@ public function formatPaymentResponse($resultCode, $action = null, $additionalDa
case self::AUTHORISED:
case self::REFUSED:
case self::ERROR:
case self::POS_SUCCESS:
return [
"isFinal" => true,
"resultCode" => $resultCode,
Expand Down
4 changes: 3 additions & 1 deletion etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ input AdyenAdditionalDataOneclick {
}

input AdyenAdditionalDataPosCloud {
terminal_id: String! @doc(description: "Terminal ID of selected terminal.")
number_of_installments: Int @doc(description: "Number of installments for the payment.")
terminal_id: String @doc(description: "Terminal ID of selected terminal.")
chain_calls: Boolean @doc(description: "Indicates the chained call.")
funding_source: String @doc(description: "Funding source to be used for combo cards.")
}

type StoreConfig @doc(description: "The type contains information about a store config") {
Expand Down

0 comments on commit ea3b60c

Please sign in to comment.