> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zafapay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Depot決済

> Depot電子マネー決済の統合方法

## 概要

Depotは**リダイレクト型**の決済方法です。APIで決済を作成後、顧客を`payment_url`にリダイレクトして決済を完了します。

## 決済フロー

<Steps>
  <Step title="決済作成">
    `POST /v1/payments` を呼び出して決済を作成し、`payment_url` を取得
  </Step>

  <Step title="顧客をリダイレクト">
    顧客を `payment_url` にリダイレクト
  </Step>

  <Step title="顧客が決済完了">
    顧客がDepotのページで決済を完了
  </Step>

  <Step title="リダイレクトバック">
    顧客は `success_redirect_url` または `failure_redirect_url` にリダイレクト
  </Step>

  <Step title="結果確認">
    必要に応じて決済取得APIで決済ステータスを確認
  </Step>
</Steps>

## 実装例

```javascript theme={null}
// 1. APIで決済を作成
const response = await fetch('https://api.sandbox.zafapay.com/v1/payments', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 100,
    currency: 'usd',
    external_id: 'order_12345'
  })
});

const payment = await response.json();

// 2. 顧客をDepot決済ページにリダイレクト
window.location.href = payment.payment_url;
```

## Webhook連携

確実な決済確認のため、Webhookを設定してください：

```javascript theme={null}
// Webhookハンドラー
app.post('/webhooks/zafapay', async (req, res) => {
  const event = req.body;

  if (event.type === 'payment.completed') {
    // 注文ステータスを更新
    await updateOrder(event.data.external_id, 'paid');
  }

  res.json({ received: true });
});
```

<Info>
  APIパラメータとレスポンスの詳細は、[決済作成](/api-reference/payments/create-payment) APIリファレンスをご覧ください。
</Info>
