Skip to content

Commit

Permalink
Implement Shop api
Browse files Browse the repository at this point in the history
  • Loading branch information
shimonhaga committed Jun 8, 2023
1 parent d538142 commit 581df0f
Show file tree
Hide file tree
Showing 13 changed files with 661 additions and 12 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ if ($result instanceof Communicator\Errors) {
```

### OAuth
#### 共通準備
#### 認証情報
以下のものをPHPで扱えるようにしておく。
* `クライアントID`
* `クライアントシークレット`
* `リダイレクトURI`

以降のコードサンプルでは、それぞれ `$clientId`, `$clientSecret`, `$redirectUri` として表現する。
OAuth に使う情報をあらかじめ作っておく。

#### OAuth に使う共通情報
```php
$oAuthOptions = new Entities\OAuth\Options($clientId, $clientSecret, $redirectUri);
```
Expand Down Expand Up @@ -118,6 +118,28 @@ if ($tokenOrErrors instanceof Communicator\Errors) {
必要に応じてデータベースなどに、安全な方法で保存する。

### ショップ
#### ショップ情報の取得
```php
// アクセストークンのないインスタンス
$client = new Client;

// インスタンス作成時に引数としてアクセストークンを与えることも可能
$client = new Client($token);

// アクセストークンを設定
$shopOrErrors = $client->getShop($token);
// アクセストークン無し
$shopOrErrors = $client->getShop();

// 結果の処理
if ($shopOrErrors instanceof Communicator\Errors) {
// error...
} else {
// success!
}
```

### 受注
#### 受注データのリストを取得
* 第1引数: 検索条件 (optional)
Expand All @@ -126,8 +148,6 @@ if ($tokenOrErrors instanceof Communicator\Errors) {
検索条件を省略した場合の条件は公式を参照。

```php
$client = new Client;

// 検索条件を省略パターン
$salePageOrErrors = $client->getSales(null, $token);

Expand All @@ -139,7 +159,7 @@ $searchParameters = new Entities\Sales\SearchParameters([
]);
$salePageOrErrors = $client->getSales($searchParameters);

// 両方省略するパターン (インスタンス作成時に引数としてトークンを与える必要がある)
// 両方省略するパターン
$salePageOrErrors = $client->getSales();

// 結果の処理
Expand Down Expand Up @@ -213,12 +233,14 @@ TODO: write
-----

## 未実装
* [ショップ](https://developer.shop-pro.jp/docs/colorme-api#tag/shop)
* [商品](https://developer.shop-pro.jp/docs/colorme-api#tag/product)
* [在庫](https://developer.shop-pro.jp/docs/colorme-api#tag/stock)
* [ギフト](https://developer.shop-pro.jp/docs/colorme-api#tag/gift)
* [ショップクーポン](https://developer.shop-pro.jp/docs/colorme-api#tag/shop_coupon)

## やりたいこと
Client から OAuth を削除する (Services\OAuth をそのまま使えば良い)。

-----

## CLI
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"minimum-stability": "dev",
"prefer-stable": true,
"version": "0.5.1",
"version": "0.6.0",
"license": "MIT",
"authors": [
{
Expand Down
20 changes: 20 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Shimoning\ColorMeShopApi\Entities\OAuth\AccessToken;
use Shimoning\ColorMeShopApi\Values\Scopes;

use Shimoning\ColorMeShopApi\Services\Shop;
use Shimoning\ColorMeShopApi\Entities\Shop\Shop as ShopEntity;

use Shimoning\ColorMeShopApi\Services\Sales;
use Shimoning\ColorMeShopApi\Entities\Sales\Sale;
use Shimoning\ColorMeShopApi\Entities\Sales\SearchParameters as SalesSearchParameters;
Expand Down Expand Up @@ -70,6 +73,23 @@ public function exchangeCode2Token(OAuthOptions $options, string $code): AccessT
return (new OAuth($options))->exchangeCode2Token($code);
}


/**
* ショップ情報の取得
*
* @link https://developer.shop-pro.jp/docs/colorme-api#tag/shop/operation/getShop
* @param string|null $accessToken
* @return ShopEntity|Errors
*/
public function getShop(?string $accessToken = null): ShopEntity|Errors
{
if ($accessToken) {
$this->accessToken = $accessToken;
}

return (new Shop($this->accessToken))->get();
}

/**
* 受注データのリストを取得
*
Expand Down
43 changes: 43 additions & 0 deletions src/Constants/ContractPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum ContractPlan: string
{
case UNKNOWN = 'unknown';

case REGULAR = 'regular';
case LARGE = 'large';
case PREMIUM = 'premium';

case FREE = 'free';
case ECONOMY = 'economy';
case SMALL = 'small';
case PLATINUM = 'platinum';
case DORMANT = 'dormant';

case LOLIPOP = 'lolipop';
case HETEML = 'heteml';
case GOOPE = 'goope';

public function name(): string
{
return match ($this) {
self::UNKNOWN => '不明',

self::REGULAR => 'レギュラー',
self::LARGE => 'ラージ',
self::PREMIUM => 'プレミアム',

self::FREE => '無料プラン',
self::ECONOMY => 'エコノミー',
self::SMALL => 'スモール',
self::PLATINUM => 'プラチナ',
self::DORMANT => '休眠',

self::LOLIPOP => 'ロリポップ',
self::HETEML => 'Heteml',
self::GOOPE => 'GOOPE',
};
}
}
19 changes: 19 additions & 0 deletions src/Constants/DomainPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum DomainPlan: string
{
case COLORME_SHOP_SUB_DOMAIN = 'cmsp_sub_domain';
case OWN_DOMAIN = 'own_domain';
case OWN_SUB_DOMAIN = 'own_sub_domain';

public function name(): string
{
return match ($this) {
self::COLORME_SHOP_SUB_DOMAIN => 'shop-proサブドメイン',
self::OWN_DOMAIN => '独自ドメイン',
self::OWN_SUB_DOMAIN => '独自サブドメイン',
};
}
}
21 changes: 21 additions & 0 deletions src/Constants/OpenStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum OpenStatus: string
{
case OPENED = 'opened';
case CLOSED = 'closed';
case PREPARE = 'prepare';
case PAUSED = 'paused';

public function name(): string
{
return match ($this) {
self::OPENED => '開店',
self::CLOSED => '閉店(工事中)',
self::PREPARE => '準備中',
self::PAUSED => '休止中',
};
}
}
19 changes: 19 additions & 0 deletions src/Constants/ShopState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum ShopState: string
{
case ENABLED = 'enabled';
case SUSPENDED = 'suspended';
case UNSIGNED = 'unsigned';

public function name(): string
{
return match ($this) {
self::ENABLED => '有効',
self::SUSPENDED => '停止',
self::UNSIGNED => '未登録',
};
}
}
19 changes: 19 additions & 0 deletions src/Constants/TaxRoundingMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum TaxRoundingMethod: string
{
case ROUND_OFF = 'round_off';
case ROUND_DOWN = 'round_down';
case ROUND_UP = 'round_up';

public function name(): string
{
return match ($this) {
self::ROUND_OFF => '四捨五入',
self::ROUND_DOWN => '切り捨て',
self::ROUND_UP => '切り上げ',
};
}
}
17 changes: 17 additions & 0 deletions src/Constants/TaxType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum TaxType: string
{
case EXCLUDED = 'excluded';
case INCLUDED = 'included';

public function name(): string
{
return match ($this) {
self::EXCLUDED => '外税',
self::INCLUDED => '内税',
};
}
}
4 changes: 0 additions & 4 deletions src/Entities/Delivery/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Shimoning\ColorMeShopApi\Entities\Delivery;

use Shimoning\ColorMeShopApi\Entities\Entity;
use Shimoning\ColorMeShopApi\Constants\DisplayState;

/**
* 配送料設定の詳細
Expand All @@ -21,9 +20,6 @@ class Charge extends Entity
'array' => true,
'entity' => Area::class,
],
'displayState' => [
'enum' => DisplayState::class,
],
];

protected int $deliveryId;
Expand Down
1 change: 0 additions & 1 deletion src/Entities/Delivery/Delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ public function getDisplayState(): DisplayState
return $this->displayState;
}


/**
* 配送希望日を指定可能か
* @return bool
Expand Down
Loading

0 comments on commit 581df0f

Please sign in to comment.