API Version 2.0 — Stable

مستندات API

API های سریع و پایدار افرا پی — اتصال به درگاه کارت‌به‌کارت هوشمند را برای توسعه‌دهندگان به یک تجربه لذت‌بخش تبدیل کرده‌ایم.

cURL JavaScript Node.js Python PHP
Base URL: https://payment.abrafra.ir

ایجاد تراکنش جدید

با این متد درخواست پرداخت ایجاد کرده و لینک درگاه را دریافت کنید.

POST /api/new-payment
پارامتراجباریتوضیح
authKeyتوکن امنیتی پذیرنده
amountمبلغ تراکنش به ریال
store_idشناسه فروشگاه شما
description×توضیحات اختیاری
customer_user_id×شناسه کاربر
curl -X POST https://payment.abrafra.ir/api/new-payment \
  -H "Content-Type: application/json" \
  -d '{
    "authKey": "YOUR_AUTH_KEY",
    "amount": 1000000,
    "store_id": "YOUR_STORE_ID",
    "description": "خرید اشتراک",
    "customer_user_id": "user_123"
}'
fetch('https://payment.abrafra.ir/api/new-payment', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        authKey: 'YOUR_AUTH_KEY',
        amount: 1000000,
        store_id: 'YOUR_STORE_ID',
        description: "خرید اشتراک",
        customer_user_id: 'user_123'
    })
})
.then(r => r.json())
.then(d => console.log(d))
.catch(e => console.error(e));
const axios = require('axios');
axios.post('https://payment.abrafra.ir/api/new-payment', {
    authKey: 'YOUR_AUTH_KEY',
    amount: 1000000,
    store_id: 'YOUR_STORE_ID',
    description: "خرید اشتراک",
    customer_user_id: 'user_123'
}, { headers: { 'Content-Type': 'application/json' } })
.then(r => console.log(r.data))
.catch(e => console.error(e.response?.data || e.message));
import requests
url = "https://payment.abrafra.ir/api/new-payment"
payload = {
    "authKey": "YOUR_AUTH_KEY",
    "amount": 1000000,
    "store_id": "YOUR_STORE_ID",
    "description": "خرید اشتراک",
    "customer_user_id": "user_123"
}
r = requests.post(url, json=payload)
print(r.json())
<?php
$ch = curl_init('https://payment.abrafra.ir/api/new-payment');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'authKey' => 'YOUR_AUTH_KEY',
    'amount' => 1000000,
    'store_id' => 'YOUR_STORE_ID',
    'description' => "خرید اشتراک",
    'customer_user_id' => 'user_123'
]));
$r = curl_exec($ch);
curl_close($ch);
print_r(json_decode($r, true));
?>
{
    "success": true,
    "payment_link": "https://payment.abrafra.ir/pay/5172556f...",
    "authority": "5172556f1c.....",
    "order_id": "111111",
    "original_amount": 1000000,
    "amount": 1000163,
    "card": { "number": "1111****1111", "bank": "ملی", "owner": "Afra pay" },
    "shop": { "name": "Afra pay", "id": 111111, "link": "https://t.me/Afrapaybot" }
}

تایید تراکنش

پس از بازگشت کاربر از درگاه، حتماً تراکنش را با این متد تایید کنید.

POST /api/verify-payment
پارامتراجباریتوضیح
authKeyتوکن امنیتی پذیرنده
authorityشناسه تراکنش دریافتی
curl -X POST https://payment.abrafra.ir/api/verify-payment \
  -H "Content-Type: application/json" \
  -d '{
    "authKey": "YOUR_AUTH_KEY",
    "authority": "AUTHORITY_FROM_NEW_PAYMENT"
}'
fetch('https://payment.abrafra.ir/api/verify-payment', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        authKey: 'YOUR_AUTH_KEY',
        authority: "AUTHORITY_FROM_NEW_PAYMENT"
    })
})
.then(r => r.json())
.then(d => console.log(d))
.catch(e => console.error(e));
const axios = require('axios');
axios.post('https://payment.abrafra.ir/api/verify-payment', {
    authKey: 'YOUR_AUTH_KEY',
    authority: "AUTHORITY_FROM_NEW_PAYMENT"
}, { headers: { 'Content-Type': 'application/json' } })
.then(r => console.log(r.data))
.catch(e => console.error(e.response?.data || e.message));
import requests
url = "https://payment.abrafra.ir/api/verify-payment"
payload = {
    "authKey": "YOUR_AUTH_KEY",
    "authority": "AUTHORITY_FROM_NEW_PAYMENT"
}
r = requests.post(url, json=payload)
print(r.json())
<?php
$ch = curl_init('https://payment.abrafra.ir/api/verify-payment');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'authKey' => 'YOUR_AUTH_KEY',
    'authority' => 'AUTHORITY_FROM_NEW_PAYMENT'
]));
$r = curl_exec($ch);
curl_close($ch);
print_r(json_decode($r, true));
?>
{
    "success": true,
    "code": 100,
    "message": "Payment verified for the first time",
    "transaction": {
        "payment_id": "111111",
        "authority": "5172556f.....",
        "amount": 1000163,
        "original_amount": 1000000,
        "customer_user_id": 1234567890
    }
}

کدهای وضعیت پاسخ

تایید موفق100
تراکنش با موفقیت پرداخت و برای اولین بار تایید شد.
تایید مجدد101
تراکنش قبلاً وریفای شده، درخواست مجدد موفقیت‌آمیز بود.
در انتظار پرداخت-55
تراکنش ایجاد شده اما مشتری هنوز پرداختی انجام نداده است.
دسترسی مسدود-53
authKey معتبر نیست یا دسترسی پذیرنده مسدود شده است.
یافت نشد-54
شناسه authority ارسالی در سیستم وجود ندارد.
تراکنش ناموفق-1
پرداخت توسط مشتری انجام نشد یا با خطا مواجه شد.