> ## Documentation Index
> Fetch the complete documentation index at: https://beta-developers.mizaniyapay.dz/llms.txt
> Use this file to discover all available pages before exploring further.

# payment.initialized: Payment Session Created Event

> Reference for the payment.initialized webhook event, including event data fields, payload example, and handler implementations in JavaScript and Python.

The `payment.initialized` event is sent when VTPE creates a payment session for a reference. Use this event to create a pending payment record in your system. Do not fulfill the order yet; wait for the `payment.success` event before completing the transaction.

## Event Data

<ResponseField name="event" type="string" required>
  Always `payment.initialized`.
</ResponseField>

<ResponseField name="data.reference" type="string" required>
  The payment reference from your system.
</ResponseField>

<ResponseField name="data.amount" type="number" required>
  The payment amount.
</ResponseField>

<ResponseField name="data.currency" type="string" required>
  The currency code.
</ResponseField>

<ResponseField name="data.paymentId" type="string" required>
  The unique VTPE payment identifier.
</ResponseField>

## Payload Example

```json theme={null}
{
  "event": "payment.initialized",
  "data": {
    "reference": "ORD-2024-001",
    "amount": 5000.00,
    "currency": "DZD",
    "paymentId": "pay_abc123xyz"
  }
}
```

## Handling This Event

<CodeGroup>
  ```javascript Node.js theme={null}
  app.post("/webhooks/vtpe", (req, res) => {
    // Signature verification omitted for brevity — see Webhook Security guide
    const { event, data } = req.body;

    if (event === "payment.initialized") {
      // Create a pending payment record
      await db.createPendingPayment({
        paymentId: data.paymentId,
        reference: data.reference,
        amount: data.amount,
        currency: data.currency,
        status: "pending"
      });
    }

    return res.status(200).json({ success: true });
  });
  ```

  ```python Python theme={null}
  @app.route("/webhooks/vtpe", methods=["POST"])
  def handle_webhook():
      # Signature verification omitted for brevity — see Webhook Security guide
      payload = request.get_json()
      event = payload["event"]
      data = payload["data"]

      if event == "payment.initialized":
          db.create_pending_payment(
              payment_id=data["paymentId"],
              reference=data["reference"],
              amount=data["amount"],
              currency=data["currency"],
              status="pending"
          )

      return jsonify({"success": True}), 200
  ```
</CodeGroup>

<Note>
  Do not fulfill the order when receiving this event. Wait for `payment.success` before completing the transaction.
</Note>
