Skip to content

Commit

Permalink
Add prep details endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbrink committed Nov 14, 2024
1 parent ef74368 commit 504b9c0
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Data/Base/ToArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jasara\AmznSPA\Data\Base;

use BackedEnum;
use Carbon\CarbonImmutable;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -50,8 +51,10 @@ private function mapPropertyValue(
return match (true) {
$has_mapper => $this->mapWithMapper($property, $value),
$value instanceof Data => $this->mapWithData($case, $value),
$value instanceof TypedCollection => $value->toArrayObject(),
$value instanceof Collection => $this->mapWithCollection($case, $value),
$value instanceof CarbonImmutable => $this->mapWithCarbonImmutable($value),
$value instanceof BackedEnum => $value->value,
default => $value,
};
}
Expand Down
14 changes: 14 additions & 0 deletions src/Data/Base/TypedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jasara\AmznSPA\Data\Base;

use BackedEnum;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

Expand Down Expand Up @@ -54,4 +55,17 @@ public function reduce(callable $callback, $initial = null)
{
return $this->toBase()->reduce($callback, $initial);
}

public function toArrayObject(): \ArrayObject
{
return new \ArrayObject($this->map(function ($item) {
return match (true) {
$item instanceof TypedCollection => $item->toArrayObject(),
$item instanceof Collection => $item->toArrayObject(),
$item instanceof Data => $item->toArrayObject(),
$item instanceof BackedEnum => $item->value,
default => $item,
};
})->toArray());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

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

use Jasara\AmznSPA\Data\Responses\BaseResponse;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\MskuPrepDetailSchemaList;

class ListPrepDetailsResponse extends BaseResponse
{
public function __construct(
public MskuPrepDetailSchemaList $msku_prep_details,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

use Jasara\AmznSPA\Data\Base\Validators\RuleValidator;
use Jasara\AmznSPA\Data\Responses\BaseResponse;

class SetPrepDetailsResponse extends BaseResponse
{
public function __construct(
#[RuleValidator(['min:36', 'max:38'])]
public ?string $operation_id,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

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

enum AllOwnersConstraint: string
{
case MustMatch = 'MUST_MATCH';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class MskuPrepDetailInputSchema extends BaseSchema
{
public function __construct(
public string $msku,
public PrepCategory $prep_category,
public PrepTypeList $prep_types,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Jasara\AmznSPA\Data\Base\TypedCollection;

/**
* @template-extends TypedCollection<MskuPrepDetailInputSchema>
*/
class MskuPrepDetailInputSchemaList extends TypedCollection
{
public const ITEM_CLASS = MskuPrepDetailInputSchema::class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

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

use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class MskuPrepDetailSchema extends BaseSchema
{
public function __construct(
public ?AllOwnersConstraint $all_owners_constraint,
public ?OwnerConstraint $label_owner_constraint,
public string $msku,
public PrepCategory $prep_category,
public PrepTypeList $prep_types,
public ?OwnerConstraint $prep_owner_constraint,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Jasara\AmznSPA\Data\Base\TypedCollection;

/**
* @template-extends TypedCollection<MskuPrepDetailSchema>
*/
class MskuPrepDetailSchemaList extends TypedCollection
{
public const ITEM_CLASS = MskuPrepDetailSchema::class;
}
10 changes: 10 additions & 0 deletions src/Data/Schemas/FulfillmentInbound/v20240320/OwnerConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

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

enum OwnerConstraint: string
{
case AmazonOnly = 'AMAZON_ONLY';
case SellerOnly = 'SELLER_ONLY';
case NoneOnly = 'NONE_ONLY';
}
21 changes: 21 additions & 0 deletions src/Data/Schemas/FulfillmentInbound/v20240320/PrepCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

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

enum PrepCategory: string
{
case Adult = 'ADULT';
case Baby = 'BABY';
case FcProvided = 'FC_PROVIDED';
case Fragile = 'FRAGILE';
case Granular = 'GRANULAR';
case Hanger = 'HANGER';
case Liquid = 'LIQUID';
case Perforated = 'PERFORATED';
case Set = 'SET';
case Sharp = 'SHARP';
case Small = 'SMALL';
case Textile = 'TEXTILE';
case Unknown = 'UNKNOWN';
case None = 'NONE';
}
13 changes: 13 additions & 0 deletions src/Data/Schemas/FulfillmentInbound/v20240320/PrepTypeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Jasara\AmznSPA\Data\Base\TypedCollection;

/**
* @template-extends TypedCollection<PrepType>
*/
class PrepTypeList extends TypedCollection
{
public const ITEM_CLASS = PrepType::class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPackingGroupItemsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPackingOptionsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPlacementOptionsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPrepDetailsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentBoxesResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentContentUpdatePreviewsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentItemsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentPalletsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListTransportationOptionsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ScheduleSelfShipAppointmentResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\SetPackingInformationResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\SetPrepDetailsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateItemComplianceDetailsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateShipmentDeliveryWindowResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateShipmentSourceAddressResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateShipmentTrackingDetailsResponse;
use Jasara\AmznSPA\Data\Schemas\Common\SortOrder;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\InboundPlanStatus;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\MskuPrepDetailInputSchemaList;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\SortBy;
use Jasara\AmznSPA\Traits\ValidatesParameters;

Expand Down Expand Up @@ -525,7 +528,7 @@ public function listPackingGroupItems(
->responseClass(ListPackingGroupItemsResponse::class)
->get(
$this->endpoint . self::BASE_PATH . 'inboundPlans/' . $inbound_plan_id
. '/packingGroups/' . $packing_group_id
. '/packingGroups/' . $packing_group_id
. '/items',
array_filter([
'pageSize' => $page_size,
Expand Down Expand Up @@ -861,4 +864,37 @@ public function getInboundOperationStatus(

return $response;
}

public function listPrepDetails(
string $marketplace_id,
#[RuleValidator(['min:1', 'max:100'])]
array $mskus,
): ListPrepDetailsResponse {
$this->validateAttributes(__FUNCTION__, ...func_get_args());

$response = $this->http
->responseClass(ListPrepDetailsResponse::class)
->get($this->endpoint . self::BASE_PATH . 'prepDetails', [
'marketplaceId' => $marketplace_id,
'mskus' => $mskus,
]);

return $response;
}

public function setPrepDetails(
string $marketplace_id,
MskuPrepDetailInputSchemaList $msku_prep_details,
): SetPrepDetailsResponse {
$this->validateAttributes(__FUNCTION__, ...func_get_args());

$response = $this->http
->responseClass(SetPrepDetailsResponse::class)
->post($this->endpoint . self::BASE_PATH . 'items/prepDetails', [
'marketplaceId' => $marketplace_id,
'mskuPrepDetails' => $msku_prep_details->toArrayObject(),
]);

return $response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,24 @@
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPackingGroupItemsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPackingOptionsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPlacementOptionsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListPrepDetailsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentBoxesResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentContentUpdatePreviewsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentItemsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListShipmentPalletsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ListTransportationOptionsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\ScheduleSelfShipAppointmentResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\SetPackingInformationResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\SetPrepDetailsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateItemComplianceDetailsResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateShipmentDeliveryWindowResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateShipmentSourceAddressResponse;
use Jasara\AmznSPA\Data\Responses\FulfillmentInbound\v20240320\UpdateShipmentTrackingDetailsResponse;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\MskuPrepDetailInputSchema;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\MskuPrepDetailInputSchemaList;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\PrepCategory;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\PrepType;
use Jasara\AmznSPA\Data\Schemas\FulfillmentInbound\v20240320\PrepTypeList;
use Jasara\AmznSPA\Resources\FulfillmentInbound\FulfillmentInbound20240320Resource;
use Jasara\AmznSPA\Tests\Unit\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
Expand Down Expand Up @@ -1087,4 +1094,64 @@ public function testCreateMarketplaceItemLabels(): void
return true;
});
}

public function testListPrepDetails(): void
{
[$config, $http] = $this->setupConfigWithFakeHttp('fulfillment-inbound/v20240320/list-prep-details');

$mskus = ['msku1', 'msku2'];

$amzn = new AmznSPA($config);
$amzn = $amzn->usingMarketplace('ATVPDKIKX0DER');
$response = $amzn->fulfillment_inbound20240320->listPrepDetails(
marketplace_id: 'ATVPDKIKX0DER',
mskus: $mskus,
);

$this->assertInstanceOf(ListPrepDetailsResponse::class, $response);
$this->assertEquals('msku1', $response->msku_prep_details[0]->msku);

$http->assertSent(function (Request $request) use ($mskus) {
$this->assertEquals('GET', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/inbound/fba/2024-03-20/prepDetails?marketplaceId=ATVPDKIKX0DER&mskus=msku1,msku2', urldecode($request->url()));

return true;
});
}

public function testSetPrepDetails(): void
{
[$config, $http] = $this->setupConfigWithFakeHttp('fulfillment-inbound/v20240320/set-prep-details');

$msku_prep_details = MskuPrepDetailInputSchemaList::make([
new MskuPrepDetailInputSchema(
msku: 'msku1',
prep_category: PrepCategory::Sharp,
prep_types: PrepTypeList::make([
PrepType::Sharp,
]),
),
]);

$amzn = new AmznSPA($config);
$amzn = $amzn->usingMarketplace('ATVPDKIKX0DER');
$response = $amzn->fulfillment_inbound20240320->setPrepDetails(
marketplace_id: 'ATVPDKIKX0DER',
msku_prep_details: $msku_prep_details,
);

$this->assertInstanceOf(SetPrepDetailsResponse::class, $response);
$this->assertEquals('1234abcd-1234-abcd-5678-1234abcd1102', $response->operation_id);

$http->assertSent(function (Request $request) use ($msku_prep_details) {
$this->assertEquals('POST', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/inbound/fba/2024-03-20/items/prepDetails', (string) $request->url());
$this->assertEquals('ATVPDKIKX0DER', $request->data()['marketplaceId']);
ray($request->data());
$this->assertEquals('SHARP', $request->data()['mskuPrepDetails'][0]['prepCategory']);
$this->assertEquals('SHARP', $request->data()['mskuPrepDetails'][0]['prepTypes'][0]);

return true;
});
}
}
24 changes: 24 additions & 0 deletions tests/stubs/fulfillment-inbound/v20240320/list-prep-details.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"mskuPrepDetails": [
{
"msku": "msku1",
"prepCategory": "TEXTILE",
"prepTypes": [
"ITEM_LABELING",
"ITEM_POLYBAGGING"
],
"prepOwnerConstraint": "AMAZON_ONLY",
"labelOwnerConstraint": "AMAZON_ONLY",
"allOwnersConstraint": "MUST_MATCH"
},
{
"msku": "msku2",
"prepCategory": "FRAGILE",
"prepTypes": [
"ITEM_LABELING",
"ITEM_BUBBLEWRAP"
],
"allOwnersConstraint": "MUST_MATCH"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"operationId": "1234abcd-1234-abcd-5678-1234abcd1102"
}

0 comments on commit 504b9c0

Please sign in to comment.