init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Oceanpayment\Model\Gateway;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class ResponseParser
|
||||
{
|
||||
private const FIELDS = [
|
||||
'account',
|
||||
'terminal',
|
||||
'signValue',
|
||||
'order_number',
|
||||
'order_currency',
|
||||
'order_amount',
|
||||
'order_notes',
|
||||
'payment_id',
|
||||
'pay_url',
|
||||
'pay_results',
|
||||
'pay_details',
|
||||
];
|
||||
|
||||
public function parse(string $body): array
|
||||
{
|
||||
$previous = libxml_use_internal_errors(true);
|
||||
try {
|
||||
$xml = simplexml_load_string($body, \SimpleXMLElement::class, LIBXML_NONET | LIBXML_NOCDATA);
|
||||
} finally {
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($previous);
|
||||
}
|
||||
|
||||
if ($xml === false) {
|
||||
throw new LocalizedException(__('Oceanpayment returned an invalid XML response.'));
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach (self::FIELDS as $field) {
|
||||
$result[$field] = isset($xml->{$field}) ? trim((string)$xml->{$field}) : '';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user