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 1c9b2899 authored by Alessio Zampatti's avatar Alessio Zampatti Committed by Aleffio

PW-503: Parse Payment receipt from TerminalAPI PaymentResponse (#304)

* PW-503: Parse Payment receipt from TerminalAPI PaymentResponse

* PW-503: call formatTerminalAPIReceipt from the validator

* PW-503: removed redundant html tags, added custom table class

* PW-503: removed redundant table, refactor, added nbsp if empty
parent 16ca2716
......@@ -35,6 +35,11 @@ class PosCloudResponseValidator extends AbstractValidator
*/
private $adyenLogger;
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* PosCloudResponseValidator constructor.
* @param \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory
......@@ -42,9 +47,11 @@ class PosCloudResponseValidator extends AbstractValidator
*/
public function __construct(
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->adyenLogger = $adyenLogger;
$this->adyenHelper = $adyenHelper;
parent::__construct($resultFactory);
}
......@@ -57,6 +64,8 @@ class PosCloudResponseValidator extends AbstractValidator
$errorMessages = [];
$isValid = true;
$response = \Magento\Payment\Gateway\Helper\SubjectReader::readResponse($validationSubject);
$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") {
......@@ -73,6 +82,10 @@ class PosCloudResponseValidator extends AbstractValidator
$errorMessages[] = $errorMsg;
$isValid = true;
}
if(!empty($response['SaleToPOIResponse']['PaymentResponse']['PaymentReceipt'])) {
$formattedReceipt = $this->adyenHelper->formatTerminalAPIReceipt(json_encode($response['SaleToPOIResponse']['PaymentResponse']['PaymentReceipt']));
$payment->setAdditionalInformation('receipt', $formattedReceipt);
}
return $this->createResult($isValid, $errorMessages);
}
}
\ No newline at end of file
......@@ -1214,6 +1214,33 @@ class Data extends AbstractHelper
return $merchantAccount;
}
public function formatTerminalAPIReceipt($paymentReceipt)
{
$paymentReceipt = json_decode($paymentReceipt);
$formatted = "<table class='terminal-api-receipt'>";
foreach ($paymentReceipt as $receipt) {
if ($receipt->DocumentQualifier == "CustomerReceipt") {
foreach ($receipt->OutputContent->OutputText as $item) {
parse_str($item->Text, $textParts);
$formatted .= "<tr class='terminal-api-receipt'>";
if (!empty($textParts['name'])) {
$formatted .= "<td class='terminal-api-receipt-name'>" . $textParts['name'] . "</td>";
} else {
$formatted .= "<td class='terminal-api-receipt-name'>&nbsp;</td>";
}
if (!empty($textParts['value'])) {
$formatted .= "<td class='terminal-api-receipt-value' align='right'>" . $textParts['value'] . "</td>";
} else {
$formatted .= "<td class='terminal-api-receipt-value' align='right'>&nbsp;</td>";
}
$formatted .= "</tr>";
}
}
}
$formatted .= "</table>";
return $formatted;
}
/**
* Initializes and returns Adyen Client and sets the required parameters of it
......
......@@ -61,3 +61,10 @@ $_isDemoMode = $block->isDemoMode();
<?php endif;?>
<?php echo $block->getChildHtml()?>
<style>
table.terminal-api-receipt{margin-top: 10px}
td.terminal-api-receipt-name{padding:inherit; font-weight: 700}
td.terminal-api-receipt-value{padding:inherit;}
tr.terminal-api-receipt{padding-bottom: 5px;}
</style>
<?php echo $this->getMethod()->getInfoInstance()->getAdditionalInformation('receipt');?>
\ No newline at end of file
......@@ -32,4 +32,11 @@ $_info = $this->getInfo();
<dl class="payment-method adyen_pos_cloud">
<?php echo $this->escapeHtml($this->getMethod()->getTitle()) ?><br/>
<dt class="title"><?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
<style>
table.terminal-api-receipt{margin-top: 10px}
td.terminal-api-receipt-name{padding:inherit; font-weight: 700}
td.terminal-api-receipt-value{padding:inherit;}
tr.terminal-api-receipt{padding-bottom: 5px;}
</style>
<table><?php $receipt = $this->getMethod()->getInfoInstance()->getAdditionalInformation('receipt'); echo $receipt;?></table>
</dl>
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