# カード登録URL 作成

`POST /v1/card_sessions`

- operationId: `createCardRegistrationSession`
- tags: リダイレクト型カード登録

fincodeが提供するリダイレクト型カード登録ページを発行し、そのカード登録ページへのURLをレスポンスします。


## コードサンプル

### cURL

```bash
curl \
    -X POST \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
    "success_url": "http://your-service.example.com/success",
    "cancel_url": "http://your-service.example.com/cancel",
}' \
'https://api.test.fincode.jp/v1/card_sessions'
```

### 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 cardRegistrationSession =
            await fincode.cardRegistrationSessions.create({
                success_url: "https://your-service.example.com/success",
                cancel_url: "https://your-service.example.com/cancel",
            });
    } catch (e) {
        // エラーの処理
    }
})();
```

### Go

```go
package main

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

func main() {

	apiKey := "<Secret API Key>"

	body := PaymentSessionCreatingRequest{
		SuccessURL: "https://your-service.example.com/success",
		CancelURL:  "https://your-service.example.com/cancel",
		Transaction: Transaction{
			PayType: []string{"Card"},
			Amount:  "1234",
		},
	}

	marshalledBody, _ := json.Marshal(body)

	// リクエストの作成
	req, _ := http.NewRequest("POST", "https://api.test.fincode.jp/v1/card_sessions", 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 PaymentSessionCreatingRequest struct {
	SuccessURL  string      `json:"success_url"`
	CancelURL   string      `json:"cancel_url"`
	Transaction Transaction `json:"transaction"`
}

type Transaction struct {
	PayType []string `json:"pay_type"`
	Amount  string   `json:"amount"`
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';

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

$data = json_encode([
    "success_url" => "http://your-service.example.com/success",
    "cancel_url" => "http://your-service.example.com/cancel",
]);

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

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

data = {
    "success_url": "http://your-service.example.com/success",
    "cancel_url": "http://your-service.example.com/cancel",
}

# 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/card_sessions"
    uri = URI.parse(BASE_URL + endpoint)

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


    data = {
        success_url: "http://your-service.example.com/success",
        cancel_url: "http://your-service.example.com/cancel",
    }

    # リクエストの作成
    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-Shop-Id` | header |  | schema | <span class="smallText color--red-400">※ 顧客情報を共有しないプラットフォームのメインショップのみ指定可</span> |

## リクエストボディ

Content-Type: `application/json`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `success_url` | properties-success_url |  |  |
| `cancel_url` | properties-cancel_url |  |  |
| `expire` | CardRegistrationSession_properties-expire |  | リダイレクト型カード登録URL 有効期限 |
| `shop_service_name` | properties-shop_service_name |  |  |
| `receiver_mail` | properties-receiver_mail |  |  |
| `mail_customer_name` | properties-mail_customer_name |  |  |
| `guide_mail_send_flag` | properties-guide_mail_send_flag |  |  |
| `completion_mail_send_flag` | completion_mail_send_flag |  |  |
| `shop_mail_template_id` | properties-shop_mail_template_id |  |  |
| `customer_id` | CardRegistrationSession_properties-customer_id |  |  |
| `customer_name` | customer_name |  |  |
| `td_tenant_name` | td_tenant_name |  |  |
| `tds_type` | tds_type |  |  |
| `tds2_type` | tds2_type |  |  |
| `tds2_ch_acc_change` | tds2_ch_acc_change |  |  |
| `tds2_ch_acc_date` | tds2_ch_acc_date |  |  |
| `tds2_ch_acc_pw_change` | tds2_ch_acc_pw_change |  |  |
| `tds2_nb_purchase_account` | tds2_nb_purchase_account |  |  |
| `tds2_payment_acc_age` | tds2_payment_acc_age |  |  |
| `tds2_provision_attempts_day` | tds2_provision_attempts_day |  |  |
| `tds2_ship_address_usage` | tds2_ship_address_usage |  |  |
| `tds2_ship_name_ind` | tds2_ship_name_ind |  |  |
| `tds2_suspicious_acc_activity` | tds2_suspicious_acc_activity |  |  |
| `tds2_txn_activity_day` | tds2_txn_activity_day |  |  |
| `tds2_txn_activity_year` | tds2_txn_activity_year |  |  |
| `tds2_three_ds_req_auth_data` | tds2_three_ds_req_auth_data |  |  |
| `tds2_three_ds_req_auth_method` | tds2_three_ds_req_auth_method |  |  |
| `tds2_three_ds_req_auth_timestamp` | tds2_three_ds_req_auth_timestamp |  |  |
| `tds2_email` | tds2_email |  |  |
| `tds2_addr_match` | tds2_addr_match |  |  |
| `tds2_bill_addr_country` | tds2_bill_addr_country |  |  |
| `tds2_bill_addr_state` | tds2_bill_addr_state |  |  |
| `tds2_bill_addr_city` | tds2_bill_addr_city |  |  |
| `tds2_bill_addr_line_1` | tds2_bill_addr_line_1 |  |  |
| `tds2_bill_addr_line_2` | tds2_bill_addr_line_2 |  |  |
| `tds2_bill_addr_line_3` | tds2_bill_addr_line_3 |  |  |
| `tds2_bill_addr_post_code` | tds2_bill_addr_post_code |  |  |
| `tds2_ship_addr_country` | tds2_ship_addr_country |  |  |
| `tds2_ship_addr_state` | tds2_ship_addr_state |  |  |
| `tds2_ship_addr_city` | tds2_ship_addr_city |  |  |
| `tds2_ship_addr_line_1` | tds2_ship_addr_line_1 |  |  |
| `tds2_ship_addr_line_2` | tds2_ship_addr_line_2 |  |  |
| `tds2_ship_addr_line_3` | tds2_ship_addr_line_3 |  |  |
| `tds2_ship_addr_post_code` | tds2_ship_addr_post_code |  |  |
| `tds2_ship_ind` | tds2_ship_ind |  |  |
| `tds2_delivery_email_address` | tds2_delivery_email_address |  |  |
| `tds2_home_phone_cc` | tds2_home_phone_cc |  |  |
| `tds2_home_phone_no` | tds2_home_phone_no |  |  |
| `tds2_mobile_phone_cc` | tds2_mobile_phone_cc |  |  |
| `tds2_mobile_phone_no` | tds2_mobile_phone_no |  |  |
| `tds2_work_phone_cc` | tds2_work_phone_cc |  |  |
| `tds2_work_phone_no` | tds2_work_phone_no |  |  |
| `tds2_delivery_timeframe` | tds2_delivery_timeframe |  |  |
| `tds2_pre_order_date` | tds2_pre_order_date |  |  |
| `tds2_pre_order_purchase_ind` | tds2_pre_order_purchase_ind |  |  |
| `tds2_reorder_items_ind` | tds2_reorder_items_ind |  |  |
| `tds2_recurring_expiry` | tds2_recurring_expiry |  |  |
| `tds2_recurring_frequency` | tds2_recurring_frequency |  |  |
| `tds2_gift_card_amount` | tds2_gift_card_amount |  |  |
| `tds2_gift_card_count` | tds2_gift_card_count |  |  |
| `tds2_gift_card_curr` | tds2_gift_card_curr |  |  |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | リダイレクト型カード登録URL ID |
| `link_url` | string |  | リダイレクト型カード登録URL |
| `success_url` | string |  | 成功時リダイレクトURL |
| `cancel_url` | string |  | キャンセル時リダイレクトURL |
| `status` | CardRegistrationSessionStatus |  |  |
| `expire` | string |  | リダイレクト型カード登録URL 有効期限 |
| `shop_service_name` | string |  | ショップ／サービス名 |
| `guide_mail_send_flag` | enum(0 | 1) |  | カード登録メール 送信フラグ |
| `receiver_mail` | string |  | カード登録メール 送信先メールアドレス |
| `mail_customer_name` | string |  | カード登録メール カード登録をするユーザーの名前 |
| `completion_mail_send_flag` | enum(0 | 1) |  | 完了メール 送信フラグ |
| `shop_mail_template_id` | string |  | メールテンプレートID |
| `customer_id` | id |  | 顧客ID |
| `customer_name` | string |  | 顧客名 |
| `tds_type` | tds_type |  |  |
| `td_tenant_name` | td_tenant_name |  |  |
| `tds2_type` | tds2_type |  |  |
| `created` | created |  |  |
| `updated` | updated |  |  |

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

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

