# バーコード発行

`PUT /v1/payments/{id}/barcode`

- operationId: `generateBarcodeOfPayment`
- tags: 決済

リクエストしたデバイスの情報に合わせてコンビニ決済のバーコードを再度発行します。


## コードサンプル

### cURL

```bash
curl \
    -X PUT \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
    "pay_type": "Konbini",
    "access_id": "<Access ID>",
    "device_name": "iPhone",
    "win_width": "390",
    "win_height": "844",
    "pixel_ratio": "3.00",
    "win_size_type": "2"
}' \
'https://api.test.fincode.jp/v1/payments/{id}/barcode'
```

### Node.js

```javascript
import { createFincode } from "@fincode/node";

const API_KEY = "<Secret API Key>";

(async () => {
    const fincode = createFincode({ apiKey: API_KEY, isLiveMode: false });

    const orderId = "<Order ID>";
    const accessId = "<Access ID>";

    const payment = await fincode.payments.generateKonbiniPaymentBarcode(
        orderId,
        {
            access_id: accessId,
            pay_type: "Konbini",
            device_name: "iPhone",
            win_width: "390",
            win_height: "844",
            pixel_ratio: "3.00",
            win_size_type: "2",
        }
    );
})();
```

### Go

```go
package main

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

func main() {

	apiKey := "<Secret API Key>"

	orderID := "<Order ID>"

	body := GeneratingBarcodeRequest{
		PayType:     "Konbini",
		AccessID:    "<Access ID>",
		DeviceName:  "iPhone",
		WinWidth:    "390",
		WinHeight:   "844",
		PixelRatio:  "3.00",
		WinSizeType: "2",
	}

	marshalledBody, _ := json.Marshal(body)

	// リクエストの作成
	req, _ := http.NewRequest(
		"PUT",
		fmt.Sprintf("https://api.test.fincode.jp/v1/payments/%s/barcode", orderID),
		bytes.NewBuffer(marshalledBody),
	)
	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.Fatal(err)
	}
	defer res.Body.Close()

}

type GeneratingBarcodeRequest struct {
	PayType     string `json:"pay_type"`
	AccessID    string `json:"access_id"`
	DeviceName  string `json:"device_name"`
	WinWidth    string `json:"win_width"`
	WinHeight   string `json:"win_height"`
	PixelRatio  string `json:"pixel_ratio"`
	WinSizeType string `json:"win_size_type"`
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';

$orderId = '<Order ID>';

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

$data = json_encode([
    "pay_type" => "Konbini",
    "access_id" => "<Access ID>",
    "device_name" => "iPhone",
    "win_width" => "390",
    "win_height" => "844",
    "pixel_ratio" => "3.00",
    "win_size_type" => "2"
]);

$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, );
// curl_setopt($session, CURLOPT_SSL_VERIFYHOST, );

$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>'

order_id = '<Order ID>'

url = f'https://api.test.fincode.jp/v1/payments/{order_id}/barcode'

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

data = {
    "pay_type": "Konbini",
    "access_id": "<Access ID>",
    "device_name": "iPhone",
    "win_width": "390",
    "win_height": "844",
    "pixel_ratio": "3.00",
    "win_size_type": "2"
}

# HTTP POSTリクエストの送信
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
    order_id = '<Order ID>'
    endpoint = "/v1/payments/#{order_id}/barcode"
    
    uri = URI.parse(BASE_URL + endpoint)

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

    data = {
        pay_type: "Konbini",
        access_id: "<Access ID>",
        device_name: "iPhone",
        win_width: "390",
        win_height: "844",
        pixel_ratio: "3.00",
        win_size_type: "2" 
    }

    # リクエストの作成
    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 | ✓ | OrderId_schema | オーダーID（決済情報のID） |

## リクエストボディ

Content-Type: `application/json`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `pay_type` | PayType | ✓ | 決済種別 |
| `access_id` | access_id | ✓ |  |
| `device_name` | device_name | ✓ |  |
| `win_width` | win_width | ✓ |  |
| `win_height` | win_height | ✓ |  |
| `pixel_ratio` | pixel_ratio | ✓ |  |
| `win_size_type` | win_size_type | ✓ |  |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `shop_id` | Shop_properties-id |  |  |
| `id` | string |  | オーダーID |
| `access_id` | string |  | 取引ID |
| `amount` | integer |  | 利用金額 |
| `tax` | integer |  | 税送料 |
| `total_amount` | integer(int64) |  | 合計金額 |
| `client_field_1` | client_field_n |  | 加盟店自由項目 1 |
| `client_field_2` | client_field_n |  | 加盟店自由項目 2 |
| `client_field_3` | client_field_n |  | 加盟店自由項目 3 |
| `process_date` | string |  | 決済 処理日時 |
| `customer_id` | id |  | 顧客ID |
| `customer_group_id` | string |  | 顧客情報共有グループID |
| `error_code` | error_code |  | この決済において発生したエラーのうち、一番最新のエラーのエラーコードです。 |
| `bill_id` | string |  | 請求ID |
| `created` | created |  |  |
| `updated` | updated |  |  |
| `pay_type` | PayType |  | 決済種別 |
| `status` | PaymentStatus |  | 決済ステータス |
| `payment_term_day` | integer(int64) |  | 支払い期限日数 |
| `payment_term` | string |  | 支払い期限日時 |
| `payment_date` | string |  | 支払日時 |
| `barcode` | string |  | バーコード画像 Base64エンコード済み画像データ |
| `barcode_format` | enum(jpg | png | bmp) |  | バーコード画像 フォーマット |
| `barcode_width` | string |  | バーコード画像 横幅（px） |
| `barcode_height` | string |  | バーコード画像 縦幅（px） |
| `overpayment_flag` | enum(0 | 1) |  | 多重支払フラグ |
| `cancel_overpayment_flag` | enum(0 | 1) |  | キャンセル後支払フラグ |
| `konbini_code` | KonbiniCode |  |  |
| `konbini_store_code` |  |  | コンビニ店舗コード |
| `device_name` | device_name |  |  |
| `os_version` |  |  | OSバージョン |
| `win_width` | win_width |  |  |
| `win_height` | win_height |  |  |
| `xdpi` |  |  | 画面横幅のDPI |
| `ydpi` |  |  | 画面縦幅のDPI |
| `result` | KonbiniPaymentProcessResult |  |  |
| `order_serial` | string |  | 注文管理ID |
| `invoice_id` | string |  | 請求ID |

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

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

