# インボイス 更新

`PUT /v1/invoices/{id}`

- operationId: `updateInvoices`
- tags: インボイス機能

指定したIDを持つインボイス情報を更新します。\
インボイス 発行APIを呼び出すまで請求は行われません。発行後は 回収困難フラグ、および 加盟店自由項目 のみが更新可能です。


## コードサンプル

### cURL

```bash
curl \
    -X PUT \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
      "is_uncollectible": false,
      "bill_mail_send_flag": "0",
      "receipt_mail_send_flag": "0",
      "underpayment_mail_send_flag": "0",
      "invoice_number": "INV123456",
      "customer_id": "CUST001",
      "customer_honorific": "様",
      "customer_overwrite": {
        "name": "株式会社テスト",
        "email": "test@example.com",
        "addr_country": "JP",
        "addr_state": "13",
        "addr_city": "新宿区",
        "addr_line_1": "1-1-1",
        "addr_line_2": "テストビル",
        "addr_line_3": "",
        "addr_post_code": "1600022"
      },
      "issuer_overwrite": {
        "addr_country": "JP",
        "addr_state": "13",
        "addr_city": "新宿区",
        "addr_line_1": "1-1-1",
        "addr_line_2": "テストビル",
        "addr_line_3": "",
        "addr_post_code": "1600022",
        "email": "issuer@example.com",
        "phone_number": "0312345678"
      },
      "lines": [
        {
          "date": "2023/10/01",
          "name": "商品A",
          "unit_price": 1000,
          "quantity": 2,
          "tax_rate": 10
        }
      ],
      "pay_types": [
        "Virtualaccount",
        "Card"
      ],
}' \
'https://api.test.fincode.jp/v1/invoices/{id}'
```

### Node.js

```javascript
import fetch from "node-fetch";

const BASE_URL = "https://api.test.fincode.jp";
const API_KEY = "<Secret API Key>";

(async () => {
  const invoiceId = "<Invoice ID>"; // ここにInvoice IDを設定

  const endpoint = `${BASE_URL}/v1/invoices/${invoiceId}`;

  const response = await fetch(endpoint, {
    method: "PUT",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      is_uncollectible: false,
      bill_mail_send_flag: "0",
      receipt_mail_send_flag: "0",
      underpayment_mail_send_flag: "0",
      invoice_number: "INV123456",
      customer_id: "CUST001",
      customer_honorific: "様",
      customer_overwrite: {
        name: "株式会社テスト",
        email: "test@example.com",
        addr_country: "JP",
        addr_state: "13",
        addr_city: "新宿区",
        addr_line_1: "1-1-1",
        addr_line_2: "テストビル",
        addr_line_3: "",
        addr_post_code: "1600022",
      },
      issuer_overwrite: {
        addr_country: "JP",
        addr_state: "13",
        addr_city: "新宿区",
        addr_line_1: "1-1-1",
        addr_line_2: "テストビル",
        addr_line_3: "",
        addr_post_code: "1600022",
        email: "issuer@example.com",
        phone_number: "0312345678",
      },
      lines: [
        {
          date: "2023/10/01",
          name: "商品A",
          unit_price: 1000,
          quantity: 2,
          tax_rate: 10,
        },
      ],
      pay_types: ["Virtualaccount", "Card"],
    }),
  });

  if (response.ok) {
    const invoiceData = await response.json();
    console.log("Invoice Updated:", invoiceData);
  } else {
    console.error("Error updating invoice:", await response.text());
  }
})();
```

### Go

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
)

func main() {
	// APIキーとインボイスIDを指定
	apiKey := "<Secret API Key>"
	invoiceID := "<Invoice ID>"

	// リクエストボディの作成
	body := UpdateInvoiceRequest{
		IsUncollectible:         false,
		BillMailSendFlag:        "0",
		ReceiptMailSendFlag:     "0",
		UnderpaymentMailSendFlag: "0",
		InvoiceNumber:           "INV123456",
		CustomerID:              "CUST001",
		CustomerHonorific:       "様",
		CustomerOverwrite: CustomerOverwrite{
			Name:        "株式会社テスト",
			Email:       "test@example.com",
			AddrCountry: "JP",
			AddrState:   "13",
			AddrCity:    "新宿区",
			AddrLine1:   "1-1-1",
			AddrLine2:   "テストビル",
			AddrLine3:   "",
			AddrPostCode: "1600022",
		},
		IssuerOverwrite: IssuerOverwrite{
			AddrCountry: "JP",
			AddrState:   "13",
			AddrCity:    "新宿区",
			AddrLine1:   "1-1-1",
			AddrLine2:   "テストビル",
			AddrLine3:   "",
			AddrPostCode: "1600022",
			Email:       "issuer@example.com",
			PhoneNumber: "0312345678",
		},
		Lines: []Line{
			{
				Date:     "2023/10/01",
				Name:     "商品A",
				UnitPrice: 1000,
				Quantity: 2,
				TaxRate:  10,
			},
		},
		PayTypes: []string{"Virtualaccount", "Card"},
	}

	// JSONにエンコード
	marshalledBody, err := json.Marshal(body)
	if err != nil {
		log.Fatalf("エンコードエラー: %v", err)
	}

	// URLの設定
	url := fmt.Sprintf("https://api.test.fincode.jp/v1/invoices/%s", invoiceID)

	// HTTPリクエストの作成
	req, err := http.NewRequest("PUT", url, bytes.NewBuffer(marshalledBody))
	if err != nil {
		log.Fatalf("リクエストの作成エラー: %v", err)
	}

	// ヘッダーの設定
	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
	req.Header.Set("Content-Type", "application/json")

	// クライアントの作成とリクエストの送信
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		log.Fatalf("リクエストエラー: %v", err)
	}
	defer res.Body.Close()

	// レスポンスのステータスコードの表示
	fmt.Println("Status:", res.Status)
}

type UpdateInvoiceRequest struct {
	IsUncollectible         bool              `json:"is_uncollectible"`
	BillMailSendFlag        string            `json:"bill_mail_send_flag"`
	ReceiptMailSendFlag     string            `json:"receipt_mail_send_flag"`
	UnderpaymentMailSendFlag string            `json:"underpayment_mail_send_flag"`
	InvoiceNumber           string            `json:"invoice_number"`
	CustomerID              string            `json:"customer_id"`
	CustomerHonorific       string            `json:"customer_honorific"`
	CustomerOverwrite       CustomerOverwrite `json:"customer_overwrite"`
	IssuerOverwrite         IssuerOverwrite   `json:"issuer_overwrite"`
	Lines                   []Line            `json:"lines"`
	PayTypes                []string          `json:"pay_types"`
}

type CustomerOverwrite struct {
	Name        string `json:"name"`
	Email       string `json:"email"`
	AddrCountry string `json:"addr_country"`
	AddrState   string `json:"addr_state"`
	AddrCity    string `json:"addr_city"`
	AddrLine1   string `json:"addr_line_1"`
	AddrLine2   string `json:"addr_line_2"`
	AddrLine3   string `json:"addr_line_3,omitempty"`
	AddrPostCode string `json:"addr_post_code"`
}

type IssuerOverwrite struct {
	AddrCountry string `json:"addr_country"`
	AddrState   string `json:"addr_state"`
	AddrCity    string `json:"addr_city"`
	AddrLine1   string `json:"addr_line_1"`
	AddrLine2   string `json:"addr_line_2"`
	AddrLine3   string `json:"addr_line_3,omitempty"`
	AddrPostCode string `json:"addr_post_code"`
	Email       string `json:"email"`
	PhoneNumber string `json:"phone_number"`
}

type Line struct {
	Date      string `json:"date"`
	Name      string `json:"name"`
	UnitPrice int    `json:"unit_price"`
	Quantity  int    `json:"quantity"`
	TaxRate   int    `json:"tax_rate"`
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';
$invoiceId = '<Invoice ID>';  // ここにInvoice IDを設定

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/invoices/{$invoiceId}";

$headers = [
    "Authorization: Bearer " . $apiKey,
    "Content-Type: application/json"
];

$data = json_encode([
    "is_uncollectible" => false,
    "bill_mail_send_flag" => "0",
    "receipt_mail_send_flag" => "0",
    "underpayment_mail_send_flag" => "0",
    "invoice_number" => "INV123456",
    "customer_id" => "CUST001",
    "customer_honorific" => "様",
    "customer_overwrite" => [
        "name" => "株式会社テスト",
        "email" => "test@example.com",
        "addr_country" => "JP",
        "addr_state" => "13",
        "addr_city" => "新宿区",
        "addr_line_1" => "1-1-1",
        "addr_line_2" => "テストビル",
        "addr_line_3" => "",
        "addr_post_code" => "1600022"
    ],
    "issuer_overwrite" => [
        "addr_country" => "JP",
        "addr_state" => "13",
        "addr_city" => "新宿区",
        "addr_line_1" => "1-1-1",
        "addr_line_2" => "テストビル",
        "addr_line_3" => "",
        "addr_post_code" => "1600022",
        "email" => "issuer@example.com",
        "phone_number" => "0312345678"
    ],
    "lines" => [
        [
            "date" => "2023/10/01",
            "name" => "商品A",
            "unit_price" => 1000,
            "quantity" => 2,
            "tax_rate" => 10
        ]
    ],
    "pay_types" => [
        "Virtualaccount",
        "Card"
    ]
]);

$session = curl_init();
curl_setopt($session, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($session, CURLOPT_SSL_VERIFYPEER, true);
// curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 2);

$response = curl_exec($session);

if ($response === false) {
    // エラー処理
    echo "cURL Error: " . curl_error($session);
} else {
    // APIからのデータを処理
    var_dump($response);
}

curl_close($session);
```

### Python 3

```python
import requests

api_key = '<Secret API Key>'
invoice_id = '<Invoice ID>'  # ここにInvoice IDを設定

url = f'https://api.test.fincode.jp/v1/invoices/{invoice_id}'

# ヘッダーを設定
headers = {
    'Authorization': f'Bearer {api_key}',
    'Content-Type': 'application/json'
}

data = {
    "is_uncollectible": False,
    "bill_mail_send_flag": "0",
    "receipt_mail_send_flag": "0",
    "underpayment_mail_send_flag": "0",
    "invoice_number": "INV123456",
    "customer_id": "CUST001",
    "customer_honorific": "様",
    "customer_overwrite": {
        "name": "株式会社テスト",
        "email": "test@example.com",
        "addr_country": "JP",
        "addr_state": "13",
        "addr_city": "新宿区",
        "addr_line_1": "1-1-1",
        "addr_line_2": "テストビル",
        "addr_line_3": "",
        "addr_post_code": "1600022"
    },
    "issuer_overwrite": {
        "addr_country": "JP",
        "addr_state": "13",
        "addr_city": "新宿区",
        "addr_line_1": "1-1-1",
        "addr_line_2": "テストビル",
        "addr_line_3": "",
        "addr_post_code": "1600022",
        "email": "issuer@example.com",
        "phone_number": "0312345678"
    },
    "lines": [
        {
            "date": "2023/10/01",
            "name": "商品A",
            "unit_price": 1000,
            "quantity": 2,
            "tax_rate": 10
        }
    ],
    "pay_types": [
        "Virtualaccount",
        "Card"
    ]
}

# HTTP PUTリクエストの送信
try:
    response = requests.put(url, headers=headers, json=data)

    # レスポンスの処理
    if response.status_code == 200:
        # 成功した場合の処理
        print(f"Success: {response.json()}")
    else:
        # エラーの処理
        print(f"Error: {response.json()}")
except requests.RequestException as e:
    # 通信エラーの処理
    print(f"Request error: {e}")
```

### Ruby

```ruby
require 'net/http'
require 'uri'
require 'json'

API_KEY = '<Secret API Key>'
BASE_URL = 'https://api.test.fincode.jp'

def main
    invoice_id = '<Invoice ID>'  # ここにInvoice IDを設定
    endpoint = "/v1/invoices/#{invoice_id}"
    
    uri = URI.parse(BASE_URL + endpoint)

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    data = {
        is_uncollectible: false,
        bill_mail_send_flag: "0",
        receipt_mail_send_flag: "0",
        underpayment_mail_send_flag: "0",
        invoice_number: "INV123456",
        customer_id: "CUST001",
        customer_honorific: "様",
        customer_overwrite: {
            name: "株式会社テスト",
            email: "test@example.com",
            addr_country: "JP",
            addr_state: "13",
            addr_city: "新宿区",
            addr_line_1: "1-1-1",
            addr_line_2: "テストビル",
            addr_line_3: "",
            addr_post_code: "1600022"
        },
        issuer_overwrite: {
            addr_country: "JP",
            addr_state: "13",
            addr_city: "新宿区",
            addr_line_1: "1-1-1",
            addr_line_2: "テストビル",
            addr_line_3: "",
            addr_post_code: "1600022",
            email: "issuer@example.com",
            phone_number: "0312345678"
        },
        lines: [
            {
                date: "2023/10/01",
                name: "商品A",
                unit_price: 1000,
                quantity: 2,
                tax_rate: 10
            }
        ],
        pay_types: [
            "Virtualaccount",
            "Card"
        ]
    }

    # リクエストの作成
    request = Net::HTTP::Put.new(uri.request_uri)
    request['Authorization'] = "Bearer #{API_KEY}"
    request['Content-Type'] = 'application/json'

    request.body = data.to_json

    # リクエストの送信
    response = http.request(request)

    case response
    when Net::HTTPSuccess
        puts 'SUCCESS'
    else
        puts 'ERROR'
    end

    # レスポンスの表示
    puts response.body
end

main
```

## パラメータ

| 名前 | 位置 | 必須 | 型 | 説明 |
| --- | --- | --- | --- | --- |
| `Tenant-Shop-Id` | header |  | schema | <span class="smallText color--red-400">※ プラットフォームのメインショップのみ指定可</span> |
| `id` | path | ✓ | string | インボイスID |

## リクエストボディ

Content-Type: `application/json`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `is_uncollectible` | boolean |  | 回収困難フラグ |
| `bill_mail_send_flag` | string |  | 請求書メール送信フラグ |
| `receipt_mail_send_flag` | string |  | 領収書メール送信フラグ |
| `underpayment_mail_send_flag` | string |  | 差額請求メール送信フラグ |
| `invoice_number` | string |  | 請求番号 |
| `customer_id` | string |  | 顧客（請求先）ID |
| `customer_honorific` | string |  | 顧客（請求先）敬称 |
| `customer_overwrite` | object |  | 上書き顧客（請求先）情報 |
| `issuer_overwrite` | object |  | 発行元事業者情報 |
| `is_tax_included` | boolean |  | 内税表記有無 |
| `due_date` | string |  | 支払期日 |
| `memo` | string |  | 備考 |
| `lines` | array<object> |  | 取引内容 |
| `pay_types` | array<string> |  | ショップで利用可能な決済種別のリスト |
| `input_type` | input_type |  |  |
| `card` | object |  | カード決済情報 |
| `virtual_account` | object |  | 銀行振込（バーチャル口座）情報 |
| `directdebit` | object |  | 口座振替情報 |
| `payee_account` | object |  | 銀行振込（指定口座）情報 |
| `client_field_1` | string |  | 加盟店自由項目1 |
| `client_field_2` | string |  | 加盟店自由項目2 |
| `client_field_3` | string |  | 加盟店自由項目3 |
| `invoice_backfill` | object |  | 領収書後付け発行情報 |

## レスポンス

### 200 リクエストに成功

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | インボイスID |
| `status` | string |  | インボイス請求書のステータス |
| `invoice_url` | string |  | インボイス 請求ページURL |
| `bill_mail_send_flag` | enum(0 | 1) |  | 請求書メール送信フラグ (0: メールを送信しない 1: メールを送信する) |
| `bill_pdf_url` | string |  | [非推奨] インボイス請求書PDFダウンロードURL |
| `receipt_mail_send_flag` | enum(0 | 1) |  | 領収書メール送信フラグ (0: メールを送信しない 1: メールを送信する) |
| `underpayment_mail_send_flag` | enum(0 | 1) |  | 差額請求メール送信フラグ (0: メールを送信しない 1: メールを送信する) |
| `receipt_pdf_url` | string |  | [非推奨] インボイス領収書PDFダウンロードURL |
| `invoice_number` | string |  | 請求番号 |
| `customer_id` | string |  | 顧客（請求先）ID |
| `customer_honorific` | string |  | 顧客（請求先）敬称 |
| `customer` | object |  | 顧客（請求先）情報 |
| `customer_overwrite` | object |  | 上書き顧客（請求先）情報 |
| `issuer` | object |  | 発行元事業者情報 |
| `issuer_overwrite` | object |  | 上書き発行元事業者情報 |
| `issue_date` | string |  | 発行年月日 |
| `lines` | array<object> |  | 取引内容レコード |
| `total_amount` | number |  | 合計金額 |
| `billing_total_amount` | number |  | 請求金額合計 |
| `pay_types` | array<string> |  | 利用可能な決済種別リスト |
| `input_type` | enum(amount) |  | 取引金額の入力方式 |
| `card` | object |  | カード決済情報 |
| `virtual_account` | object |  | 銀行振込（バーチャル口座）情報 |
| `embedded_virtual_account` | object |  | このインボイス情報に対して発行されたバーチャル口座情報 |
| `is_tax_included` | boolean |  | 内税表記有無 |
| `due_date` | string |  | 支払期日 |
| `memo` | string |  | 備考 |
| `client_field_1` | string |  | 加盟店自由項目1 |
| `client_field_2` | string |  | 加盟店自由項目2 |
| `client_field_3` | string |  | 加盟店自由項目3 |
| `is_uncollectible` | boolean |  | 回収困難フラグ |
| `is_paid_externally` | boolean |  | M's PayBridge外支払フラグ |
| `transaction_date` | string |  | 支払完了日 |
| `bill_id` | string |  | 請求ID |
| `directdebit` | object |  | 口座振替情報 |
| `payee_account` | object |  | 銀行振込（指定口座）情報 |
| `embedded_directdebit` | object |  | このインボイス情報に対する口座振替の口座情報 この口座から引き落とし完了することでインボイスによる請求に対して支払いできます。 |
| `embedded_payee_accounts` | array<object> |  | このインボイス情報に対する銀行振込（指定口座）口座情報 この口座情報に対して振込を行うことでインボイスによる請求に対して支払いできます。 |
| `billing_file_import_entry_id` | string |  | 請求インポートファイル読み込みエントリーID |
| `trade_client_field_1` | string |  | 決済情報自由項目 1 |
| `trade_client_field_2` | string |  | 決済情報自由項目 2 |
| `trade_client_field_3` | string |  | 決済情報自由項目 3 |
| `invoice_backfill` | object |  | 後付け請求情報 |
| `created` | string |  | 作成日時 |
| `updated` | string |  | 更新日時 |

### 400 不正なリクエスト

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `errors` | array<FincodeAPIError> |  |  |

