# Webhook設定 登録

`POST /v1/webhook_settings`

- operationId: `createWebhookSetting`
- tags: Webhook設定

Webhook設定を登録します。


## コードサンプル

### cURL

```bash
curl \
    -X POST \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
    "event": "payments.card.secure",
    "url": "https://your-service.example.com/webhook-receiver",
}' \
'https://api.test.fincode.jp/v1/webhook_settings'
```

### Node.js

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

const API_KEY = "<Secret API Key>";

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

    try {
        // リクエストの送信
        const webhookSetting = await fincode.webhookSettings.create({
            url: "https://your-service.example.com/webhook-receiver",
            event: "payments.card.secure",
            signature: "WEBHOOK_FROM_FINCODE",
        });
    } catch (e) {
        // エラーの処理
    }
})();
```

### Go

```go
package main

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

func main() {

	apiKey := "<Secret API Key>"

	body := CreatingWebhookSettingRequest{
		URL:       stringPointer("https://your-service.example.com/webhook-receiver"),
		Event:     stringPointer("payments.card.secure"),
		Signature: stringPointer("WEBHOOK_FROM_FINCODE"),
	}

	marshalledBody, _ := json.Marshal(body)

	// リクエストの作成
	req, _ := http.NewRequest("POST", "https://api.test.fincode.jp/v1/webhook_settings", 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 CreatingWebhookSettingRequest struct {
	ID        *string `json:"id"`
	URL       *string `json:"url"`
	Event     *string `json:"event"`
	Signature *string `json:"signature"`
}

func stringPointer(s string) *string {
	return &s
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';

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

$data = json_encode([
    "url" => "https://your-service.example.com/webhook-receiver",
    "event" => "payments.card.secure",
    "signature" => "WEBHOOK_FROM_FINCODE"
]);

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

url = f'https://api.test.fincode.jp/v1/webhook_settings'

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

data = {
    "event": "payments.card.secure",
    "url": "https://your-service.example.com/webhook-receiver",
    "signature": "WEBHOOK_FROM_FINCODE"
}

# HTTP POSTリクエストの送信
try:
    response = requests.post(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
    endpoint = "/v1/webhook_settings"
    uri = URI.parse(BASE_URL + endpoint)

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

    data = {
        event: "payments.card.secure",
        url: "https://your-service.example.com/webhook-receiver",
        signature: "WEBHOOK_FROM_FINCODE"
    }

    # リクエストの作成
    request = Net::HTTP::Post.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-Buyer-Id` | header | ✓ | schema | <span class="smallText color--red-400">※ バイヤープラットフォームのみ指定可</span> |

## リクエストボディ

Content-Type: `application/json`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | WebhookSetting_properties-id |  |  |
| `url` | url |  |  |
| `event` | FincodeEventForBuyerPlatform | ✓ |  |
| `signature` | signature |  |  |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | Webhook設定ID |
| `url` | string(uri) |  | Webhook通知先 URL |
| `event` | FincodeEventForBuyerPlatform |  |  |
| `signature` | string |  | 署名 |
| `created` | created |  |  |
| `updated` | updated |  |  |

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

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

