پرش به مطلب اصلی

دریافت Payment Intent

جزئیات یک Payment Intent را دریافت کنید تا وضعیتش را بررسی کنید و اطلاعات به‌روز بگیرید.

اندپوینت​

GET /api/v1/payment_intents/:id

احراز هویت​

این اندپوینت از هر دو روش احراز هویت پشتیبانی می‌کند:

  • توکن Bearer (JWT) — Authorization: Bearer YOUR_JWT_TOKEN
  • کلید API (Basic Auth) — Authorization: Basic base64(key:secret)

درخواست​

پارامترهای مسیر​

پارامترنوعالزامیتوضیح
idstringبلهشناسه Payment Intent که دریافت می‌شود (مثلاً 550e8400-e29b-41d4-a716-446655440000).

پاسخ​

پاسخ موفق​

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"amount": "100.00",
"currency": "usd",
"status": "completed",
"payment_method_types": ["crypto"],
"return_url": "https://merchant.example.com/return",
"cancel_url": "https://merchant.example.com/cancel",
"description": "Payment for services",
"metadata": {
"order_id": "12345",
"customer_id": "67890"
},
"pay_url": "https://pay.orcarail.com/pl_abc123",
"payment_link": {
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"unique_slug": "pl_abc123",
"link": "https://pay.orcarail.com/pl_abc123"
},
"latest_transaction": {
"id": "txn_1234567890",
"status": "completed",
"amount_received": "100.00",
"hash": "0x1234567890abcdef..."
}
}

فیلدهای پاسخ​

فیلدنوعتوضیح
idstringشناسه یکتای Payment Intent.
amountstringمبلغ دریافت‌شده.
currencystringکد ارز.
statusstringوضعیت فعلی Payment Intent. مقادیر وضعیت را در ادامه ببینید.
payment_method_typesarrayآرایه انواع روش پرداخت استفاده‌شده.
return_urlstringآدرس بازگشت تعیین‌شده.
cancel_urlstringآدرس لغو (در صورت تعیین).
descriptionstringتوضیح (در صورت ارائه).
metadataobjectفراداده (در صورت ارائه).
payment_linkobjectشیء لینک پرداخت با آدرس پرداخت.
pay_urlstringآدرس صفحه پرداخت آماده.
latest_transactionobjectآخرین تراکنش مرتبط با این Payment Intent.
latest_transaction.idstringشناسه تراکنش.
latest_transaction.statusstringوضعیت تراکنش.
latest_transaction.amount_receivedstringمبلغ تراکنش.
latest_transaction.hashstringهش تراکنش روی بلاکچین (در صورت تکمیل).

مقادیر وضعیت​

وضعیتتوضیح
requires_payment_methodPaymentIntent ساخته شده اما هنوز روش پرداختی به آن متصل نشده است.
requires_confirmationPaymentIntent روش پرداخت دارد اما باید تأیید شود.
processingPaymentIntent روی بلاکچین در حال پردازش است.
completedPaymentIntent موفق شده و پرداخت پردازش شده است.
canceledPaymentIntent لغو شده است.

نمونه​

cURL​

curl https://api.orcarail.com/api/v1/payment_intents/550e8400-e29b-41d4-a716-446655440000 \
-H "Authorization: Bearer YOUR_JWT_TOKEN"

JavaScript (Node.js)​

const paymentIntentId = '550e8400-e29b-41d4-a716-446655440000'

const response = await fetch(
`https://api.orcarail.com/api/v1/payment_intents/${paymentIntentId}`,
{
headers: {
Authorization: `Bearer ${jwtToken}`,
},
}
)

const paymentIntent = await response.json()

console.log('Status:', paymentIntent.status)
console.log('Amount:', paymentIntent.amount)

if (paymentIntent.status === 'completed') {
console.log('Transaction Hash:', paymentIntent.latestTransaction?.hash)
}

Python​

import requests

payment_intent_id = '550e8400-e29b-41d4-a716-446655440000'

response = requests.get(
f'https://api.orcarail.com/api/v1/payment_intents/{payment_intent_id}',
headers={
'Authorization': f'Bearer {jwt_token}',
},
)

payment_intent = response.json()

print(f"Status: {payment_intent['status']}")
print(f"Amount: {payment_intent['amount']}")

if payment_intent['status'] == 'completed':
print(f"Transaction Hash: {payment_intent['latestTransaction']['hash']}")

PHP (SDK)​

$intent = $orcarail->paymentIntents->retrieve('550e8400-e29b-41d4-a716-446655440000');

echo $intent->status;
echo $intent->amount;
echo $intent->latest_transaction?->hash;

برای راه‌اندازی کلاینت SDK پی‌اچ‌پی را ببینید.

موارد استفاده​

بررسی وضعیت پرداخت پس از بازگشت​

پس از اینکه مشتری به return_url شما بازگشت، Payment Intent را دریافت کنید تا ببینید پرداخت موفق بوده یا نه:

// Extract from URL query params
const urlParams = new URLSearchParams(window.location.search)
const paymentIntentId = urlParams.get('payment_intent')

if (paymentIntentId) {
const response = await fetch(
`https://api.orcarail.com/api/v1/payment_intents/${paymentIntentId}`,
{
headers: {
Authorization: `Bearer ${jwtToken}`,
},
}
)

const paymentIntent = await response.json()

switch (paymentIntent.status) {
case 'completed':
// Payment completed successfully
showSuccessMessage()
fulfillOrder(paymentIntent.metadata.order_id)
break
case 'processing':
// Payment is being processed
showProcessingMessage()
break
case 'canceled':
// Payment was canceled
showCanceledMessage()
break
default:
// Handle other statuses
showErrorMessage()
}
}

پرس‌وجوی دوره‌ای وضعیت​

اگر از وب‌هوک استفاده نمی‌کنید، می‌توانید به‌طور دوره‌ای اندپوینت Payment Intent را برای تغییر وضعیت بررسی کنید:

async function pollPaymentStatus(paymentIntentId, maxAttempts = 30) {
for (let i = 0; i < maxAttempts; i++) {
const response = await fetch(
`https://api.orcarail.com/api/v1/payment_intents/${paymentIntentId}`,
{
headers: {
Authorization: `Bearer ${jwtToken}`,
},
}
)

const paymentIntent = await response.json()

if (paymentIntent.status === 'completed') {
return { success: true, paymentIntent }
}

if (paymentIntent.status === 'canceled') {
return { success: false, paymentIntent }
}

// Wait 2 seconds before next poll
await new Promise((resolve) => setTimeout(resolve, 2000))
}

return { success: false, error: 'Timeout' }
}

قدم‌های بعدی​