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
*
* @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
* @return array
* @throws \Magento\Payment\Gateway\Http\ClientException
* @throws \Magento\Payment\Gateway\Http\ConverterException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
$request = $transferObject->getBody();
if (!empty($request['response'])) {
if (!empty($request['response']['SaleToPOIResponse']['PaymentResponse'])) {
$paymentResponse = $request['response']['SaleToPOIResponse']['PaymentResponse'];
//Initiate has already a response
return $request['response'];
return $paymentResponse;
}
//always do status call and return the response of the status call
$service = new \Adyen\Service\PosPayment($this->_client);
......@@ -123,8 +123,23 @@ class TransactionPosCloudSync implements ClientInterface
$response = $service->runTenderSync($request);
} catch (\Adyen\AdyenException $e) {
$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
* Handles response
*
* @param array $handlingSubject
* @param array $response
* @param array $paymentResponse
* @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);
......@@ -71,16 +72,9 @@ class PaymentPosCloudHandler implements HandlerInterface
// set transaction not to processing by default wait for notification
$payment->setIsTransactionPending(true);
// no not send order confirmation mail
// do not send order confirmation mail
$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)
if (!empty($paymentResponse) && !empty($paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'])) {
$pspReference = $paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'];
......
......@@ -71,32 +71,17 @@ class PosCloudResponseValidator extends AbstractValidator
// Check for errors
if (!empty($response['error'])) {
if (strpos($response['error'], "Could not connect") !== false) {
// Do the status call(try to place an order)
if (!empty($response['code']) && $response['code'] == CURLE_OPERATION_TIMEOUTED) {
// If the initiate call resulted in a timeout, do a status call(try to place an order)
return $this->createResult($isValid, $errorMessages);
} else {
// There is an error which is not a timeout, stop the transaction and show the error
$this->adyenLogger->error(json_encode($response));
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 {
$paymentResponse = $response['SaleToPOIResponse']['PaymentResponse'];
// We have a paymentResponse from the terminal
$paymentResponse = $response;
}
if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') {
......
......@@ -1184,15 +1184,16 @@ class Data extends AbstractHelper
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()) {
case true:
if ($this->isDemoMode($storeId)) {
$apiKey = $this->_encryptor->decrypt(trim($this->getAdyenPosCloudConfigData('api_key_test')));
break;
default:
} else {
$apiKey = $this->_encryptor->decrypt(trim($this->getAdyenPosCloudConfigData('api_key_live')));
break;
}
return $apiKey;
}
......@@ -1241,7 +1242,6 @@ class Data extends AbstractHelper
return $formatted;
}
/**
* Initializes and returns Adyen Client and sets the required parameters of it
*
......
......@@ -41,28 +41,20 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
/**
* AdyenInitiateTerminalApi constructor.
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param RecurringType $recurringType
* @param \Magento\Checkout\Model\Session $_checkoutSession
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Model\RecurringType $recurringType,
\Magento\Checkout\Model\Session $_checkoutSession,
array $data = []
)
{
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->_checkoutSession = $_checkoutSession;
// initialize client
......@@ -90,9 +82,8 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
/**
* Trigger sync call on terminal
*
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Exception
*/
public function initiate()
{
......
......@@ -332,22 +332,6 @@ class Cron
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
$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