From bec172a489904d5883ea5e8a7ecfc2ee42bb1c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Owsiak?= Date: Tue, 19 Jul 2022 17:32:11 +0200 Subject: [PATCH 1/2] Changed date time format during deserialization --- .../SellingPartner/ObjectSerializer.php | 8 +-- .../Functional/FulfillmentOutboundApiTest.php | 56 +++++++++++++++++++ .../Tests/Functional/ReportsApiTest.php | 19 +++++++ 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/AmazonPHP/SellingPartner/ObjectSerializer.php b/src/AmazonPHP/SellingPartner/ObjectSerializer.php index e18daeeb8..96428b91b 100644 --- a/src/AmazonPHP/SellingPartner/ObjectSerializer.php +++ b/src/AmazonPHP/SellingPartner/ObjectSerializer.php @@ -11,7 +11,7 @@ final class ObjectSerializer { - private static string $dateTimeFormat = \DateTimeInterface::ATOM; + private static string $dateTimeFormat = 'Y-m-d\TH:i:s.v\Z'; /** * Change the date format. @@ -39,7 +39,7 @@ public static function sanitizeForSerialization($data, string $type = null, stri } if ($data instanceof \DateTimeInterface) { - return ($format === 'date') ? $data->format('Y-m-d') : $data->format(self::$dateTimeFormat); + return ($format === 'date') ? $data->format('Y-m-d') : $data->setTimezone(new \DateTimeZone('UTC'))->format(self::$dateTimeFormat); } if (\is_array($data)) { @@ -193,8 +193,8 @@ public static function toFormValue($value) */ public static function toString($value) : string { - if ($value instanceof \DateTimeInterface) { // datetime in ISO8601 format - return $value->format(self::$dateTimeFormat); + if ($value instanceof \DateTimeInterface) { // datetime in ISO8601 zulu format + return $value->setTimezone(new \DateTimeZone('UTC'))->format(self::$dateTimeFormat); } if (\is_bool($value)) { diff --git a/tests/AmazonPHP/SellingPartner/Tests/Functional/FulfillmentOutboundApiTest.php b/tests/AmazonPHP/SellingPartner/Tests/Functional/FulfillmentOutboundApiTest.php index 728cc4eab..1288e5879 100644 --- a/tests/AmazonPHP/SellingPartner/Tests/Functional/FulfillmentOutboundApiTest.php +++ b/tests/AmazonPHP/SellingPartner/Tests/Functional/FulfillmentOutboundApiTest.php @@ -6,10 +6,15 @@ use AmazonPHP\SellingPartner\Marketplace; use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\Address; +use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\CODSettings; +use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\CreateFulfillmentOrderItem; +use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\CreateFulfillmentOrderRequest; use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\FeatureSettings; +use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\FulfillmentAction; use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\FulfillmentPreview; use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\GetFulfillmentPreviewItem; use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\GetFulfillmentPreviewRequest; +use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\Money; use AmazonPHP\SellingPartner\Model\FulfillmentOutbound\ShippingSpeedCategory; final class FulfillmentOutboundApiTest extends SandboxTestCase @@ -81,4 +86,55 @@ public function test_sandbox_get_fulfillment_preview() : void $this->assertCount(1, $response->getPayload()->getFulfillmentPreviews()); $this->assertContainsOnlyInstancesOf(FulfillmentPreview::class, $response->getPayload()->getFulfillmentPreviews()); } + + public function test_sandbox_create_fulfillment_order() : void + { + $marketplace = Marketplace::US(); + + $response = $this->sellingPartnerSDK->fulfillmentOutbound()->createFulfillmentOrder( + $this->sellingPartnerSDK->oAuth()->exchangeRefreshToken($this->sellerRefreshToken), + $marketplace->region(), + new CreateFulfillmentOrderRequest([ + 'marketplace_id' => 'ATVPDKIKX0DER', + 'seller_fulfillment_order_id' => 'FBATestOrder-11', + 'displayable_order_id' => 'TestOrder-FBAOutbound', + 'displayable_order_date' => new \DateTime('2020-01-09T19:46:45.809Z'), + 'displayable_order_comment' => 'TestOrder', + 'shipping_speed_category' => new ShippingSpeedCategory(ShippingSpeedCategory::STANDARD), + 'destination_address' => new Address([ + 'name' => 'Amazon', + 'address_line1' => '1234 Amazon Way', + 'address_line2' => 'Suite 123', + 'address_line3' => 'Lane1', + 'city' => 'Troy', + 'state_or_region' => 'MI', + 'postal_code' => '48084', + 'country_code' => 'US', + ]), + 'fulfillment_action' => new FulfillmentAction(FulfillmentAction::SHIP), + 'cod_settings' => new CODSettings([ + 'is_cod_required' => false, + 'cod_charge' => new Money(['value' => '10.00', 'currency_code' => 'USD']), + 'cod_charge_tax' => new Money(['value' => '2.00', 'currency_code' => 'USD']), + 'shipping_charge' => new Money(['value' => '5.00', 'currency_code' => 'USD']), + 'shipping_charge_tax' => new Money(['value' => '3.00', 'currency_code' => 'USD']), + ]), + 'notification_emails' => ['test1%40amazon.com', 'test2%40amazon.com'], + 'items' => [ + new CreateFulfillmentOrderItem([ + 'seller_sku' => 'CR-47K6-H6QN', + 'seller_fulfillment_order_item_id' => 'OrderItemID1', + 'quantity' => 3, + ]), + new CreateFulfillmentOrderItem([ + 'seller_sku' => 'PSMM-TEST-SKU-Jan-21_19_59_44-0738', + 'seller_fulfillment_order_item_id' => 'OrderItemID2', + 'quantity' => 1, + ]) + ], + ]) + ); + + $this->assertNull($response->getErrors()); + } } diff --git a/tests/AmazonPHP/SellingPartner/Tests/Functional/ReportsApiTest.php b/tests/AmazonPHP/SellingPartner/Tests/Functional/ReportsApiTest.php index 413a00932..be825ee9e 100644 --- a/tests/AmazonPHP/SellingPartner/Tests/Functional/ReportsApiTest.php +++ b/tests/AmazonPHP/SellingPartner/Tests/Functional/ReportsApiTest.php @@ -5,6 +5,7 @@ namespace AmazonPHP\Test\AmazonPHP\SellingPartner\Tests\Functional; use AmazonPHP\SellingPartner\Marketplace; +use AmazonPHP\SellingPartner\Model\Reports\CreateReportScheduleSpecification; use AmazonPHP\SellingPartner\Model\Reports\Report; final class ReportsApiTest extends SandboxTestCase @@ -23,4 +24,22 @@ public function test_sandbox_get_reports() : void $this->assertCount(1, $response->getReports()); $this->assertContainsOnlyInstancesOf(Report::class, $response->getReports()); } + + public function test_sandbox_create_report_schedule() : void + { + $marketplace = Marketplace::US(); + + $response = $this->sellingPartnerSDK->reports()->createReportSchedule( + $this->sellingPartnerSDK->oAuth()->exchangeRefreshToken($this->sellerRefreshToken), + $marketplace->region(), + new CreateReportScheduleSpecification([ + 'report_type' => 'FEE_DISCOUNTS_REPORT', + 'marketplace_ids' => ['A1PA6795UKMFR9', 'ATVPDKIKX0DER'], + 'period' => 'PT5M', + 'next_report_creation_time' => new \DateTime('2019-12-10T20:11:24.000Z'), + ]) + ); + + $this->assertEquals("ID323", $response->getReportScheduleId()); + } } From 559133f3ba34885d0e0b4156a22c0c13e6f45974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Owsiak?= Date: Tue, 19 Jul 2022 17:59:18 +0200 Subject: [PATCH 2/2] added missing tests --- .../Tests/Unit/ObjectSerializerTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/AmazonPHP/SellingPartner/Tests/Unit/ObjectSerializerTest.php b/tests/AmazonPHP/SellingPartner/Tests/Unit/ObjectSerializerTest.php index 645d61362..6d7112e93 100644 --- a/tests/AmazonPHP/SellingPartner/Tests/Unit/ObjectSerializerTest.php +++ b/tests/AmazonPHP/SellingPartner/Tests/Unit/ObjectSerializerTest.php @@ -91,6 +91,34 @@ public function test_serialization_of_object_with_enums(): void ); } + public function test_serialization_of_date_time_objects(): void + { + $this->assertEquals( + '2022-07-19', + ObjectSerializer::sanitizeForSerialization(new \DateTime('2022-07-19 10:15:35'), null, 'date') + ); + + $this->assertEquals( + '2022-07-19T10:15:35.000Z', + ObjectSerializer::sanitizeForSerialization(new \DateTime('2022-07-19 10:15:35')) + ); + + $this->assertEquals( + '2022-07-19T17:15:35.000Z', + ObjectSerializer::sanitizeForSerialization(new \DateTime('2022-07-19 10:15:35', new \DateTimeZone('America/Los_Angeles'))) + ); + + $this->assertEquals( + '2022-07-19T17:15:35.000Z', + ObjectSerializer::toString(new \DateTime('2022-07-19 10:15:35', new \DateTimeZone('America/Los_Angeles'))) + ); + + $this->assertEquals( + '2022-07-19T10:15:35.351Z', + ObjectSerializer::toString(new \DateTime('2022-07-19 10:15:35.351', new \DateTimeZone('UTC'))) + ); + } + public function test_deserialize_label_format_enum_with_an_empty_string(): void { $response = <<