Custom HTTP adapter
By default the PHP SDK uses its default HTTP Client library i. e. php-curl. The SDK serializes the resource into JSON and sends it to the API endpoint. The response is parsed and de-serialized to update the original object respectively creating an object from the response data.
If an error occurs within the communication between SDK and API, a heidelpayApiException
is thrown. An error on the SDK side, results in a \RuntimeException
.
If you prefer using a custom adapter, you can do so by implementing the
HttpAdapterInterface
and injecting it via setter into the heidelpay
object as shown in the example below.// Implement your own HTTP adapter
namespace My\Namespace;
use heidelpayPHP\Adapter\HttpAdapterInterface;
class MyHttpAdapter implements HttpAdapterInterface
{
public function init($url, $payload = null, $httpMethod = HttpAdapterInterface::REQUEST_GET);
public function execute()
{
// ...
}
public function getResponseCode(): string
{
// ...
}
public function close()
{
// ...
}
public function setHeaders(array $headers)
{
// ...
}
public function setUserAgent($userAgent)
{
// ...
}
}
// Inject your own HTTP adapter
$heidelpay = new heidelpayPHP\Heidelpay('s-priv-xxxxxxxxxx');
$heidelpay->setAdapter(new My\Namespace\MyHttpAdapter());