diff --git a/README.md b/README.md index ef8b1c2..9a341c1 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,14 @@ TODO: write #### 決済設定の一覧を取得 TODO: write +### 配送 +#### 配送方法一覧を取得 +TODO: write + +### 配送日時設定を取得 +TODO: write + + ### 未実装 * ショップ * 顧客 @@ -168,7 +176,6 @@ TODO: write * 在庫 * 商品グループ * 商品カテゴリー -* 配送 * ギフト * ショップクーポン diff --git a/composer.json b/composer.json index f2d2506..d5fe32e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "minimum-stability": "dev", "prefer-stable": true, - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "authors": [ { diff --git a/src/Client.php b/src/Client.php index 65c7bca..19ca1a0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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; @@ -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|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(); + } } diff --git a/src/Constants/DeliveryChargeFreeType.php b/src/Constants/DeliveryChargeFreeType.php new file mode 100644 index 0000000..f6a0d2c --- /dev/null +++ b/src/Constants/DeliveryChargeFreeType.php @@ -0,0 +1,10 @@ + [ + '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; + } +} diff --git a/src/Entities/Delivery/Charge.php b/src/Entities/Delivery/Charge.php new file mode 100644 index 0000000..bcfea4e --- /dev/null +++ b/src/Entities/Delivery/Charge.php @@ -0,0 +1,126 @@ + [ + '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 + */ + public function getChargeRangesByPrice(): array + { + return $this->chargeRangesByPrice; + } + + /** + * charge_ranges_by_priceに設定されている区分以上の金額の場合の手数料 + * @return int|null + */ + public function getChargeMaxPrice(): ?int + { + return $this->chargeMaxPrice; + } + + /** + * 都道府県ごとの配送料 + * @return array + */ + public function getChargeRangesByArea(): array + { + return $this->chargeRangesByArea; + } + + /** + * 配送料が変わる重量の区分 + * @return array + */ + public function getChargeRangesByWeight(): array + { + return $this->chargeRangesByWeight; + } + + /** + * charge_ranges_by_weightに設定されている区分以上の重量の場合の手数料 + * @return array + */ + public function getChargeRangesMaxWeight(): array + { + return $this->chargeRangesMaxWeight; + } +} diff --git a/src/Entities/Delivery/Delivery.php b/src/Entities/Delivery/Delivery.php new file mode 100644 index 0000000..b3949ed --- /dev/null +++ b/src/Entities/Delivery/Delivery.php @@ -0,0 +1,253 @@ + [ + 'enum' => DeliveryMethodType::class, + ], + 'chargeFreeType'=> [ + 'enum' => DeliveryChargeFreeType::class, + ], + 'chargeType'=> [ + 'enum' => DeliveryChargeType::class, + ], + 'displayState'=> [ + 'enum' => DisplayState::class, + ], + 'charge'=> [ + 'entity' => Charge::class, + ], + ]; + + protected int $id; + protected string $accountId; + + protected string $name; + + protected DeliveryMethodType $methodType; + protected ?string $imageUrl; + + protected DeliveryChargeFreeType $chargeFreeType; + protected ?int $chargeFreeLimit; + protected DeliveryChargeType $chargeType; + protected Charge $charge; + + protected ?string $memo; + protected ?string $memo2; + + protected ?int $sort; + protected DisplayState $displayState; + + protected bool $preferredDateUse; + protected bool $preferredPeriodUse; + + protected array $unavailablePaymentIds; + + protected int $makeDate; + protected int $updateDate; + + /** + * 配送方法ID + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * ショップアカウントID + * @return string + */ + public function getAccountId(): string + { + return $this->accountId; + } + + /** + * 配送方法名 + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * 配送方法区分 + * @return DeliveryMethodType + */ + public function getMethodType(): DeliveryMethodType + { + return $this->methodType; + } + + /** + * 配送方法画像URL + * @return string|null + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * 配送料が無料になる基準 + * @return DeliveryChargeFreeType + */ + public function getChargeFreeType(): DeliveryChargeFreeType + { + return $this->chargeFreeType; + } + + /** + * 配送料が無料になる金額 + * @return int|null + */ + public function getChargeFreeLimit(): ?int + { + return $this->chargeFreeLimit; + } + + /** + * フィーチャーフォン向けショップ用の説明 + * @return sDeliveryChargeType + */ + public function getChargeType(): DeliveryChargeType + { + return $this->chargeType; + } + + /** + * 配送料設定の詳細 + * @return Charge + */ + public function getCharge(): Charge + { + return $this->charge; + } + + /** + * 送料が税込み料金であるか否か + * @return bool + */ + public function getTaxIncluded(): bool + { + return $this->taxIncluded; + } + + /** + * 配送伝票番号設定を使用するか否か + * @return bool + */ + public function getSlipNumberUse(): bool + { + return $this->slipNumberUse; + } + + /** + * 配送伝票番号確認URL + * @return string|null + */ + public function getSlipNumberUrl(): ?string + { + return $this->slipNumberUrl; + } + + /** + * 配送方法の説明 + * @return string|null + */ + public function getMemo(): ?string + { + return $this->memo; + } + + /** + * フィーチャーフォン向けショップ用の配送方法説明 + * @return string|null + */ + public function getMemo2(): ?string + { + return $this->memo2; + } + + /** + * 表示順 + * @return int|null + */ + public function getSort(): ?int + { + return $this->sort; + } + + /** + * 表示状態 + * @return DisplayState + */ + public function getDisplayState(): DisplayState + { + return $this->displayState; + } + + + /** + * 配送希望日を指定可能か + * @return bool + */ + public function getPreferredDateUse(): bool + { + return $this->preferredDateUse; + } + + /** + * 配送時間帯を指定可能か + * @return bool + */ + public function getPreferredPeriodUse(): bool + { + return $this->preferredPeriodUse; + } + + /** + * 利用不可決済方法の配列 + * @return array + */ + public function getUnavailablePaymentIds(): array + { + return $this->unavailablePaymentIds; + } + + /** + * 配送方法作成日時 + * @return DateTimeImmutable + */ + public function getMakeDate(): DateTimeImmutable + { + return (new DateTimeImmutable)->setTimestamp($this->makeDate); + } + + /** + * 配送方法更新日時 + * @return DateTimeImmutable + */ + public function getUpdateDate(): DateTimeImmutable + { + return (new DateTimeImmutable)->setTimestamp($this->updateDate); + } +} diff --git a/src/Entities/Delivery/Waight.php b/src/Entities/Delivery/Waight.php new file mode 100644 index 0000000..c43ed5c --- /dev/null +++ b/src/Entities/Delivery/Waight.php @@ -0,0 +1,41 @@ + [ + 'array' => true, + 'entity' => Area::class, + ], + ]; + + protected int $weight; + protected array $areas; + + /** + * これ未満のグラム数の場合 + * @return int + */ + public function getWeight(): int + { + return $this->weight; + } + + /** + * 都道府県ごとの配送料 + * @return array + */ + public function getAreas(): array + { + return $this->areas; + } +} diff --git a/src/Services/Delivery.php b/src/Services/Delivery.php new file mode 100644 index 0000000..c26ba14 --- /dev/null +++ b/src/Services/Delivery.php @@ -0,0 +1,38 @@ +_accessToken = $accessToken; + } + + /** + * @link https://developer.shop-pro.jp/docs/colorme-api#tag/delivery/operation/getDeliveries + * @return Collection|Errors + */ + public function all(?string $accessToken = null): Collection|Errors + { + $response = (new Request(new RequestOptions([ + 'authorization' => $accessToken ?? $this->_accessToken, + ])))->get( + 'https://api.shop-pro.jp/v1/deliveries', + ); + if (! $response->isSuccess()) { + return Errors::build($response); + } + $data = $response->getParsedBody(); + + return Collection::cast(DeliveryEntity::class, $data['deliveries'] ?? []); + } +}