We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit bdb6d949 authored by Aleffio's avatar Aleffio

PW-615: Separate Initiate/Status flow for TerminalAPI

parent 2dfcff7e
......@@ -73,9 +73,10 @@ class TransactionPosCloudSync implements ClientInterface
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
$request = $transferObject->getBody();
if (!empty($request['response'])) {
if (!empty($request['response']) && !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 +124,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;
}
}
\ No newline at end of file
}
......@@ -61,7 +61,7 @@ class PaymentPosCloudHandler implements HandlerInterface
* @param array $response
* @return void
*/
public function handle(array $handlingSubject, array $response)
public function handle(array $handlingSubject, array $paymentResponse)
{
$payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
......@@ -74,13 +74,6 @@ class PaymentPosCloudHandler implements HandlerInterface
// no 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'];
......@@ -95,4 +88,4 @@ class PaymentPosCloudHandler implements HandlerInterface
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(false);
}
}
\ No newline at end of file
}
......@@ -71,35 +71,21 @@ class PosCloudResponseValidator extends AbstractValidator
// Check for errors
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)
return $this->createResult($isValid, $errorMessages);
} else {
$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'])){
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'];
$paymentResponse = $response;
}
if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') {
$errorMsg = __($paymentResponse['Response']['ErrorCondition']);
$this->adyenLogger->error($errorMsg);
$this->adyenLogger->error(json_encode($response));
throw new \Magento\Framework\Exception\LocalizedException(__("The transaction could not be completed."));
}
......@@ -109,4 +95,4 @@ class PosCloudResponseValidator extends AbstractValidator
}
return $this->createResult($isValid, $errorMessages);
}
}
\ No newline at end of file
}
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