# 請求 バーチャル口座再発行

`PUT /v1/billings/{id}/virtual_account/refresh`

- operationId: `refreshBillingsVirtualaccount`
- tags: 請求管理

指定した請求に割り当てられているバーチャル口座について、期限が切れていて口座がクローズされている場合、新たなバーチャル口座を割り当てます。


## コードサンプル

### cURL

```bash
curl \
    -X PUT \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
\
'https://api.test.fincode.jp/v1/billings/{id}/virtual_account/refresh'
```

### Node.js

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

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

(async () => {
    const billingId = "<Billing ID>";

    const endpoint = `${BASE_URL}/v1/billings/${billingId}/virtual_account/refresh`;

    const response = await fetch(endpoint, {
        method: "PUT",
        headers: {
            Authorization: `Bearer ${API_KEY}`,
            "Content-Type": "application/json",
        },
    });

    if (!response.ok) {
        console.error("Error refreshing virtual account:", await response.text());
    } else {
        const result = await response.json();
        console.log("Virtual account refresh successful:", result);
    }
})();
```

### Go

```go
package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {
	// APIキーと請求IDを指定
	apiKey := "<Secret API Key>"
	billingID := "<Billing ID>" // 請求IDを指定

	// URLの設定
	url := fmt.Sprintf("https://api.test.fincode.jp/v1/billings/%s/virtual_account/refresh", billingID)

	// HTTPリクエストの作成
	req, err := http.NewRequest("PUT", url, nil)
	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)
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';
$billingId = '<Billing ID>';

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/billings/{$billingId}/virtual_account/refresh";
$headers = [
    "Authorization: Bearer " . $apiKey,
    "Content-Type: application/json"
];

$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_RETURNTRANSFER, true);

$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>'
billing_id = '<Billing ID>'

url = f'https://api.test.fincode.jp/v1/billings/{billing_id}/virtual_account/refresh'

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

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

    # レスポンスの処理
    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
    billing_id = '<Billing ID>'
    endpoint = "/v1/billings/#{billing_id}/virtual_account/refresh"

    uri = URI.parse(BASE_URL + endpoint)

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

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

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

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

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

main
```

## パラメータ

| 名前 | 位置 | 必須 | 型 | 説明 |
| --- | --- | --- | --- | --- |
| `id` | path | ✓ | string | 請求ID |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | 請求ID |
| `bill_type` | string |  | 請求方式 |
| `status` | string |  | 請求のステータス |
| `customer_id` | string |  | 顧客（請求先）ID |
| `customer_honorific` | string |  | 顧客（請求先）敬称 |
| `customer` | object |  | 顧客（請求先）情報 |
| `customer_overwrite` | object |  | 上書き顧客（請求先）情報 |
| `issuer` | object |  | 発行元事業者情報 |
| `issuer_overwrite` | object |  | 上書き発行元事業者情報 |
| `issue_date` | string |  | 発行年月日 形式： `yyyy/MM/dd` |
| `is_tax_included` | boolean |  | 内税表記有無 |
| `due_date` | string |  | 支払期日 形式： `yyyy/MM/dd` |
| `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 |  | 支払完了日 形式： `yyyy/MM/dd` |
| `total_amount` | string |  | 合計金額 |
| `billing_total_amount` | string |  | 合計請求金額 |
| `pay_types` | array<string> |  | 利用可能な決済種別リスト |
| `input_type` | enum(amount) |  | 取引金額の入力方式 |
| `used_pay_type` | string |  | 利用された決済種別 |
| `invoice` | object |  | インボイスに関する情報 |
| `link_type` | object |  | リダイレクト型決済に関する情報 |
| `draft` | 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 |
| `created` | string |  | 作成日時 形式： `yyyy/MM/dd HH:mm:ss.SSS` |
| `updated` | string |  | 更新日時 形式： `yyyy/MM/dd HH:mm:ss.SSS` |

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

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

