We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit d443f4a8 authored by Alessio Zampatti's avatar Alessio Zampatti Committed by GitHub

Merge pull request #337 from Adyen/PW-615

Re-merging "PW-615"
parents 3ecb944b 365b5b0b
...@@ -67,15 +67,15 @@ class TransactionPosCloudSync implements ClientInterface ...@@ -67,15 +67,15 @@ class TransactionPosCloudSync implements ClientInterface
* *
* @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
* @return array * @return array
* @throws \Magento\Payment\Gateway\Http\ClientException * @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Payment\Gateway\Http\ConverterException
*/ */
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject) public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{ {
$request = $transferObject->getBody(); $request = $transferObject->getBody();
if (!empty($request['response'])) { if (!empty($request['response']['SaleToPOIResponse']['PaymentResponse'])) {
$paymentResponse = $request['response']['SaleToPOIResponse']['PaymentResponse'];
//Initiate has already a response //Initiate has already a response
return $request['response']; return $paymentResponse;
} }
//always do status call and return the response of the status call //always do status call and return the response of the status call
$service = new \Adyen\Service\PosPayment($this->_client); $service = new \Adyen\Service\PosPayment($this->_client);
...@@ -123,8 +123,23 @@ class TransactionPosCloudSync implements ClientInterface ...@@ -123,8 +123,23 @@ class TransactionPosCloudSync implements ClientInterface
$response = $service->runTenderSync($request); $response = $service->runTenderSync($request);
} catch (\Adyen\AdyenException $e) { } catch (\Adyen\AdyenException $e) {
$response['error'] = $e->getMessage(); $response['error'] = $e->getMessage();
return $response;
} }
return $response; if (!empty($response['SaleToPOIResponse']['TransactionStatusResponse'])) {
$statusResponse = $response['SaleToPOIResponse']['TransactionStatusResponse'];
if ($statusResponse['Response']['Result'] == 'Failure') {
$errorMsg = __('In Progress');
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
} else {
$paymentResponse = $statusResponse['RepeatedMessageResponse']['RepeatedResponseMessageBody']['PaymentResponse'];
}
} else {
// probably SaleToPOIRequest, that means terminal unreachable, log the response as error
$this->adyenLogger->error(json_encode($response));
throw new \Magento\Framework\Exception\LocalizedException(__("The terminal could not be reached."));
}
return $paymentResponse;
} }
} }
...@@ -58,10 +58,11 @@ class PaymentPosCloudHandler implements HandlerInterface ...@@ -58,10 +58,11 @@ class PaymentPosCloudHandler implements HandlerInterface
* Handles response * Handles response
* *
* @param array $handlingSubject * @param array $handlingSubject
* @param array $response * @param array $paymentResponse
* @return void * @return void
* @throws Exception
*/ */
public function handle(array $handlingSubject, array $response) public function handle(array $handlingSubject, array $paymentResponse)
{ {
$payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject); $payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
...@@ -71,16 +72,9 @@ class PaymentPosCloudHandler implements HandlerInterface ...@@ -71,16 +72,9 @@ class PaymentPosCloudHandler implements HandlerInterface
// set transaction not to processing by default wait for notification // set transaction not to processing by default wait for notification
$payment->setIsTransactionPending(true); $payment->setIsTransactionPending(true);
// no not send order confirmation mail // do not send order confirmation mail
$payment->getOrder()->setCanSendNewEmailFlag(false); $payment->getOrder()->setCanSendNewEmailFlag(false);
if (!empty($response['SaleToPOIResponse']['TransactionStatusResponse'])) {
$statusResponse = $response['SaleToPOIResponse']['TransactionStatusResponse'];
$paymentResponse = $statusResponse['RepeatedMessageResponse']['RepeatedResponseMessageBody']['PaymentResponse'];
} else {
$paymentResponse = $response['SaleToPOIResponse']['PaymentResponse'];
}
// set transaction(status) // set transaction(status)
if (!empty($paymentResponse) && !empty($paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'])) { if (!empty($paymentResponse) && !empty($paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'])) {
$pspReference = $paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID']; $pspReference = $paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'];
......
...@@ -71,32 +71,17 @@ class PosCloudResponseValidator extends AbstractValidator ...@@ -71,32 +71,17 @@ class PosCloudResponseValidator extends AbstractValidator
// Check for errors // Check for errors
if (!empty($response['error'])) { if (!empty($response['error'])) {
if (strpos($response['error'], "Could not connect") !== false) { if (!empty($response['code']) && $response['code'] == CURLE_OPERATION_TIMEOUTED) {
// Do the status call(try to place an order) // If the initiate call resulted in a timeout, do a status call(try to place an order)
return $this->createResult($isValid, $errorMessages); return $this->createResult($isValid, $errorMessages);
} else { } else {
// There is an error which is not a timeout, stop the transaction and show the error
$this->adyenLogger->error(json_encode($response)); $this->adyenLogger->error(json_encode($response));
throw new \Magento\Framework\Exception\LocalizedException(__($response['error'])); throw new \Magento\Framework\Exception\LocalizedException(__($response['error']));
} }
}
// We receive a SaleToPOIRequest when the terminal is not reachable
if (!empty($response['SaleToPOIRequest'])){
$this->adyenLogger->error(json_encode($response));
throw new \Magento\Framework\Exception\LocalizedException(__("The terminal could not be reached."));
}
// Check if Status or PaymentResponse
if (!empty($response['SaleToPOIResponse']['TransactionStatusResponse'])) {
$statusResponse = $response['SaleToPOIResponse']['TransactionStatusResponse'];
if ($statusResponse['Response']['Result'] == 'Failure') {
$errorMsg = __('In Progress');
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
} else {
$paymentResponse = $statusResponse['RepeatedMessageResponse']['RepeatedResponseMessageBody']['PaymentResponse'];
}
} else { } else {
$paymentResponse = $response['SaleToPOIResponse']['PaymentResponse']; // We have a paymentResponse from the terminal
$paymentResponse = $response;
} }
if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') { if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') {
......
...@@ -1184,15 +1184,16 @@ class Data extends AbstractHelper ...@@ -1184,15 +1184,16 @@ class Data extends AbstractHelper
return $formFields; return $formFields;
} }
public function getApiKey() /**
* @param integer|null $storeId
* @return string the X API Key for the specified or current store
*/
public function getApiKey($storeId = null)
{ {
switch ($this->isDemoMode()) { if ($this->isDemoMode($storeId)) {
case true:
$apiKey = $this->_encryptor->decrypt(trim($this->getAdyenPosCloudConfigData('api_key_test'))); $apiKey = $this->_encryptor->decrypt(trim($this->getAdyenPosCloudConfigData('api_key_test')));
break; } else {
default:
$apiKey = $this->_encryptor->decrypt(trim($this->getAdyenPosCloudConfigData('api_key_live'))); $apiKey = $this->_encryptor->decrypt(trim($this->getAdyenPosCloudConfigData('api_key_live')));
break;
} }
return $apiKey; return $apiKey;
} }
...@@ -1241,7 +1242,6 @@ class Data extends AbstractHelper ...@@ -1241,7 +1242,6 @@ class Data extends AbstractHelper
return $formatted; return $formatted;
} }
/** /**
* Initializes and returns Adyen Client and sets the required parameters of it * Initializes and returns Adyen Client and sets the required parameters of it
* *
......
...@@ -41,28 +41,20 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface ...@@ -41,28 +41,20 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
/** /**
* AdyenInitiateTerminalApi constructor. * AdyenInitiateTerminalApi constructor.
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param RecurringType $recurringType * @param \Magento\Checkout\Model\Session $_checkoutSession
* @param array $data * @param array $data
*/ */
public function __construct( public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger, \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Model\RecurringType $recurringType,
\Magento\Checkout\Model\Session $_checkoutSession, \Magento\Checkout\Model\Session $_checkoutSession,
array $data = [] array $data = []
) )
{ {
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->_checkoutSession = $_checkoutSession; $this->_checkoutSession = $_checkoutSession;
// initialize client // initialize client
...@@ -90,9 +82,8 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface ...@@ -90,9 +82,8 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
/** /**
* Trigger sync call on terminal * Trigger sync call on terminal
*
* @return mixed * @return mixed
* @throws \Magento\Framework\Exception\LocalizedException * @throws \Exception
*/ */
public function initiate() public function initiate()
{ {
......
...@@ -332,22 +332,6 @@ class Cron ...@@ -332,22 +332,6 @@ class Cron
continue; continue;
} }
/**
* If the event is a RECURRING_CONTRACT wait an extra 5 minutes
* before processing so we are sure the RECURRING_CONTRACT
*/
if (trim($notification->getEventCode()) == Notification::RECURRING_CONTRACT &&
strtotime($notification->getCreatedAt()) >= strtotime('-5 minutes', time())
) {
$this->_adyenLogger->addAdyenNotificationCronjob(
"This is a recurring_contract notification wait an extra 5 minutes
before processing this to make sure the contract exists"
);
// set processing back to false
$this->_updateNotification($notification, false, false);
continue;
}
// log the executed notification // log the executed notification
$this->_adyenLogger->addAdyenNotificationCronjob(print_r($notification->debug(), 1)); $this->_adyenLogger->addAdyenNotificationCronjob(print_r($notification->debug(), 1));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment