# 一括決済 登録

`POST /v1/payments/bulk`

- operationId: `createPaymentBulk`
- tags: 一括決済

fincodeにJSON形式のファイルで一括決済情報を登録し、`process_plan_date`で指定した日時に一括決済処理を予約します。


## コードサンプル

### cURL

```bash
curl \
    -X POST \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: multipart/form-data" \
    -F 'pay_type=Card' \
    -F 'process_plan_date=2024/03/15' \
    -F 'file=@<File Name>;type=application/json' \
'https://api.test.fincode.jp/v1/payments/bulk'
```

### Node.js

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

const API_KEY = "<Secret API Key>";

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

    try {
        const filePath = "<Path to File>";
        const fileName = "<File Name>";
        const file = fs.createReadStream(filePath);

        // リクエストの送信
        const paymentBulk = await fincode.paymentBulks.create(
            {
                pay_type: "Card",
                process_plan_date: "2022/05/16",
            },
            {
                file: file,
                fileName: fileName,
            }
        );
    } catch (e) {
        // エラーの処理
    }
})();
```

### Go

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"log"
	"mime/multipart"
	"net/http"
	"os"
)

func main() {

	apiKey := "<Secret API Key>"

	payType := "<Pay Type>"
	processPlanDate := "<Process Plan Date>"

	// ファイルの読み込み
	filePath := "<Path To File>"
	fileName := "<File Name>"
	file, err := os.Open(filePath)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	// バッファの作成
	body := &bytes.Buffer{}
	writer := multipart.NewWriter(body)

	// ファイルの書き込み
	part, err := writer.CreateFormFile("file", fileName)
	if err != nil {
		log.Fatal(err)
	}
	_, err = io.Copy(part, file)
	if err != nil {
		log.Fatal(err)
	}

	// リクエストの作成
	req, _ := http.NewRequest(
		"POST",
		fmt.Sprintf("https://api.test.fincode.jp/v1/payments/bulk"),
		body,
	)
	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
	req.Header.Set("Content-Type", writer.FormDataContentType())

	params := req.URL.Query()
	params.Add("process_plan_date", processPlanDate)
	params.Add("pay_type", payType)
	req.URL.RawQuery = params.Encode()

	// リクエストの送信
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/payments/bulk";
$queryParams = [
    "pay_type" => "Card",
    "process_plan_date" => "2022/05/16",
];

$headers = [
    "Authorization: Bearer " . $apiKey,
];

$filePath = '<Path to json file>';
$fileName = '<File Name>';

$fields = [
    "file" => new CURLFile($filePath, null, $fileName),
];

$session = curl_init();
curl_setopt($session, CURLOPT_URL, $baseUrl . $endpoint . '?' . http_build_query($queryParams));
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $fields);
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

def main():
    api_key = '<Secret API Key>'

    file_path = '<Path to file>'
    file_name = '<File Name>'
    
    with open(file_path, 'rb') as file:
        files = {'file': (file_name, file)}

        url = f'https://api.test.fincode.jp/v1/payments/bulk'
        query_params = {
            'pay_type': 'Card',
            'process_plan_date': "2022/05/22"
        }

        # ヘッダーを設定
        headers = {
            'Authorization': f'Bearer {api_key}',
        }

        # HTTP POSTリクエストの送信
        try:
            response = requests.post(url, headers=headers, files=files, params=query_params)

            # レスポンスの処理
            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}")

if __name__ == '__main__':
    main()
```

### Ruby

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

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

def main
    endpoint = "/v1/payments/bulk"
    query_params =  {
        pay_type: 'Card',
        process_plan_date: '2025/12/31',
    }
    
    uri = URI.parse(BASE_URL + endpoint)
    uri.query = URI.encode_www_form(query_params)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    file_path = '<Path to file>'
    file_name = '<File Name>'
    
    file = File.open(file_path, 'rb')
    file_data = file.read
    file.close

    # リクエストの作成
    request = Net::HTTP::Post.new(uri.request_uri)
    request['Authorization'] = "Bearer #{API_KEY}"

    # ファイルと追加情報をマルチパートフォームデータに追加
    boundary = '----FincodeMultipartRequest'
    body = []
    insert_file_to_body(body, boundary, 'file', file_name, file_data)
    body << "--#{boundary}--\r\n"

    request['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
    request.body = body.join('')

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

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

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

def insert_file_to_body(body, boundary, key, file_name, file_data)
    body << "--#{boundary}\r\n"
    body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{file_name}\"\r\n"
    body << "Content-Type: #{MIME::Types.type_for(file_name).first.content_type}\r\n"
    body << "\r\n"
    body << file_data
    body << "\r\n"
end

main
```

## パラメータ

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

## リクエストボディ

Content-Type: `multipart/form-data`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `file` | file |  |  |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | 一括決済ID |
| `shop_id` | Shop_properties-id |  |  |
| `pay_type` | PaymentBulkPayType |  |  |
| `status` | PaymentBulkStatus |  |  |
| `process_plan_date` | string |  | 一括決済 処理予定日 |
| `file_name` | string |  | 一括決済データファイル名 |
| `process_start_date` | string |  | 一括決済 処理開始日時 |
| `process_end_date` | string |  | 一括決済 処理終了日時 |
| `total_count` | integer(int32) |  | 一括決済 総件数 |
| `process_success_count` | integer(int32) |  | 一括決済 成功件数 |
| `process_failure_count` | integer(int32) |  | 一括決済 失敗件数 |
| `error_code` | error_code |  | この一括決済において発生したエラーのうち、一番最新のエラーのエラーコードです。 |
| `delete_flag` | delete_flag |  |  |
| `created` | created |  |  |
| `updated` | updated |  |  |

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

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

