You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ymww_backend/addons/epay/library/v3/Yansongda/Pay/Direction/ArrayDirection.php

33 lines
916 B

1 year ago
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Direction;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Contract\DirectionInterface;
use Yansongda\Pay\Contract\PackerInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidResponseException;
class ArrayDirection implements DirectionInterface
{
/**
* @throws InvalidResponseException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): array
{
if (is_null($response)) {
throw new InvalidResponseException(Exception::RESPONSE_NONE);
}
$body = (string) $response->getBody();
if (!is_null($result = $packer->unpack($body))) {
return $result;
}
throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]);
}
}