<?php
/**
 * ChargeApi
 * PHP version 5
 *
 * @category Class
 * @package  ColorMeShop\Swagger
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * カラーミーショップ API
 *
 * # カラーミーショップ API  [カラーミーショップ](https://shop-pro.jp) APIでは、受注の検索や商品情報の更新を行うことができます。  ## 利用手順  はじめに、カラーミーデベロッパーアカウントを用意します。[デベロッパー登録ページ](https://api.shop-pro.jp/developers/sign_up)から登録してください。  次に、[登録ページ](https://api.shop-pro.jp/oauth/applications/new)からアプリケーション登録を行ってください。 スマートフォンのWebViewを利用する場合は、リダイレクトURIに`urn:ietf:wg:oauth:2.0:oob`を入力してください。  その後、カラーミーショップアカウントの認証ページを開きます。認証ページのURLは、`https://api.shop-pro.jp/oauth/authorize`に必要なパラメータをつけたものです。  |パラメータ名|値| |---|---| |`client_id`|アプリケーション詳細画面で確認できるクライアントID| |`response_type`|\"code\"という文字列| |`scope`| 別表参照| |`redirect_uri`|アプリケーション登録時に入力したリダイレクトURI|  `scope`は、以下のうち、アプリケーションが利用したい機能をスペース区切りで指定してください。  |スコープ|機能| |---|---| |`read_products`|商品データの参照| |`write_products`|在庫データの更新| |`read_sales`|受注・顧客データの参照| |`write_sales`|受注データの更新|  以下のようなURLとなります。  ``` https://api.shop-pro.jp/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&scope=read_products%20write_products ```  初めてこのページを訪れる場合は、カラーミーショップアカウントのIDとパスワードの入力を求められます。 承認ボタンを押すと、このアプリケーションがショップのデータにアクセスすることが許可され、リダイレクトURIへリダイレクトされます。  承認された場合は、`code`というクエリパラメータに認可コードが付与されます。承認がキャンセルされた、またはエラーが起きた場合は、 `error`パラメータにエラーの内容を表す文字列が与えられます。  アプリケーション登録時のリダイレクトURIに`urn:ietf:wg:oauth:2.0:oob`を指定した場合は、以下のようなURLにリダイレクトされます。 末尾のパスが認可コードになっています。  ``` https://api.shop-pro.jp/oauth/authorize/AUTH_CODE ```  認可コードの有効期限は発行から10分間です。  最後に、認可コードとアクセストークンを交換します。以下のパラメータを付けて、`https://api.shop-pro.jp/oauth/token`へリクエストを送ります。  |パラメータ名|値| |---|---| |`client_id`|アプリケーション詳細画面に表示されているクライアントID| |`client_secret`|アプリケーション詳細画面に表示されているクライアントシークレット| |`code`|取得した認可コード| |`grant_type`|\"authorization_code\"という文字列| |`redirect_uri`|アプリケーション登録時に入力したリダイレクトURI|  ```console # curl での例  $ curl -X POST \\   -d'client_id=CLIENT_ID' \\   -d'client_secret=CLIENT_SECRET' \\   -d'code=CODE' \\   -d'grant_type=authorization_code'   \\   -d'redirect_uri=REDIRECT_URI'  \\   'https://api.shop-pro.jp/oauth/token' ```  リクエストが成功すると、以下のようなJSONが返ってきます。  ```json {   \"access_token\": \"d461ab8XXXXXXXXXXXXXXXXXXXXXXXXX\",   \"token_type\": \"bearer\",   \"scope\": \"read_products write_products\" } ```  アクセストークンに有効期限はありませんが、許可済みアプリケーション一覧画面から失効させることができます。なお、同じ認可コードをアクセストークンに交換できるのは1度だけです。  取得したアクセストークンは、Authorizationヘッダに入れて使用します。以下にショップ情報を取得する際の例を示します。  ```console # curlの例  $ curl -H 'Authorization: Bearer d461ab8XXXXXXXXXXXXXXXXXXXXXXXXX' https://api.shop-pro.jp/v1/shop.json ```  ## エラー  カラーミーショップAPI v1では  - エラーコード - エラーメッセージ - ステータスコード  の配列でエラーを表現します。以下に例を示します。  ```json {   \"errors\": [     {       \"code\": 404100,       \"message\": \"レコードが見つかりませんでした。\",       \"status\": 404     }   ] } ```
 *
 * OpenAPI spec version: 1.0.0
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 * Swagger Codegen version: 2.3.0
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace ColorMeShop\Swagger\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use ColorMeShop\Swagger\ApiException;
use ColorMeShop\Swagger\Configuration;
use ColorMeShop\Swagger\HeaderSelector;
use ColorMeShop\Swagger\ObjectSerializer;

/**
 * ChargeApi Class Doc Comment
 *
 * @category Class
 * @package  ColorMeShop\Swagger
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */
class ChargeApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation activateApplicationCharge
     *
     * スポット課金データをアクティベートする
     *
     * @param  int $application_charge_id application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20019
     */
    public function activateApplicationCharge($application_charge_id)
    {
        list($response) = $this->activateApplicationChargeWithHttpInfo($application_charge_id);
        return $response;
    }

    /**
     * Operation activateApplicationChargeWithHttpInfo
     *
     * スポット課金データをアクティベートする
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20019, HTTP status code, HTTP response headers (array of strings)
     */
    public function activateApplicationChargeWithHttpInfo($application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20019';
        $request = $this->activateApplicationChargeRequest($application_charge_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20019',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation activateApplicationChargeAsync
     *
     * スポット課金データをアクティベートする
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function activateApplicationChargeAsync($application_charge_id)
    {
        return $this->activateApplicationChargeAsyncWithHttpInfo($application_charge_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation activateApplicationChargeAsyncWithHttpInfo
     *
     * スポット課金データをアクティベートする
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function activateApplicationChargeAsyncWithHttpInfo($application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20019';
        $request = $this->activateApplicationChargeRequest($application_charge_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'activateApplicationCharge'
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function activateApplicationChargeRequest($application_charge_id)
    {
        // verify the required parameter 'application_charge_id' is set
        if ($application_charge_id === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $application_charge_id when calling activateApplicationCharge'
            );
        }

        $resourcePath = '/v1/application_charges/{applicationChargeId}/activate.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($application_charge_id !== null) {
            $resourcePath = str_replace(
                '{' . 'applicationChargeId' . '}',
                ObjectSerializer::toPathValue($application_charge_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation activateRecurringApplicationCharge
     *
     * 月額課金データをアクティベートする
     *
     * @param  int $recurring_application_charge_id recurring_application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20021
     */
    public function activateRecurringApplicationCharge($recurring_application_charge_id)
    {
        list($response) = $this->activateRecurringApplicationChargeWithHttpInfo($recurring_application_charge_id);
        return $response;
    }

    /**
     * Operation activateRecurringApplicationChargeWithHttpInfo
     *
     * 月額課金データをアクティベートする
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20021, HTTP status code, HTTP response headers (array of strings)
     */
    public function activateRecurringApplicationChargeWithHttpInfo($recurring_application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20021';
        $request = $this->activateRecurringApplicationChargeRequest($recurring_application_charge_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20021',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation activateRecurringApplicationChargeAsync
     *
     * 月額課金データをアクティベートする
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function activateRecurringApplicationChargeAsync($recurring_application_charge_id)
    {
        return $this->activateRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation activateRecurringApplicationChargeAsyncWithHttpInfo
     *
     * 月額課金データをアクティベートする
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function activateRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20021';
        $request = $this->activateRecurringApplicationChargeRequest($recurring_application_charge_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'activateRecurringApplicationCharge'
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function activateRecurringApplicationChargeRequest($recurring_application_charge_id)
    {
        // verify the required parameter 'recurring_application_charge_id' is set
        if ($recurring_application_charge_id === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $recurring_application_charge_id when calling activateRecurringApplicationCharge'
            );
        }

        $resourcePath = '/v1/recurring_application_charges/{recurringApplicationChargeId}/activate.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($recurring_application_charge_id !== null) {
            $resourcePath = str_replace(
                '{' . 'recurringApplicationChargeId' . '}',
                ObjectSerializer::toPathValue($recurring_application_charge_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation cancelRecurringApplicationCharge
     *
     * 月額課金データをキャンセルする
     *
     * @param  int $recurring_application_charge_id recurring_application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20021
     */
    public function cancelRecurringApplicationCharge($recurring_application_charge_id)
    {
        list($response) = $this->cancelRecurringApplicationChargeWithHttpInfo($recurring_application_charge_id);
        return $response;
    }

    /**
     * Operation cancelRecurringApplicationChargeWithHttpInfo
     *
     * 月額課金データをキャンセルする
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20021, HTTP status code, HTTP response headers (array of strings)
     */
    public function cancelRecurringApplicationChargeWithHttpInfo($recurring_application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20021';
        $request = $this->cancelRecurringApplicationChargeRequest($recurring_application_charge_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20021',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation cancelRecurringApplicationChargeAsync
     *
     * 月額課金データをキャンセルする
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function cancelRecurringApplicationChargeAsync($recurring_application_charge_id)
    {
        return $this->cancelRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation cancelRecurringApplicationChargeAsyncWithHttpInfo
     *
     * 月額課金データをキャンセルする
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function cancelRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20021';
        $request = $this->cancelRecurringApplicationChargeRequest($recurring_application_charge_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'cancelRecurringApplicationCharge'
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function cancelRecurringApplicationChargeRequest($recurring_application_charge_id)
    {
        // verify the required parameter 'recurring_application_charge_id' is set
        if ($recurring_application_charge_id === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $recurring_application_charge_id when calling cancelRecurringApplicationCharge'
            );
        }

        $resourcePath = '/v1/recurring_application_charges/{recurringApplicationChargeId}/cancel.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($recurring_application_charge_id !== null) {
            $resourcePath = str_replace(
                '{' . 'recurringApplicationChargeId' . '}',
                ObjectSerializer::toPathValue($recurring_application_charge_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getApplicationCharge
     *
     * スポット課金データの取得
     *
     * @param  int $application_charge_id application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20019
     */
    public function getApplicationCharge($application_charge_id)
    {
        list($response) = $this->getApplicationChargeWithHttpInfo($application_charge_id);
        return $response;
    }

    /**
     * Operation getApplicationChargeWithHttpInfo
     *
     * スポット課金データの取得
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20019, HTTP status code, HTTP response headers (array of strings)
     */
    public function getApplicationChargeWithHttpInfo($application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20019';
        $request = $this->getApplicationChargeRequest($application_charge_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20019',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getApplicationChargeAsync
     *
     * スポット課金データの取得
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getApplicationChargeAsync($application_charge_id)
    {
        return $this->getApplicationChargeAsyncWithHttpInfo($application_charge_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getApplicationChargeAsyncWithHttpInfo
     *
     * スポット課金データの取得
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getApplicationChargeAsyncWithHttpInfo($application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20019';
        $request = $this->getApplicationChargeRequest($application_charge_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getApplicationCharge'
     *
     * @param  int $application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getApplicationChargeRequest($application_charge_id)
    {
        // verify the required parameter 'application_charge_id' is set
        if ($application_charge_id === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $application_charge_id when calling getApplicationCharge'
            );
        }

        $resourcePath = '/v1/application_charges/{applicationChargeId}.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($application_charge_id !== null) {
            $resourcePath = str_replace(
                '{' . 'applicationChargeId' . '}',
                ObjectSerializer::toPathValue($application_charge_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getApplicationCharges
     *
     * スポット課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20018
     */
    public function getApplicationCharges($limit = null, $since_id = null)
    {
        list($response) = $this->getApplicationChargesWithHttpInfo($limit, $since_id);
        return $response;
    }

    /**
     * Operation getApplicationChargesWithHttpInfo
     *
     * スポット課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20018, HTTP status code, HTTP response headers (array of strings)
     */
    public function getApplicationChargesWithHttpInfo($limit = null, $since_id = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20018';
        $request = $this->getApplicationChargesRequest($limit, $since_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20018',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getApplicationChargesAsync
     *
     * スポット課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getApplicationChargesAsync($limit = null, $since_id = null)
    {
        return $this->getApplicationChargesAsyncWithHttpInfo($limit, $since_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getApplicationChargesAsyncWithHttpInfo
     *
     * スポット課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getApplicationChargesAsyncWithHttpInfo($limit = null, $since_id = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20018';
        $request = $this->getApplicationChargesRequest($limit, $since_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getApplicationCharges'
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getApplicationChargesRequest($limit = null, $since_id = null)
    {

        $resourcePath = '/v1/application_charges.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($limit !== null) {
            $queryParams['limit'] = ObjectSerializer::toQueryValue($limit);
        }
        // query params
        if ($since_id !== null) {
            $queryParams['since_id'] = ObjectSerializer::toQueryValue($since_id);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getRecurringApplicationCharge
     *
     * 月額課金データの取得
     *
     * @param  int $recurring_application_charge_id recurring_application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20021
     */
    public function getRecurringApplicationCharge($recurring_application_charge_id)
    {
        list($response) = $this->getRecurringApplicationChargeWithHttpInfo($recurring_application_charge_id);
        return $response;
    }

    /**
     * Operation getRecurringApplicationChargeWithHttpInfo
     *
     * 月額課金データの取得
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20021, HTTP status code, HTTP response headers (array of strings)
     */
    public function getRecurringApplicationChargeWithHttpInfo($recurring_application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20021';
        $request = $this->getRecurringApplicationChargeRequest($recurring_application_charge_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20021',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getRecurringApplicationChargeAsync
     *
     * 月額課金データの取得
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getRecurringApplicationChargeAsync($recurring_application_charge_id)
    {
        return $this->getRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getRecurringApplicationChargeAsyncWithHttpInfo
     *
     * 月額課金データの取得
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20021';
        $request = $this->getRecurringApplicationChargeRequest($recurring_application_charge_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getRecurringApplicationCharge'
     *
     * @param  int $recurring_application_charge_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getRecurringApplicationChargeRequest($recurring_application_charge_id)
    {
        // verify the required parameter 'recurring_application_charge_id' is set
        if ($recurring_application_charge_id === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $recurring_application_charge_id when calling getRecurringApplicationCharge'
            );
        }

        $resourcePath = '/v1/recurring_application_charges/{recurringApplicationChargeId}.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($recurring_application_charge_id !== null) {
            $resourcePath = str_replace(
                '{' . 'recurringApplicationChargeId' . '}',
                ObjectSerializer::toPathValue($recurring_application_charge_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getRecurringApplicationCharges
     *
     * 月額課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse20020
     */
    public function getRecurringApplicationCharges($limit = null, $since_id = null)
    {
        list($response) = $this->getRecurringApplicationChargesWithHttpInfo($limit, $since_id);
        return $response;
    }

    /**
     * Operation getRecurringApplicationChargesWithHttpInfo
     *
     * 月額課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse20020, HTTP status code, HTTP response headers (array of strings)
     */
    public function getRecurringApplicationChargesWithHttpInfo($limit = null, $since_id = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20020';
        $request = $this->getRecurringApplicationChargesRequest($limit, $since_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse20020',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getRecurringApplicationChargesAsync
     *
     * 月額課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getRecurringApplicationChargesAsync($limit = null, $since_id = null)
    {
        return $this->getRecurringApplicationChargesAsyncWithHttpInfo($limit, $since_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getRecurringApplicationChargesAsyncWithHttpInfo
     *
     * 月額課金一覧の取得
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getRecurringApplicationChargesAsyncWithHttpInfo($limit = null, $since_id = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse20020';
        $request = $this->getRecurringApplicationChargesRequest($limit, $since_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getRecurringApplicationCharges'
     *
     * @param  int $limit レスポンスの件数を指定します。指定がない場合は10件。最大50件。 (optional)
     * @param  int $since_id 指定した課金ID以降のデータを返します。 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getRecurringApplicationChargesRequest($limit = null, $since_id = null)
    {

        $resourcePath = '/v1/recurring_application_charges.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($limit !== null) {
            $queryParams['limit'] = ObjectSerializer::toQueryValue($limit);
        }
        // query params
        if ($since_id !== null) {
            $queryParams['since_id'] = ObjectSerializer::toQueryValue($since_id);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postApplicationCharge
     *
     * スポット課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\ApplicationCharge $application_charge application_charge (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse201
     */
    public function postApplicationCharge($application_charge)
    {
        list($response) = $this->postApplicationChargeWithHttpInfo($application_charge);
        return $response;
    }

    /**
     * Operation postApplicationChargeWithHttpInfo
     *
     * スポット課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\ApplicationCharge $application_charge (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse201, HTTP status code, HTTP response headers (array of strings)
     */
    public function postApplicationChargeWithHttpInfo($application_charge)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse201';
        $request = $this->postApplicationChargeRequest($application_charge);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse201',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postApplicationChargeAsync
     *
     * スポット課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\ApplicationCharge $application_charge (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postApplicationChargeAsync($application_charge)
    {
        return $this->postApplicationChargeAsyncWithHttpInfo($application_charge)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postApplicationChargeAsyncWithHttpInfo
     *
     * スポット課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\ApplicationCharge $application_charge (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postApplicationChargeAsyncWithHttpInfo($application_charge)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse201';
        $request = $this->postApplicationChargeRequest($application_charge);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postApplicationCharge'
     *
     * @param  \ColorMeShop\Swagger\Model\ApplicationCharge $application_charge (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postApplicationChargeRequest($application_charge)
    {
        // verify the required parameter 'application_charge' is set
        if ($application_charge === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $application_charge when calling postApplicationCharge'
            );
        }

        $resourcePath = '/v1/application_charges.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // body params
        $_tempBody = null;
        if (isset($application_charge)) {
            $_tempBody = $application_charge;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postRecurringApplicationCharge
     *
     * 月額課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\RecurringApplicationCharge $recurring_application_charge recurring_application_charge (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse2011
     */
    public function postRecurringApplicationCharge($recurring_application_charge)
    {
        list($response) = $this->postRecurringApplicationChargeWithHttpInfo($recurring_application_charge);
        return $response;
    }

    /**
     * Operation postRecurringApplicationChargeWithHttpInfo
     *
     * 月額課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\RecurringApplicationCharge $recurring_application_charge (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse2011, HTTP status code, HTTP response headers (array of strings)
     */
    public function postRecurringApplicationChargeWithHttpInfo($recurring_application_charge)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2011';
        $request = $this->postRecurringApplicationChargeRequest($recurring_application_charge);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse2011',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postRecurringApplicationChargeAsync
     *
     * 月額課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\RecurringApplicationCharge $recurring_application_charge (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postRecurringApplicationChargeAsync($recurring_application_charge)
    {
        return $this->postRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postRecurringApplicationChargeAsyncWithHttpInfo
     *
     * 月額課金データの作成
     *
     * @param  \ColorMeShop\Swagger\Model\RecurringApplicationCharge $recurring_application_charge (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postRecurringApplicationChargeAsyncWithHttpInfo($recurring_application_charge)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2011';
        $request = $this->postRecurringApplicationChargeRequest($recurring_application_charge);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postRecurringApplicationCharge'
     *
     * @param  \ColorMeShop\Swagger\Model\RecurringApplicationCharge $recurring_application_charge (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postRecurringApplicationChargeRequest($recurring_application_charge)
    {
        // verify the required parameter 'recurring_application_charge' is set
        if ($recurring_application_charge === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $recurring_application_charge when calling postRecurringApplicationCharge'
            );
        }

        $resourcePath = '/v1/recurring_application_charges.json';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // body params
        $_tempBody = null;
        if (isset($recurring_application_charge)) {
            $_tempBody = $recurring_application_charge;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        return $options;
    }
}
