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 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 ...@@ -73,9 +73,10 @@ class TransactionPosCloudSync implements ClientInterface
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']) && !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 +124,23 @@ class TransactionPosCloudSync implements ClientInterface ...@@ -123,8 +124,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;
} }
} }
...@@ -61,7 +61,7 @@ class PaymentPosCloudHandler implements HandlerInterface ...@@ -61,7 +61,7 @@ class PaymentPosCloudHandler implements HandlerInterface
* @param array $response * @param array $response
* @return void * @return void
*/ */
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);
...@@ -74,13 +74,6 @@ class PaymentPosCloudHandler implements HandlerInterface ...@@ -74,13 +74,6 @@ class PaymentPosCloudHandler implements HandlerInterface
// no not send order confirmation mail // no 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,35 +71,21 @@ class PosCloudResponseValidator extends AbstractValidator ...@@ -71,35 +71,21 @@ 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) // Do the status call(try to place an order)
return $this->createResult($isValid, $errorMessages); return $this->createResult($isValid, $errorMessages);
} else { } else {
$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'])){
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']; $paymentResponse = $response;
} }
if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') { if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') {
$errorMsg = __($paymentResponse['Response']['ErrorCondition']); $errorMsg = __($paymentResponse['Response']['ErrorCondition']);
$this->adyenLogger->error($errorMsg); $this->adyenLogger->error($errorMsg);
$this->adyenLogger->error(json_encode($response));
throw new \Magento\Framework\Exception\LocalizedException(__("The transaction could not be completed.")); throw new \Magento\Framework\Exception\LocalizedException(__("The transaction could not be completed."));
} }
......
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