Skip to content

Commit

Permalink
Fix address schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbrink committed Aug 9, 2024
1 parent 2977586 commit 22789b8
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Base\Validators\StringEnumValidator;
use Jasara\AmznSPA\Data\Requests\BaseRequest;
use Jasara\AmznSPA\Data\Schemas\AddressSchema;
use Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound\CODSettingsSchema;
use Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound\CreateFulfillmentOrderItemListSchema;
use Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound\DeliveryWindowSchema;
use Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound\FeatureSettingListSchema;
use Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound\FulfillmentOutboundAddressSchema;

class CreateFulfillmentOrderRequest extends BaseRequest
{
Expand All @@ -22,7 +22,7 @@ public function __construct(
public string $displayable_order_comment,
#[StringEnumValidator(['Standard', 'Expedited', 'Priority', 'ScheduledDelivery'])]
public string $shipping_speed_category,
public AddressSchema $destination_address,
public FulfillmentOutboundAddressSchema $destination_address,
public CreateFulfillmentOrderItemListSchema $items,
public ?DeliveryWindowSchema $delivery_window = null,
#[StringEnumValidator(['Ship', 'Hold'])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Jasara\AmznSPA\Data\Requests\MerchantFulfillment;

use Jasara\AmznSPA\Data\Requests\BaseRequest;
use Jasara\AmznSPA\Data\Schemas\AddressSchema;
use Jasara\AmznSPA\Data\Schemas\MerchantFulfillment\MerchantFulfillmentAddressSchema;

class GetAdditionalSellerInputsRequest extends BaseRequest
{
public function __construct(
public string $shipping_service_id,
public AddressSchema $ship_from_address,
public MerchantFulfillmentAddressSchema $ship_from_address,
public string $order_id,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Schemas/AddressSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
public string $postal_code,
public ?string $email,
#[MaxLengthValidator(30)]
public ?string $phone,
public ?string $phone_number,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

namespace Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320;

use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Base\Validators\RuleValidator;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class BoxContentSchema extends BaseSchema
{
public function __construct(
#[RuleValidator(['date_format:Y-m-d'])]
public ?string $expiration,
#[CarbonFromStringCaster]
public ?CarbonImmutable $expiration,
public LabelOwner $label_owner,
#[RuleValidator(['min:1', 'max:256'])]
public ?string $manufacturing_lot_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

namespace Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320;

use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Base\Validators\RuleValidator;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class ItemInputSchema extends BaseSchema
{
public function __construct(
#[RuleValidator(['date_format:Y-m-d'])]
public ?string $expiration,
#[CarbonFromStringCaster]
public ?CarbonImmutable $expiration,
public LabelOwner $label_owner,
#[RuleValidator(['min:1', 'max:256'])]
public ?string $manufacturing_lot_code,
Expand Down
6 changes: 4 additions & 2 deletions src/Data/Schemas/FulfillmentInbound/v20240320/ItemSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320;

use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Base\Validators\RuleValidator;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;

Expand All @@ -10,8 +12,8 @@ class ItemSchema extends BaseSchema
public function __construct(
#[RuleValidator(['min:1', 'max:10'])]
public string $asin,
#[RuleValidator(['date_format:Y-m-d'])]
public ?string $expiration,
#[CarbonFromStringCaster]
public ?CarbonImmutable $expiration,
#[RuleValidator(['min:1', 'max:10'])]
public string $fnsku,
public LabelOwner $label_owner,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound;

use Jasara\AmznSPA\Data\Base\Validators\MaxLengthValidator;
use Jasara\AmznSPA\Data\Base\Validators\RuleValidator;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class FulfillmentOutboundAddressSchema extends BaseSchema
{
public function __construct(
#[RuleValidator(['max:30'])]
public string $name,
#[MaxLengthValidator(180)]
public string $address_line_1,
#[MaxLengthValidator(60)]
public ?string $address_line_2,
#[MaxLengthValidator(60)]
public ?string $address_line_3,
public ?string $district_or_county,
#[MaxLengthValidator(30)]
public ?string $city,
#[MaxLengthValidator(30)]
public ?string $state_or_region,
#[MaxLengthValidator(2)]
public string $country_code,
#[MaxLengthValidator(30)]
public string $postal_code,
#[MaxLengthValidator(30)]
public ?string $phone,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Schemas\AddressSchema;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;
use Jasara\AmznSPA\Data\Schemas\MoneySchema;
use Jasara\AmznSPA\Data\Schemas\WeightSchema;
Expand All @@ -18,7 +17,7 @@ public function __construct(
public ?int $value_as_integer,
#[CarbonFromStringCaster]
public ?CarbonImmutable $value_as_timestamp,
public ?AddressSchema $value_as_address,
public ?MerchantFulfillmentAddressSchema $value_as_address,
public ?WeightSchema $value_as_weight,
public ?PackageDimensionsSchema $value_as_dimension,
public ?MoneySchema $value_as_currency,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\MerchantFulfillment;

use Jasara\AmznSPA\Data\Base\Validators\MaxLengthValidator;
use Jasara\AmznSPA\Data\Base\Validators\RuleValidator;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class MerchantFulfillmentAddressSchema extends BaseSchema
{
public function __construct(
#[RuleValidator(['max:30'])]
public string $name,
#[MaxLengthValidator(180)]
public string $address_line_1,
#[MaxLengthValidator(60)]
public ?string $address_line_2,
#[MaxLengthValidator(60)]
public ?string $address_line_3,
public ?string $district_or_county,
#[MaxLengthValidator(30)]
public ?string $city,
#[MaxLengthValidator(30)]
public ?string $state_or_province_code,
#[MaxLengthValidator(2)]
public string $country_code,
#[MaxLengthValidator(30)]
public string $postal_code,
public ?string $email,
#[MaxLengthValidator(30)]
public ?string $phone,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Schemas\AddressSchema;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;
use Jasara\AmznSPA\Data\Schemas\CatalogItems\v20201201\ItemListSchema;
use Jasara\AmznSPA\Data\Schemas\WeightSchema;
Expand All @@ -15,7 +14,7 @@ public function __construct(
public string $amazon_order_id,
public ?string $seller_order_id,
public ItemListSchema $item_list,
public AddressSchema $ship_from_address,
public MerchantFulfillmentAddressSchema $ship_from_address,
public PackageDimensionsSchema $package_dimensions,
public WeightSchema $weight,
#[CarbonFromStringCaster]
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Schemas/MerchantFulfillment/ShipmentSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Casts\CarbonFromStringCaster;
use Jasara\AmznSPA\Data\Base\Validators\StringEnumValidator;
use Jasara\AmznSPA\Data\Schemas\AddressSchema;
use Jasara\AmznSPA\Data\Schemas\BaseSchema;
use Jasara\AmznSPA\Data\Schemas\MoneySchema;
use Jasara\AmznSPA\Data\Schemas\WeightSchema;
Expand All @@ -17,8 +16,8 @@ public function __construct(
public string $amazon_order_id,
public ?string $seller_order_id,
public ItemListSchema $item_list,
public AddressSchema $ship_from_address,
public AddressSchema $ship_to_address,
public MerchantFulfillmentAddressSchema $ship_from_address,
public MerchantFulfillmentAddressSchema $ship_to_address,
public PackageDimensionsSchema $package_dimensions,
public WeightSchema $weight,
public MoneySchema $insurance,
Expand Down
6 changes: 5 additions & 1 deletion tests/Setup/SetupMerchantFulfillmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace Jasara\AmznSPA\Tests\Setup;

use Illuminate\Support\Str;
use Jasara\AmznSPA\Data\Schemas\MerchantFulfillment\MerchantFulfillmentAddressSchema;
use Jasara\AmznSPA\Data\Schemas\MerchantFulfillment\ShipmentRequestDetailsSchema;

trait SetupMerchantFulfillmentRequest
{
public function shipmentRequestDetails(): ShipmentRequestDetailsSchema
{
$setup_address = $this->setupAddress();
$address = MerchantFulfillmentAddressSchema::from($setup_address->toArray());

return ShipmentRequestDetailsSchema::from(
amazon_order_id: '52986411826454',
item_list: [
Expand All @@ -18,7 +22,7 @@ public function shipmentRequestDetails(): ShipmentRequestDetailsSchema
'quantity' => rand(1, 10),
],
],
ship_from_address: $this->setupAddress(),
ship_from_address: $address,
package_dimensions: [
'length' => 88,
],
Expand Down
8 changes: 7 additions & 1 deletion tests/Unit/Resources/FulfillmentOutboundResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Jasara\AmznSPA\Data\Responses\FulfillmentOutbound\ListAllFulfillmentOrdersResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentOutbound\ListReturnReasonCodesResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentOutbound\UpdateFulfillmentOrderResponse;
use Jasara\AmznSPA\Data\Schemas\FulfillmentOutbound\FulfillmentOutboundAddressSchema;
use Jasara\AmznSPA\Tests\Unit\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

Expand Down Expand Up @@ -89,14 +90,19 @@ public function testCreateFulfillmentOrder()
{
list($config, $http) = $this->setupConfigWithFakeHttp('empty');

$setup_address = $this->setupAddress();
$address = FulfillmentOutboundAddressSchema::from(array_merge($setup_address->toArray(), [
'state_or_region' => $setup_address->state_or_province_code,
]));

$request = CreateFulfillmentOrderRequest::from(
marketplace_id: 'ATVPDKIKX0DER',
seller_fulfillment_order_id: Str::random(),
displayable_order_id: Str::random(),
displayable_order_date: CarbonImmutable::now(),
displayable_order_comment: Str::random(),
shipping_speed_category: 'Expedited',
destination_address: $this->setupAddress(),
destination_address: $address,
fulfillment_action: 'Hold',
fulfillment_policy: 'fulfillment_policy',
cod_settings: [
Expand Down
11 changes: 6 additions & 5 deletions tests/Unit/Resources/MerchantFulfillmentResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Jasara\AmznSPA\Data\Responses\MerchantFulfillment\GetAdditionalSellerInputsResponse;
use Jasara\AmznSPA\Data\Responses\MerchantFulfillment\GetEligibleShipmentServicesResponse;
use Jasara\AmznSPA\Data\Responses\MerchantFulfillment\GetShipmentResponse;
use Jasara\AmznSPA\Data\Schemas\MerchantFulfillment\MerchantFulfillmentAddressSchema;
use Jasara\AmznSPA\Tests\Setup\SetupMerchantFulfillmentRequest;
use Jasara\AmznSPA\Tests\Unit\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
Expand Down Expand Up @@ -90,7 +91,7 @@ function (Request $request) {
},
function (Request $request) use ($shipment_id) {
$this->assertEquals('GET', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/mfn/v0/shipments/'.$shipment_id, $request->url());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/mfn/v0/shipments/' . $shipment_id, $request->url());

return true;
},
Expand All @@ -114,7 +115,7 @@ public function testCancelShipment()

$http->assertSent(function (Request $request) use ($shipment_id) {
$this->assertEquals('DELETE', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/mfn/v0/shipments/'.$shipment_id, $request->url());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/mfn/v0/shipments/' . $shipment_id, $request->url());

return true;
});
Expand All @@ -135,7 +136,7 @@ public function testCancelShipmentOld()

$http->assertSent(function (Request $request) use ($shipment_id) {
$this->assertEquals('PUT', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/mfn/v0/shipments/'.$shipment_id.'/cancel', $request->url());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/mfn/v0/shipments/' . $shipment_id . '/cancel', $request->url());

return true;
});
Expand Down Expand Up @@ -169,7 +170,7 @@ public function testGetAdditionalSellerInputsOld()
list($config, $http) = $this->setupConfigWithFakeHttp('merchant-fulfillment/get-additional-seller-inputs-old');
$request = new GetAdditionalSellerInputsRequest(
shipping_service_id: Str::random(),
ship_from_address: $this->setupAddress(),
ship_from_address: MerchantFulfillmentAddressSchema::from($this->setupAddress()->toArray()),
order_id: Str::random()
);

Expand All @@ -193,7 +194,7 @@ public function testGetAdditionalSellerInputs()
list($config, $http) = $this->setupConfigWithFakeHttp('merchant-fulfillment/get-additional-seller-inputs-old');
$request = new GetAdditionalSellerInputsRequest(
shipping_service_id: Str::random(),
ship_from_address: $this->setupAddress(),
ship_from_address: MerchantFulfillmentAddressSchema::from($this->setupAddress()->toArray()),
order_id: Str::random()
);

Expand Down

0 comments on commit 22789b8

Please sign in to comment.