From 2d785619be9cbc3c32bfa89353eeeb73c834eb7b Mon Sep 17 00:00:00 2001 From: Pavlo Kotets <99185488+pkotets@users.noreply.github.com> Date: Thu, 22 Feb 2024 19:34:58 +0000 Subject: [PATCH] v1.5.1 --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/Utils.php | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d0c36..9938fe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### [1.5.1] 2024-02-22 + +**BUGFIX:** + +- `Utils::receiptJsonSerialize()`: DateTime field serialization fixed fix, handle possible exception in case of wrong format + ### [1.5.0] 2023-08-31 **IMPROVEMENTS:** diff --git a/composer.json b/composer.json index 3da0c4e..8f5d3e7 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php" ], "homepage": "https://github.com/readdle/app-store-receipt-verification", - "version": "1.5.0", + "version": "1.5.1", "autoload": { "psr-4": { "Readdle\\AppStoreReceiptVerification\\": "src/" diff --git a/src/Utils.php b/src/Utils.php index 53bcafe..349dc45 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -5,6 +5,7 @@ use DateTime; use DateTimeZone; +use Exception; use Readdle\AppStoreReceiptVerification\PKCS7\AppStore\AbstractField; use function base64_encode; @@ -53,7 +54,12 @@ public static function receiptJsonSerialize(array $fields, bool $includeUnknown continue; } - $dt = DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $value); + try { + $dt = new DateTime($value); + } catch (Exception $e) { + continue; + } + $receipt[$type . '_ms'] = (string) ($dt->getTimestamp() * 1000); $dt->setTimezone(new DateTimeZone('Etc/GMT'));