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

# Sample code

> Initialize and verify in Node, Python, and PHP.

Point `VESTRAPAY_SECRET_KEY` at your test secret key. Swap the host to `https://api.vestrapay.com/v1` when you [go live](/payments/go-live).

## Initialize

See [Quickstart](/quickstart) for cURL, Node, Python, and PHP.

## Verify

<CodeGroup>
  ```javascript Node theme={"theme":{"light":"github-light","dark":"github-dark"}}
  async function verifyPayment(reference) {
    const res = await fetch(
      `https://server.staging.vestrapay.app/v1/payment/verify/${encodeURIComponent(reference)}`,
      { headers: { "x-api-key": process.env.VESTRAPAY_SECRET_KEY } },
    );
    const body = await res.json();
    if (body.status !== "success") throw new Error(body.error);
    return body.data;
  }

  const payment = await verifyPayment(reference);
  if (payment.status === "success" && payment.amount === expectedAmount) {
    // fulfill the order once
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os, requests

  def verify_payment(reference: str) -> dict:
      res = requests.get(
          f"https://server.staging.vestrapay.app/v1/payment/verify/{reference}",
          headers={"x-api-key": os.environ["VESTRAPAY_SECRET_KEY"]},
          timeout=15,
      )
      body = res.json()
      if body.get("status") != "success":
          raise RuntimeError(body.get("error"))
      return body["data"]
  ```

  ```php PHP theme={"theme":{"light":"github-light","dark":"github-dark"}}
  function vestrapay_verify(string $reference): array {
    $ch = curl_init("https://server.staging.vestrapay.app/v1/payment/verify/" . rawurlencode($reference));
    curl_setopt_array($ch, [
      CURLOPT_HTTPHEADER => ["x-api-key: " . getenv("VESTRAPAY_SECRET_KEY")],
      CURLOPT_RETURNTRANSFER => true,
    ]);
    $body = json_decode(curl_exec($ch), true);
    if (($body["status"] ?? "") !== "success") {
      throw new RuntimeException($body["error"] ?? "verify_failed");
    }
    return $body["data"];
  }
  ```
</CodeGroup>

HMAC verification is on [Webhooks](/payments/webhooks).
