From df2fc8b7082ad723f5194d33c20fed64ab6e9ea9 Mon Sep 17 00:00:00 2001 From: Michael Woodward Date: Mon, 15 Jan 2024 15:16:03 +0000 Subject: [PATCH] fix: Prevents invalid stream for null payloads (#4) fix: Prevents invalid stream for null payloads docs(release): 0.1.1 Resolves: #3 --- CHANGELOG.md | 6 ++++++ src/Client.php | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0265d86..aa398a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-php-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools. +## 0.1.1 - 2024-01-15 + +### Fixed + +- Resolved invalid streams being created for null payloads + ## dev - 2024-01-10 ### Added diff --git a/src/Client.php b/src/Client.php index a20e09b..c40be63 100644 --- a/src/Client.php +++ b/src/Client.php @@ -51,7 +51,7 @@ class Client { - private const SDK_VERSION = '0.1.0'; + private const SDK_VERSION = '0.1.1'; public readonly LoggerInterface $logger; public readonly Options $options; @@ -176,12 +176,14 @@ private function requestRaw(string $method, string|UriInterface $uri, array|\Jso [new JsonEncoder()], ); - $body = $serializer->serialize($payload, 'json'); + if ($payload !== null) { + $body = $serializer->serialize($payload, 'json'); - $request = $request->withBody( - // Satisfies empty body requests. - $this->streamFactory->createStream($body === '[]' ? '{}' : $body), - ); + $request = $request->withBody( + // Satisfies empty body requests. + $this->streamFactory->createStream($body === '[]' ? '{}' : $body), + ); + } $request = $request->withAddedHeader('X-Transaction-ID', $this->transactionId ?? (string) new Ulid());