diff --git a/Helpers/RefundHelper.php b/Helpers/RefundHelper.php index 2c0e1b5..3c16b89 100644 --- a/Helpers/RefundHelper.php +++ b/Helpers/RefundHelper.php @@ -165,7 +165,7 @@ private function buildPayload(object $order, array $built): array $payload = [ 'client_id' => (string)$cid, - 'timestamp_micros' => (string)microtime(true) * 1000000, + 'timestamp_micros' => (string)(int)(microtime(true) * 1000000), 'non_personalized_ads' => false, 'events' => [ [ diff --git a/Init/module.json b/Init/module.json index 947a700..278746e 100644 --- a/Init/module.json +++ b/Init/module.json @@ -1,6 +1,6 @@ { "Okay": "4.5.3", - "version": "1.1.0", + "version": "1.1.1", "moduleName": "Аналітика GA4", "vendor": { "email": "devsviat@proton.me", diff --git a/tests/RefundTimestampTest.php b/tests/RefundTimestampTest.php new file mode 100644 index 0000000..f5802d3 --- /dev/null +++ b/tests/RefundTimestampTest.php @@ -0,0 +1,48 @@ +createStub(CurrenciesEntity::class); + $currencies->method('getMainCurrency')->willReturn((object) ['code' => 'UAH']); + $entityFactory = $this->createStub(EntityFactory::class); + $entityFactory->method('get')->willReturn($currencies); + + $helper = new RefundHelper( + $entityFactory, + new ReflectionClass(AnalyticsHelper::class)->newInstanceWithoutConstructor(), + new ReflectionClass(Settings::class)->newInstanceWithoutConstructor(), + ); + + $before = (int) (microtime(true) * 1000000); + $payload = new ReflectionMethod(RefundHelper::class, 'buildPayload')->invoke( + $helper, + (object) ['id' => 7, 'cid' => '1.2', 'sid' => '', 'user_id' => 0], + ['items' => [], 'shipping' => 0, 'value' => 10], + ); + $after = (int) (microtime(true) * 1000000); + + $micros = $payload['timestamp_micros']; + self::assertIsString($micros); + self::assertMatchesRegularExpression('/^\d{16}$/', $micros); + self::assertGreaterThanOrEqual($before, (int) $micros); + self::assertLessThanOrEqual($after, (int) $micros); + self::assertMatchesRegularExpression('/"timestamp_micros":"\d{16}"/', json_encode($payload)); + } +}