Skip to content

Commit

Permalink
Add sellers get account
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbrink committed Aug 16, 2024
1 parent 22789b8 commit 1df11e1
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/Data/Responses/Sellers/GetAccountResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Jasara\AmznSPA\Data\Responses\Sellers;

use Jasara\AmznSPA\Data\Responses\BaseResponse;
use Jasara\AmznSPA\Data\Schemas\Sellers\AccountSchema;

class GetAccountResponse extends BaseResponse
{
public function __construct(
public ?AccountSchema $payload,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Jasara\AmznSPA\Data\Responses\Sellers;

use Jasara\AmznSPA\Data\Responses\BaseResponse;
use Jasara\AmznSPA\Data\Schemas\Sellers\MarketplaceParticipationListSchema;
use Jasara\AmznSPA\Data\Schemas\Sellers\MarketplaceParticipationSchemaList;

class GetMarketplaceParticipationsResponse extends BaseResponse
{
public function __construct(
public ?MarketplaceParticipationListSchema $payload,
public ?MarketplaceParticipationSchemaList $payload,
) {
}
}
16 changes: 16 additions & 0 deletions src/Data/Schemas/Sellers/AccountSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class AccountSchema extends BaseSchema
{
public function __construct(
public MarketplaceLevelAttributesSchemaList $marketplace_level_attributes,
public BusinessType $business_type,
public ?BusinessSchema $business,
public ?PrimaryContactSchema $primary_contact,
) {
}
}
17 changes: 17 additions & 0 deletions src/Data/Schemas/Sellers/BusinessSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class BusinessSchema extends BaseSchema
{
public function __construct(
public string $name,
public SellersAddressSchema $registered_business_address,
public ?string $company_registration_number,
public ?string $company_tax_identification_number,
public ?string $non_latin_name,
) {
}
}
15 changes: 15 additions & 0 deletions src/Data/Schemas/Sellers/BusinessType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

enum BusinessType: string
{
case Charity = 'CHARITY';
case Craftsman = 'CRAFTSMAN';
case NaturalPersonCompany = 'NATURAL_PERSON_COMPANY';
case PublicListed = 'PUBLIC_LISTED';
case PrivateLimited = 'PRIVATE_LIMITED';
case SoleProprietorship = 'SOLE_PROPRIETORSHIP';
case StateOwned = 'STATE_OWNED';
case Individual = 'INDIVIDUAL';
}
9 changes: 9 additions & 0 deletions src/Data/Schemas/Sellers/ListingStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

enum ListingStatus: string
{
case Active = 'ACTIVE';
case Inactive = 'INACTIVE';
}
16 changes: 16 additions & 0 deletions src/Data/Schemas/Sellers/MarketplaceLevelAttributesSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class MarketplaceLevelAttributesSchema extends BaseSchema
{
public function __construct(
public MarketplaceSchema $marketplace,
public string $store_name,
public ListingStatus $listing_status,
public SellingPlan $selling_plan,
) {
}
}
13 changes: 13 additions & 0 deletions src/Data/Schemas/Sellers/MarketplaceLevelAttributesSchemaList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

use Jasara\AmznSPA\Data\Base\TypedCollection;

/**
* @template-extends TypedCollection<MarketplaceLevelAttributesSchema>
*/
class MarketplaceLevelAttributesSchemaList extends TypedCollection
{
public const ITEM_CLASS = MarketplaceLevelAttributesSchema::class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @template-extends TypedCollection<MarketplaceParticipationSchema>
*/
class MarketplaceParticipationListSchema extends TypedCollection
class MarketplaceParticipationSchemaList extends TypedCollection
{
public const ITEM_CLASS = MarketplaceParticipationSchema::class;
}
4 changes: 2 additions & 2 deletions src/Data/Schemas/Sellers/MarketplaceSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public function __construct(
public string $id,
public string $name,
public string $country_code,
public string $default_currency_code,
public string $default_language_code,
public ?string $default_currency_code,
public ?string $default_language_code,
public string $domain_name,
) {
}
Expand Down
15 changes: 15 additions & 0 deletions src/Data/Schemas/Sellers/PrimaryContactSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

use Jasara\AmznSPA\Data\Schemas\BaseSchema;

class PrimaryContactSchema extends BaseSchema
{
public function __construct(
public string $name,
public SellersAddressSchema $address,
public ?string $non_latin_name,
) {
}
}
20 changes: 20 additions & 0 deletions src/Data/Schemas/Sellers/SellersAddressSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

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

class SellersAddressSchema extends BaseSchema
{
public function __construct(
public string $address_line_1,
public ?string $address_line_2,
public ?string $city,
public ?string $state_or_province_code,
#[MaxLengthValidator(2)]
public string $country_code,
public string $postal_code,
) {
}
}
9 changes: 9 additions & 0 deletions src/Data/Schemas/Sellers/SellingPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Jasara\AmznSPA\Data\Schemas\Sellers;

enum SellingPlan: string
{
case Professional = 'PROFESSIONAL';
case Individual = 'INDIVIDUAL';
}
14 changes: 12 additions & 2 deletions src/Resources/SellersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Jasara\AmznSPA\AmznSPAHttp;
use Jasara\AmznSPA\Contracts\ResourceContract;
use Jasara\AmznSPA\Data\Responses\Sellers\GetAccountResponse;
use Jasara\AmznSPA\Data\Responses\Sellers\GetMarketplaceParticipationsResponse;
use Jasara\AmznSPA\Traits\ValidatesParameters;

class SellersResource implements ResourceContract
{
use ValidatesParameters;
public const BASE_PATH = '/sellers/v1/marketplaceParticipations';
public const BASE_PATH = '/sellers/v1/';

public function __construct(
private AmznSPAHttp $http,
Expand All @@ -22,7 +23,16 @@ public function getMarketplaceParticipations(): GetMarketplaceParticipationsResp
{
$response = $this->http
->responseClass(GetMarketplaceParticipationsResponse::class)
->get($this->endpoint . self::BASE_PATH);
->get($this->endpoint . self::BASE_PATH . 'marketplaceParticipations');

return $response;
}

public function getAccount(): GetAccountResponse
{
$response = $this->http
->responseClass(GetAccountResponse::class)
->get($this->endpoint . self::BASE_PATH . 'account');

return $response;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Resources/SellersResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Client\Request;
use Jasara\AmznSPA\AmznSPA;
use Jasara\AmznSPA\Data\Responses\Sellers\GetAccountResponse;
use Jasara\AmznSPA\Data\Responses\Sellers\GetMarketplaceParticipationsResponse;
use Jasara\AmznSPA\Tests\Unit\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
Expand All @@ -28,4 +29,22 @@ public function testGetMarketplaceParticipations()
return true;
});
}

public function testGetAccount()
{
list($config, $http) = $this->setupConfigWithFakeHttp('sellers/get-account');

$amzn = new AmznSPA($config);
$amzn = $amzn->usingMarketplace('ATVPDKIKX0DER');
$response = $amzn->sellers->getAccount();

$this->assertInstanceOf(GetAccountResponse::class, $response);

$http->assertSent(function (Request $request) {
$this->assertEquals('GET', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/sellers/v1/account', $request->url());

return true;
});
}
}
43 changes: 43 additions & 0 deletions tests/stubs/sellers/get-account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"payload": {
"businessType": "PRIVATE_LIMITED",
"marketplaceLevelAttributes": [
{
"marketplace": {
"id": "ATVPDKIKX0DER",
"name": "United States",
"countryCode": "US",
"domainName": "www.amazon.com"
},
"storeName": "BestSellerStore",
"listingStatus": "ACTIVE",
"sellingPlan": "PROFESSIONAL"
}
],
"business": {
"name": "BestSeller Inc.",
"nonLatinName": "ベストセラー株式会社",
"registeredBusinessAddress": {
"addressLine1": "123 Main St",
"addressLine2": "Suite 500",
"city": "Seattle",
"stateOrProvinceCode": "WA",
"postalCode": "98101",
"countryCode": "US"
},
"companyRegistrationNumber": "123456789"
},
"primaryContact": {
"name": "John Doe",
"nonLatinName": "ジョン・ドゥ",
"address": {
"addressLine1": "456 Oak St",
"addressLine2": "Apt 12",
"city": "Seattle",
"stateOrProvinceCode": "WA",
"postalCode": "98102",
"countryCode": "US"
}
}
}
}

0 comments on commit 1df11e1

Please sign in to comment.