VESTRAPAY_SECRET_KEY at your test secret key. Swap the host to https://api.vestrapay.com/v1 when you go live.
Initialize
See Quickstart for cURL, Node, Python, and PHP.Verify
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
}
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"]
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"];
}