注文作成前にチェックアウトセッションの税金計算をプレビューします。このエンドポイントは、消費者が請求情報を入力または更新した際にホスティングチェックアウトページから呼び出されます。
POST /v1/actions/checkout/preview-tax
認証: Store Slug
リクエストボディ
| フィールド | 型 | 必須 | 説明 |
|---|
checkoutSessionId | string | はい | チェックアウトセッション ID(cs_ + UUID 形式) |
billingDetail | object | はい | 税金計算用の請求詳細 |
請求詳細オブジェクト
| フィールド | 型 | 必須 | 説明 |
|---|
country | string | はい | ISO 3166-1 alpha-2 国コード |
isBusiness | boolean | はい | ビジネス購入かどうか |
state | string | 条件付き | US と CA の場合に必須 |
リクエスト例
const response = await fetch("https://api.waffo.ai/v1/actions/checkout/preview-tax", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Store-Slug": "my-store-abc123",
"X-Environment": "test",
},
body: JSON.stringify({
checkoutSessionId: "cs_550e8400-e29b-41d4-a716-446655440000",
billingDetail: {
country: "US",
isBusiness: false,
state: "CA",
},
}),
});
const { data } = await response.json();
console.log(data.total); // => "31.61"
成功レスポンス
{
"data": {
"subtotal": "29.00",
"taxAmount": "2.61",
"total": "31.61",
"taxRate": 0.09
}
}
レスポンスフィールド
| フィールド | 型 | 説明 |
|---|
subtotal | string | 商品価格の表示形式文字列(例:“29.00” = $29.00) |
taxAmount | string | 計算された税額の表示形式文字列 |
total | string | subtotal + taxAmount |
taxRate | number | 適用された税率(小数、例:0.09 = 9%) |
エラー
| ステータス | メッセージ | 説明 |
|---|
| 400 | 必須フィールドが欠落しています | checkoutSessionId or billingDetail is missing |
| 400 | Missing state for US/CA | country が US または CA の場合、state が必要です |
| 404 | Session not found | 指定された ID に一致するチェックアウトセッションがありません |
| 404 | Session expired | チェックアウトセッションの有効期限が切れています |
すべての金額は表示形式の文字列です(例:USD の場合 “29.00”、JPY の場合 “4500”)。例えば、USD の "29.00" は $29.00 を意味します。