> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paymentoptions.com/llms.txt
> Use this file to discover all available pages before exploring further.

# トークンAPIの生成

> カードトークン生成APIは、購入または認証プロセス中に敏感なカード情報をトークン化し、実際のカード詳細を公開せずに安全な取引を可能にします。

### 重要なポイント

<Info>
  * カードをトークン化することで、カード詳細を再入力することなく繰り返し取引を行うことができ、セキュリティとユーザー体験の向上が図れます。

  * 生成されたトークンは、購入と認証の両方の取引で使用でき、さまざまな支払いタイプに対応する柔軟性を提供します。

  * 重要なパラメータには通常、カード番号、有効期限、CVV、顧客情報が含まれます。
</Info>

## フローダイアグラム

<img src="https://mintcdn.com/dasdoc/NIfdTDr2rgRx_fiM/images/flows-API-GenerateToken-jp.svg?fit=max&auto=format&n=NIfdTDr2rgRx_fiM&q=85&s=b4bc3039c096750e2effaa254f65144d" alt="フローダイアグラム画像" width="1997" height="1150" data-path="images/flows-API-GenerateToken-jp.svg" />

### ノート

`store_payment_method`: 将来の使用のためにカードトークンを保存するには、ペイロードで `true` に設定する必要があります。

```json リクエスト例 theme={null}
{
  "payment_method": {
    "type": "scheme",
    "store_payment_method": true
  }
```

`store_payment_method` を `true` に設定することで、カード詳細を再入力することなく、カードトークンが今後の取引のために保存されます。

```json レスポンス例 theme={null}
{
  "transaction_details": {
    "id": "<transaction_id>",
    "ref": <ref>,
    "timestamp": "yyyy-mm-ddThh:mm:ss.000Z",
    "merchant_txn_ref": "<string>",
    "stored_payment_method_id": "094db781-fabc-4c6d-8fcd-18bee06a527a"
  }
}
```

`stored_payment_method_id` は、カード詳細を再入力することなく、今後の取引でカードトークンAPIを使用するために利用できます。

## APIパラメータ


## OpenAPI

````yaml /api-reference/jp/open-api-config/tokenization/generate-token.json POST /api/v1/server-to-server-interface/payment
openapi: 3.0.1
info:
  title: Payment Options API
  description: ホストされた支払いページ（HPP）リンクを生成し、支払いを処理するためのAPI。
  version: 1.0.0
servers:
  - url: https://api-dev.paymentoptions.com
security:
  - apiKeyAuth: []
    xApiKeyAuth: []
paths:
  /api/v1/server-to-server-interface/payment:
    post:
      operationId: generatetoken
      requestBody:
        description: 決済取引を処理するためのリクエストペイロード。
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              properties:
                amount:
                  type: string
                  description: 取引の金額。
                  example: '1000'
                currency:
                  type: string
                  description: '処理通貨の略語（例: JPY）。'
                  example: JPY
                  maxLength: 3
                card:
                  type: object
                  additionalProperties: false
                  description: カードの詳細を含むJSONオブジェクト。
                  properties:
                    cvc:
                      type: string
                      description: カードのセキュリティコード（通常3桁、AMEXは4桁）。
                      example: '100'
                      maxLength: 4
                    expiry_month:
                      type: string
                      description: 'カードの有効期限（月）（例: 12 = 12月）。'
                      example: '12'
                      maxLength: 2
                    expiry_year:
                      type: string
                      description: カードの有効期限の年（例：29 または 2029 年）。
                      example: '29'
                      maxLength: 4
                    name:
                      type: string
                      description: カード名義人の名前。
                      example: John Doe
                      maxLength: 255
                    number:
                      type: string
                      description: カード番号。
                      example: '4000000000001091'
                      maxLength: 16
                payment_method:
                  type: object
                  additionalProperties: false
                  description: 決済方法を含むJSONオブジェクト。
                  properties:
                    type:
                      type: string
                      description: '決済方法の種類（例: ''scheme''）。'
                      example: scheme
                      maxLength: 128
                    store_payment_method:
                      type: boolean
                      description: 決済方法を保存する場合はTrue、保存しない場合はFalse（トークン化用）。
                      example: true
                merchant_txn_ref:
                  type: string
                  description: 加盟店取引参照ID。
                  example: qwe
                  maxLength: 45
                customer_ip:
                  type: string
                  description: カード所有者のIPアドレス。
                  example: 127.0.0.1
                  maxLength: 45
                merchant_id:
                  type: string
                  description: 加盟店ID（DASMID）。
                  example: < Merchant ID >
                  maxLength: 128
                return_url:
                  type: object
                  additionalProperties: false
                  description: リターンURLを含むJSONオブジェクト。（このフィールドは3DS取引に必須）。
                  properties:
                    webhook_url:
                      type: string
                      description: Webhook URLリンク。
                      example: < Webhook url >
                      maxLength: 255
                    success_url:
                      type: string
                      description: 支払い成功後のリダイレクトURL。
                      example: http://www.successurl.com/
                      maxLength: 255
                    decline_url:
                      type: string
                      description: 支払い失敗後のリダイレクトURL。
                      example: http://www.declineurl.com/
                      maxLength: 255
                billing_address:
                  type: object
                  additionalProperties: false
                  description: カード所有者の請求先住所を含むJSONオブジェクト。
                  properties:
                    country:
                      type: string
                      description: カード所有者の請求先国コード。
                      example: JP
                      maxLength: 2
                    email:
                      type: string
                      description: カード所有者の請求先メールアドレス。
                      example: billing@testemail.com
                      maxLength: 45
                    phone_number:
                      type: string
                      description: カード所有者の請求先電話番号。
                      example: '8112345678'
                      maxLength: 20
                    address1:
                      type: string
                      description: カード所有者の請求先住所。
                      example: 1-2-3 Shinjuku
                      maxLength: 199
                    city:
                      type: string
                      description: カード所有者の請求先市区町村。
                      example: Shinjuku-ku
                      maxLength: 65
                    state:
                      type: string
                      description: カード所有者の請求先都道府県。
                      example: Tokyo
                      maxLength: 65
                    postal_code:
                      type: string
                      description: カード所有者の請求先郵便番号。
                      example: '1600022'
                      maxLength: 45
                shipping_address:
                  type: object
                  additionalProperties: false
                  description: カード所有者の配送先住所を含むJSONオブジェクト（オプション）。
                  properties:
                    country:
                      type: string
                      description: カード所有者の配送先国コード。
                      example: JP
                      maxLength: 2
                    email:
                      type: string
                      description: カード所有者の配送先メールアドレス。
                      example: shipping@testemail.com
                      maxLength: 45
                    phone_number:
                      type: string
                      description: カード所有者の配送先電話番号。
                      example: '8112345678'
                      maxLength: 20
                    address1:
                      type: string
                      description: カード所有者の配送先住所。
                      example: 1-2-3 Shinjuku
                      maxLength: 199
                    city:
                      type: string
                      description: カード所有者の配送先市区町村。
                      example: Shinjuku-ku
                      maxLength: 65
                    state:
                      type: string
                      description: カード所有者の配送先都道府県。
                      example: Tokyo
                      maxLength: 65
                    postal_code:
                      type: string
                      description: カード所有者の配送先郵便番号。
                      example: '1600022'
                      maxLength: 45
                time_zone:
                  type: string
                  description: 取引の国のタイムゾーン。
                  example: Asia/Kuala_Lumpur
                  maxLength: 128
              required:
                - amount
                - currency
                - card
                - payment_method
                - merchant_id
                - billing_address
      responses:
        '201':
          description: 支払いが正常に処理されました。
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: 取引が成功した場合はtrue、失敗した場合はfalse。
                    example: true
                  status_code:
                    type: integer
                    description: 取引のステータスコード。
                    example: 201
                  is_live:
                    type: boolean
                    description: 本番環境の取引の場合はtrue、テスト取引の場合はfalse。
                    example: false
                  transaction_type:
                    type: string
                    description: 取引の種類（例：CAPTURE）。
                    example: CAPTURE
                  gateway_response:
                    type: object
                    description: ゲートウェイからのレスポンスを含むJSONオブジェクト。
                    properties:
                      version:
                        type: string
                        description: ゲートウェイのバージョン。
                        example: '1'
                      type:
                        type: string
                        description: レスポンスの種類（例：INFO）。
                        example: INFO
                      message:
                        type: string
                        description: ゲートウェイからのメッセージレスポンス。
                        example: Payment Successful.
                      code:
                        type: string
                        description: レスポンスのメッセージコード。
                        example: INFO0000
                  merchant_details:
                    type: object
                    description: 加盟店の詳細情報を含むJSONオブジェクト。
                    properties:
                      legal_name:
                        type: string
                        description: 加盟店の正式名称。
                        example: アイベック株式会社
                      mid:
                        type: string
                        description: 加盟店ID（DASMID）。
                        example: < Merchant ID >
                      merchant_txn_ref:
                        type: string
                        description: 加盟店取引参照ID。
                        example: qwe
                      billing_details:
                        type: object
                        description: 請求情報を含むJSONオブジェクト。
                        properties:
                          billing_address:
                            type: object
                            description: 請求先住所を含むJSONオブジェクト。
                            properties:
                              country:
                                type: string
                                description: カード所有者の請求先国コード。
                                example: JP
                              email:
                                type: string
                                description: カード所有者の請求先メールアドレス。
                                example: billing@testemail.com
                              phone_number:
                                type: string
                                description: カード所有者の請求先電話番号。
                                example: '8112345678'
                              address1:
                                type: string
                                description: カード所有者の請求先住所。
                                example: 1-2-3 Shinjuku
                              city:
                                type: string
                                description: カード所有者の請求先市区町村。
                                example: Shinjuku-ku
                              state:
                                type: string
                                description: カード所有者の請求先都道府県。
                                example: Tokyo
                              postal_code:
                                type: string
                                description: カード所有者の請求先郵便番号。
                                example: '1600022'
                      device_details:
                        type: object
                        description: デバイスの詳細情報を含むJSONオブジェクト。
                        properties:
                          visited_ip:
                            type: string
                            description: 決済ページのIPアドレス。
                            example: 127.0.0.1
                          merchant_ip:
                            type: string
                            description: 加盟店のIPアドレスです。
                            example: 127.0.0.1
                          customer_ip:
                            type: string
                            description: カード所有者のIPアドレス。
                            example: 127.0.0.1
                  payment_details:
                    type: object
                    description: 支払いの詳細情報を含むJSONオブジェクト。
                    properties:
                      amount:
                        type: number
                        description: 取引の金額値。
                        example: 1000
                      response_code:
                        type: integer
                        description: アクワイアラーのレスポンスコード。
                        example: 0
                      auth_code:
                        type: string
                        description: アクワイアラーの認可コード。
                        example: '268004'
                      currency:
                        type: string
                        description: 取引の通貨。
                        example: JPY
                      payment_method:
                        type: string
                        description: '支払いカードの種類（例: クレジットカード）。'
                        example: ECMC-SSL
                      scheme:
                        type: string
                        description: 'カードブランドのスキーム（例: マスターカード）。'
                        example: MASTERCARD
                      card:
                        type: object
                        description: カードの詳細を含むJSONオブジェクト。
                        properties:
                          name:
                            type: string
                            description: カード名義人の氏名。
                            example: John Doe
                          number:
                            type: string
                            description: カード番号（マスキング済み）。
                            example: '4000000000001091'
                          exp_month:
                            type: string
                            description: カードの有効期限（月）。
                            example: '12'
                          exp_year:
                            type: string
                            description: カードの有効期限（年）。
                            example: '29'
                      additional_data:
                        type: object
                        description: 追加データを含むJSONオブジェクト。
                        properties:
                          payment_data_source:
                            type: object
                            description: 支払いデータソースを含むJSONオブジェクト。
                            properties:
                              type:
                                type: string
                                description: 支払いデータソースの種類。
                                example: card
                  transaction_details:
                    type: object
                    description: 取引の詳細を含むJSONオブジェクト。
                    properties:
                      id:
                        type: string
                        description: 取引ID。
                        example: fc565b43-26f5-4906-92ae-d849edc3c3a1
                      ref:
                        type: integer
                        description: 取引の認可コード。
                        example: 74811
                      timestamp:
                        type: string
                        description: 取引の日時。
                        example: '2024-11-25T08:24:36.000Z'
                      merchant_txn_ref:
                        type: string
                        description: 加盟店の取引参照ID。
                        example: qwe
                      stored_payment_method_id:
                        type: string
                        description: 保存済みの支払い方法ID（該当する場合）。
                        example: 094db781-fabc-4c6d-8fcd-18bee06a527a
                  risk-details:
                    type: object
                    description: リスクの詳細を含むJSONオブジェクト。
                    properties:
                      risk_score:
                        type: string
                        description: リスクスコア（該当する場合）。
                        example: null
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      name: Authorization
      in: header
      description: '認証のためのAPIキー。フォーマット: ''Basic YOUR_API_KEY_HERE'''
    xApiKeyAuth:
      type: apiKey
      name: x-api-key
      in: header
      description: x-api-key専用のAPIキー。

````