Skip to content

Commit

Permalink
Implement delivery list
Browse files Browse the repository at this point in the history
  • Loading branch information
shimonhaga committed Jan 26, 2023
1 parent 6c489da commit 05a9206
Show file tree
Hide file tree
Showing 13 changed files with 582 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,21 @@ TODO: write
#### 決済設定の一覧を取得
TODO: write

### 配送
#### 配送方法一覧を取得
TODO: write

### 配送日時設定を取得
TODO: write


### 未実装
* ショップ
* 顧客
* 商品
* 在庫
* 商品グループ
* 商品カテゴリー
* 配送
* ギフト
* ショップクーポン

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.2.1",
"version": "0.3.0",
"license": "MIT",
"authors": [
{
Expand Down
21 changes: 21 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use Shimoning\ColorMeShopApi\Services\Payment;
use Shimoning\ColorMeShopApi\Entities\Payment\Payment as PaymentEntity;

use Shimoning\ColorMeShopApi\Services\Delivery;
use Shimoning\ColorMeShopApi\Entities\Delivery\Delivery as DeliveryEntity;

class Client
{
protected string $accessToken;
Expand Down Expand Up @@ -172,4 +175,22 @@ public function getPayments(?string $accessToken = null): Collection|Errors

return (new Payment($this->accessToken))->all();
}

/**
* 配送方法一覧を取得
*
* @link https://developer.shop-pro.jp/docs/colorme-api#tag/delivery/operation/getDeliveries
* @return Collection<DeliveryEntity>|Errors
*/
public function getDeliveries(?string $accessToken = null): Collection|Errors
{
if ($accessToken) {
$this->accessToken = $accessToken;
}
if (empty($this->accessToken)) {
throw new ParameterException('アクセストークンは必ず指定してください');
}

return (new Delivery($this->accessToken))->all();
}
}
10 changes: 10 additions & 0 deletions src/Constants/DeliveryChargeFreeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum DeliveryChargeFreeType: string
{
case NOT_FREE = 'not_free'; // 有料
case FREE = 'free'; // 無料
case FREE_TO_LIMIT = 'free_to_limit'; // 注文金額が一定以上の場合は無料
}
11 changes: 11 additions & 0 deletions src/Constants/DeliveryChargeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum DeliveryChargeType: string
{
case FIXED = 'fixed'; // 固定額
case BY_PRICE = 'by_price'; // 注文金額によって決定
case BY_AREA = 'by_area'; // 配送先都道府県によって決定
case BY_WEIGHT = 'by_weight'; // 商品重量によって決定
}
12 changes: 12 additions & 0 deletions src/Constants/DeliveryMethodType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum DeliveryMethodType: string
{
case OTHER = 'other'; // そのほか
case YAMATO = 'yamato'; // クロネコヤマト
case YAMATO_PICKUP = 'yamato_pickup'; // ヤマト自宅外受け取り
case SAGAWA = 'sagawa'; // 佐川急便
case JP = 'jp'; // 日本郵便
}
9 changes: 9 additions & 0 deletions src/Constants/DisplayState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Shimoning\ColorMeShopApi\Constants;

enum DisplayState: string
{
case SHOWING = 'showing';
case HIDDEN = 'hidden';
}
2 changes: 1 addition & 1 deletion src/Constants/KouzaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
enum KouzaType: string
{
case SAVING = 'saving'; // 普通
case SAVING = 'checking'; // 当座
case CHECKING = 'checking'; // 当座
}
51 changes: 51 additions & 0 deletions src/Entities/Delivery/Area.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Shimoning\ColorMeShopApi\Entities\Delivery;

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

/**
* 都道府県ごとの送料設定
*
* @link https://developer.shop-pro.jp/docs/colorme-api#tag/delivery/operation/getDeliveries
*/
class Area extends Entity
{
public const OBJECT_FIELDS = [
'prefId'=> [
'enum' => Prefecture::class,
],
];

protected Prefecture $prefId;
protected string $prefName;
protected int $charge;

/**
* 都道府県の通し番号
* @return Prefecture
*/
public function getPrefId(): Prefecture
{
return $this->prefId;
}

/**
* 都道府県名
* @return string
*/
public function getPrefName(): string
{
return $this->prefName;
}

/**
* 配送料
* @return int
*/
public function getCharge(): int
{
return $this->charge;
}
}
126 changes: 126 additions & 0 deletions src/Entities/Delivery/Charge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace Shimoning\ColorMeShopApi\Entities\Delivery;

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

/**
* 配送料設定の詳細
*
* @link https://developer.shop-pro.jp/docs/colorme-api#tag/delivery/operation/getDeliveries
*/
class Charge extends Entity
{
public const OBJECT_FIELDS = [
'chargeRangesByArea' => [
'array' => true,
'entity' => Area::class,
],
'chargeRangesMaxWeight' => [
'array' => true,
'entity' => Area::class,
],
'displayState' => [
'enum' => DisplayState::class,
],
];

protected int $deliveryId;
protected string $accountId;

protected ?int $chargeFixed;
protected array $chargeRangesByPrice;
protected ?int $chargeMaxPrice;

protected array $chargeRangesByArea;
protected array $chargeRangesByWeight;
protected array $chargeRangesMaxWeight;

public function __construct(array $data)
{
parent::__construct($data);

// chargeRangesByWeight
$this->chargeRangesByWeight = [];
foreach ($data['charge_ranges_by_weight'] ?? [] as $weight) {
$this->chargeRangesByWeight[] = new Weight([
'weight' => $weight[0],
'areas' => $weight[1],
]);
}
}

/**
* 決済方法ID
* @return int
*/
public function getDeliveryId(): int
{
return $this->deliveryId;
}

/**
* ショップアカウントID
* @return string
*/
public function getAccountId(): string
{
return $this->accountId;
}

/**
* 配送料が固定の場合の金額
* @return int|null
*/
public function getChargeFixed(): ?int
{
return $this->chargeFixed;
}

/**
* 配送料が変わる決済金額の区分
* [3000, 100]であれば、3000円以下の場合、手数料は100円であることを表す
* @return array<int, int>
*/
public function getChargeRangesByPrice(): array
{
return $this->chargeRangesByPrice;
}

/**
* charge_ranges_by_priceに設定されている区分以上の金額の場合の手数料
* @return int|null
*/
public function getChargeMaxPrice(): ?int
{
return $this->chargeMaxPrice;
}

/**
* 都道府県ごとの配送料
* @return array<Area>
*/
public function getChargeRangesByArea(): array
{
return $this->chargeRangesByArea;
}

/**
* 配送料が変わる重量の区分
* @return array<Weight>
*/
public function getChargeRangesByWeight(): array
{
return $this->chargeRangesByWeight;
}

/**
* charge_ranges_by_weightに設定されている区分以上の重量の場合の手数料
* @return array<Area>
*/
public function getChargeRangesMaxWeight(): array
{
return $this->chargeRangesMaxWeight;
}
}
Loading

0 comments on commit 05a9206

Please sign in to comment.