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 ce46eacd authored by Aleffio's avatar Aleffio

PW-560: Rebuild the validator

parent 8d275529
......@@ -67,23 +67,44 @@ class PosCloudResponseValidator extends AbstractValidator
$paymentDataObjectInterface = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($validationSubject);
$payment = $paymentDataObjectInterface->getPayment();
// Check In Progress status call
if (!empty($response['SaleToPOIResponse']['TransactionStatusResponse']['Response']['Result']) && $response['SaleToPOIResponse']['TransactionStatusResponse']['Response']['Result'] == "Failure") {
$errorMsg = __('In Progress');
$errorMessages[] = $errorMsg;
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
$this->adyenLogger->addAdyenDebug(print_r($response, true));
// Check for errors
if (!empty($response['error'])) {
if (strpos($response['error'], "Could not connect") !== false) {
// Do the status call(try to place an order)
return $this->createResult($isValid, $errorMessages);
} else {
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."));
}
elseif ((!empty($response['SaleToPOIResponse']['PaymentResponse']['Response']['Result']) &&
$response['SaleToPOIResponse']['PaymentResponse']['Response']['Result'] != 'Success'
) || empty($response['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])
) {
$errorMsg = __('Problem with POS terminal');
// 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'];
}
if (!empty($paymentResponse) && $paymentResponse['Response']['Result'] != 'Success') {
$errorMsg = __($paymentResponse['Response']['ErrorCondition']);
$this->adyenLogger->error($errorMsg);
$errorMessages[] = $errorMsg;
$isValid = true;
throw new \Magento\Framework\Exception\LocalizedException(__("The transaction could not be completed."));
}
if(!empty($response['SaleToPOIResponse']['PaymentResponse']['PaymentReceipt'])) {
$formattedReceipt = $this->adyenHelper->formatTerminalAPIReceipt(json_encode($response['SaleToPOIResponse']['PaymentResponse']['PaymentReceipt']));
if (!empty($paymentResponse['PaymentReceipt'])) {
$formattedReceipt = $this->adyenHelper->formatTerminalAPIReceipt(json_encode($paymentResponse['PaymentReceipt']));
$payment->setAdditionalInformation('receipt', $formattedReceipt);
}
return $this->createResult($isValid, $errorMessages);
......
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