|
- <?php
-
- namespace App\Transmissions\HTICWeb;
-
- use App\Codes\EnvironmentName;
- use App\Exceptions\AppCommonException;
- use App\Exceptions\GeneralErrorMessageException;
- use Illuminate\Support\Facades\Http;
-
- trait Sender
- {
- protected function sendSeasonTicketContractCreate(array $contents)
- {
- return $this->sendToHTICWeb("seasonticketcontract/create", $contents);
- }
- protected function sendSeasonTicketContractUpdate(array $contents)
- {
- return $this->sendToHTICWeb("seasonticketcontract/update", $contents);
- }
- protected function sendSeasonTicketContractDelete(array $contents)
- {
- return $this->sendToHTICWeb("seasonticketcontract/delete", $contents);
- }
- protected function getSeasonTicketContractParams(array $contents)
- {
- return $this->sendToHTICWeb("seasonticketcontract/params", $contents);
- }
- protected function getSeasonTicketContractFetch(array $contents)
- {
- return $this->sendToHTICWeb("seasonticketcontract/fetch", $contents);
- }
- protected function sendUserCreate(array $contents)
- {
- return $this->sendToHTICWeb("user/create", $contents);
- }
- protected function sendUserUpdate(array $contents)
- {
- return $this->sendToHTICWeb("user/update", $contents);
- }
- protected function sendUserDelete(array $contents)
- {
- return $this->sendToHTICWeb("user/delete", $contents);
- }
-
- private function sendToHTICWeb(string $url, array $contents)
- {
- $fullUrl = sprintf("%s/api/kyoto-public/%s", config("custom.ht-ic-web.url", ""), $url);
- $customerCode = app()->environment([EnvironmentName::PRODUCTOIN->value]) ? "1163" : "9990";
- $sendContents = [
- ...$contents,
- 'customer_code' => $customerCode,
- 'ht-ic-web-api-key' => config("custom.ht-ic-web.apiKey", ""),
-
- ];
- logger([
- "senddata",
- 'url' => $fullUrl,
- "contents" => $sendContents
- ]);
- $res = Http::post($fullUrl, $sendContents);
-
- if ($res->failed()) {
- throw $res->toException();
- }
-
- if ($res->json('result') !== 0) {
- logger($res->json());
-
-
- $generalErrorMessage = $res->json('messages.general', "");
- if (!!$generalErrorMessage) {
- throw new GeneralErrorMessageException($generalErrorMessage);
- }
- $messages = $res->json('messages.errors', []);
- logger(['messages' => $messages]);
- if (0 < count($messages)) {
- $key = array_key_first($messages);
- $message = $messages[$key];
- throw new GeneralErrorMessageException(sprintf("%s: %s", $key, $message));
- }
-
- throw new AppCommonException("HTICWeb連携失敗");
- }
-
- return $res;
- }
- }
|