Nexzoneo Pay API Documentation

Integrate secure payment processing into your application with our REST API.

API Base URL
https://payment.nexzoneo.com/api/merchant/
Interactive API Testing

Test API endpoints directly in your browser:

Open Swagger UI

Documentation Formats

Traditional Documentation

Comprehensive guide with detailed explanations, code examples, and integration patterns.

Current Page
Interactive Swagger UI

Test API endpoints directly in your browser with live request/response examples.

Open Swagger UI

API Features

Authentication

All API requests require authentication using your site credentials and must be made from your server.

Required Headers

X-Site-Key: your_site_key_here
Authorization: your_security_token_here
Content-Type: application/json
Critical Security Notice
  • Never expose your security token in client-side code (HTML, JavaScript, mobile apps, etc.)
  • All API calls must be made from your server using server-side languages like PHP, Python, Node.js, etc.
  • Store your credentials securely using environment variables or secure configuration files
  • Your client-side code should call your own server endpoints, which then securely call our API

API Endpoints

POST /create_payment_session

Creates a new payment session for processing a customer payment.

Request Parameters
Parameter Type Required Description
order_id string Required Unique identifier for the order
total number Required Total amount to charge
currency string Required Currency code (e.g., USD, EUR)
customer_email string Required Customer's email address
items array Optional Array of order items
return_url string Optional URL to redirect after successful payment
cancel_url string Optional URL to redirect after cancelled payment
callback_url string Optional Webhook URL for payment notifications
Example Request
{
  "order_id": "ORD-12345",
  "total": 99.99,
  "currency": "USD",
  "customer_email": "customer@example.com",
  "items": [
    {
      "name": "Premium Plan",
      "quantity": 1,
      "unit_price": 99.99
    }
  ],
  "return_url": "https://example.com/success",
  "cancel_url": "https://example.com/cancel",
  "callback_url": "https://example.com/webhook"
}
Successful Response
{
  "status": "success",
  "data": {
    "success": true,
    "session_id": 12345,
    "session_token": "abc123def456...",
    "payment_url": "https://payment.nexzoneo.com/session/abc123def456...",
    "reused": false
  },
  "request_id": "req_abc123",
  "duration_ms": 45.2
}
GET /get_session?token={session_token}

Retrieves details about an existing payment session.

Query Parameters
Parameter Type Required Description
token string Required Payment session token
Successful Response
{
  "status": "success",
  "data": {
    "success": true,
    "session": {
      "id": 12345,
      "session_token": "abc123def456...",
      "external_order_id": "ORD-12345",
      "customer_email": "customer@example.com",
      "amount": "99.99",
      "currency": "USD",
      "status": 2,
      "current_status": 2,
      "created_at": "2024-01-15 10:30:00",
      "completed_at": "2024-01-15 10:35:00"
    }
  },
  "request_id": "req_def789",
  "duration_ms": 12.8
}
POST /create_refund

Creates a full or partial refund for a completed payment. Only payments with status COMPLETED or PARTIALLY_REFUNDED can be refunded.

Request Parameters
Parameter Type Required Description
session_id number Required Payment session ID to refund
amount number Required Refund amount (up to remaining balance)
reason string Required Refund reason: duplicate, fraudulent, or requested_by_customer
comment string Optional Optional comment for the refund
Example Request
{
  "session_id": 12345,
  "amount": 29.99,
  "reason": "requested_by_customer",
  "comment": "Customer requested refund due to order cancellation"
}
Successful Response
{
  "status": "success",
  "data": {
    "success": true,
    "message": "Refund processed successfully",
    "refund_id": 456,
    "transaction_id": "txn_1234567890abcdef"
  },
  "request_id": "req_abc456",
  "duration_ms": 1250.3
}
Rate Limiting: Maximum 5 refund attempts per session per hour to prevent abuse.
GET /get_refund_status?refund_id={refund_id}

Retrieves the current status of a specific refund.

Query Parameters
Parameter Type Required Description
refund_id number Required Refund ID from create_refund response
Successful Response
{
  "status": "success",
  "data": {
    "success": true,
    "refund": {
      "id": 456,
      "session_id": 12345,
      "payment_intent_id": "pi_1234567890abcdef",
      "transaction_id": "txn_1234567890abcdef",
      "amount": "29.99",
      "currency": "USD",
      "reason": "requested_by_customer",
      "status": "succeeded",
      "admin_comment": "Customer requested refund",
      "created_at": "2024-01-15 11:00:00",
      "updated_at": "2024-01-15 11:00:15"
    }
  },
  "request_id": "req_def456",
  "duration_ms": 23.1
}
Refund Status Values
  • pending - Refund is being processed
  • succeeded - Refund was successful
  • failed - Refund failed
  • canceled - Refund was canceled
GET /list_refunds?session_id={session_id}

Lists all refunds for a specific payment session, including the total refunded amount.

Query Parameters
Parameter Type Required Description
session_id number Required Payment session ID to query refunds for
Successful Response
{
  "status": "success",
  "data": {
    "success": true,
    "refunds": [
      {
        "id": 456,
        "session_id": 12345,
        "payment_intent_id": "pi_1234567890abcdef",
        "transaction_id": "txn_1234567890abcdef",
        "amount": "29.99",
        "currency": "USD",
        "reason": "requested_by_customer",
        "status": "succeeded",
        "admin_comment": "Customer requested refund",
        "created_at": "2024-01-15 11:00:00",
        "updated_at": "2024-01-15 11:00:15"
      }
    ],
    "total_refunded": "29.99"
  },
  "request_id": "req_ghi789",
  "duration_ms": 18.5
}

Webhooks

Webhooks allow you to receive real-time notifications about payment status changes.

Webhook Payload

When a payment status changes, we'll send a POST request to your callback URL with the following data:

{
  "order_id": "ORD-12345",
  "total": "99.99",
  "currency": "USD",
  "payment_status": "completed",
  "session_status": "completed",
  "transaction_ref": "TXN-789",
  "customer_email": "customer@example.com",
  "timestamp": "1705320900",
  "signature": "abc123def456..."
}
Refund Webhook Examples

When refunds are processed, you'll receive webhooks with the appropriate refund status:

// Partial refund example
{
  "order_id": "ORD-12345",
  "total": "99.99",
  "currency": "USD",
  "payment_status": "partially_refunded",
  "session_status": "partially_refunded",
  "transaction_ref": "TXN-789",
  "customer_email": "customer@example.com",
  "timestamp": "1705320900",
  "signature": "def789abc123..."
}

// Full refund example
{
  "order_id": "ORD-12345",
  "total": "99.99",
  "currency": "USD",
  "payment_status": "fully_refunded",
  "session_status": "fully_refunded",
  "transaction_ref": "TXN-789",
  "customer_email": "customer@example.com",
  "timestamp": "1705320900",
  "signature": "ghi456def789..."
}

Signature Verification

Verify webhook authenticity by checking the signature:

$data = $_POST;
$signature = $data['signature'];
unset($data['signature']);

ksort($data);
$expected_signature = hash_hmac('sha256', json_encode($data), $your_security_token);

if (hash_equals($expected_signature, $signature)) {
    // Webhook is authentic
} else {
    // Invalid webhook
}

Payment Status Values

Error Handling

The API uses standard HTTP status codes and returns detailed error information.

Error Response Format

{
  "status": "error",
  "data": {
    "error": "Missing required fields",
    "fields": ["order_id", "total"]
  },
  "request_id": "req_error123",
  "duration_ms": 5.2
}

Common Error Codes

Status Code Description
400 Bad Request - Invalid or missing parameters
401 Unauthorized - Invalid credentials
404 Not Found - Endpoint or resource not found
405 Method Not Allowed - Wrong HTTP method
429 Too Many Requests - Rate limit exceeded (refund attempts)
500 Internal Server Error - Server error occurred

Common Refund Errors

Error Message Description Solution
Payment session not found or access denied Invalid session ID or not owned by merchant Verify session ID and ownership
Refund amount must be greater than zero Invalid refund amount Check amount is positive number
Invalid refund reason Reason not in allowed list Use: duplicate, fraudulent, or requested_by_customer
Refund amount exceeds remaining balance Attempting to refund more than available Check remaining refundable amount first
Rate limit exceeded for refunds Too many refund attempts Wait 1 hour before attempting again

Code Examples

PHP Example

function createPaymentSession($orderData) {
    $url = 'https://payment.nexzoneo.com/api/merchant/create_payment_session';
    
    $headers = [
        'Content-Type: application/json',
        'X-Site-Key: your_site_key_here',
        'Authorization: your_security_token_here'
    ];
    
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => json_encode($orderData),
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => true
    ]);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($httpCode === 200) {
        $data = json_decode($response, true);
        return $data['data'];
    } else {
        throw new Exception('API Error: ' . $response);
    }
}

// Usage
$orderData = [
    'order_id' => 'ORD-12345',
    'total' => 99.99,
    'currency' => 'USD',
    'customer_email' => 'customer@example.com'
];

$result = createPaymentSession($orderData);
echo $result['payment_url'];

// Create refund example
function createRefund($sessionId, $amount, $reason, $comment = null) {
    $url = 'https://payment.nexzoneo.com/api/merchant/create_refund';
    
    $refundData = [
        'session_id' => $sessionId,
        'amount' => $amount,
        'reason' => $reason
    ];
    
    if ($comment) {
        $refundData['comment'] = $comment;
    }
    
    $headers = [
        'Content-Type: application/json',
        'X-Site-Key: your_site_key_here',
        'Authorization: your_security_token_here'
    ];
    
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => json_encode($refundData),
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => true
    ]);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($httpCode === 200) {
        $data = json_decode($response, true);
        return $data['data'];
    } else {
        throw new Exception('Refund Error: ' . $response);
    }
}

// Usage
$refundResult = createRefund(12345, 29.99, 'requested_by_customer', 'Customer cancelled order');
echo 'Refund ID: ' . $refundResult['refund_id'];

JavaScript/Node.js Example (Server-side)

// Server-side Node.js example
const express = require('express');
const fetch = require('node-fetch');

app.post('/create-payment', async (req, res) => {
    try {
        const orderData = req.body;
        
        const response = await fetch('https://payment.nexzoneo.com/api/merchant/create_payment_session', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-Site-Key': process.env.NEXZONEO_SITE_KEY,
                'Authorization': process.env.NEXZONEO_SECURITY_TOKEN
            },
            body: JSON.stringify(orderData)
        });
        
        if (response.ok) {
            const data = await response.json();
            res.json(data.data);
        } else {
            throw new Error(`API Error: ${response.status}`);
        }
    } catch (error) {
        res.status(500).json({ error: error.message });
    }
});

// Client-side JavaScript example
async function createPayment(orderData) {
    // Call YOUR server endpoint, not Nexzoneo directly
    const response = await fetch('/create-payment', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(orderData)
    });
    
    if (response.ok) {
        const data = await response.json();
        // Redirect user to payment URL
        window.location.href = data.payment_url;
    } else {
        throw new Error('Payment creation failed');
    }
}
Important: The JavaScript example above shows the correct approach - your client-side code should call your own server, which then makes the secure API call to Nexzoneo. Never include your API credentials in client-side JavaScript.

Python Example

import requests
import json

def create_payment_session(order_data):
    url = 'https://payment.nexzoneo.com/api/merchant/create_payment_session'
    
    headers = {
        'Content-Type': 'application/json',
        'X-Site-Key': 'your_site_key_here',
        'Authorization': 'your_security_token_here'
    }
    
    response = requests.post(url, headers=headers, json=order_data)
    
    if response.status_code == 200:
        return response.json()['data']
    else:
        raise Exception(f'API Error: {response.text}')

# Usage
order_data = {
    'order_id': 'ORD-12345',
    'total': 99.99,
    'currency': 'USD',
    'customer_email': 'customer@example.com'
}

result = create_payment_session(order_data)
print(f"Payment URL: {result['payment_url']}")

Testing

Use test mode to safely test your integration without processing real payments.

Test Mode

Enable test mode in your merchant site settings. In test mode:

Test Cards

Use these test card numbers to simulate different scenarios:

Card Number Description
4242424242424242 Successful payment
4000000000000002 Card declined
4000000000009995 Insufficient funds
Interactive API Testing

The fastest way to test our API is using our interactive Swagger UI documentation:

Test API Endpoints Live

No additional tools required - test directly in your browser with real API responses.

Tip: Always test your webhook handling and error scenarios before going live.

OpenAPI Specification & Swagger UI

Our API is fully documented using the OpenAPI 3.0 specification, providing multiple ways to integrate and test.

OpenAPI Specification

Download or access our machine-readable API specification:

  • Format: OpenAPI 3.0.3 (YAML)
  • URL: /api/merchant/docs/openapi.yaml
  • Use for: Code generation, validation, tooling
Download OpenAPI Spec

Interactive Swagger UI

Test API endpoints directly in your browser:

  • Live testing: Send real API requests
  • Authentication: Built-in credential management
  • Examples: Pre-filled request examples
  • Responses: See actual API responses
Open Swagger UI
Developer Tools Integration

You can import our OpenAPI specification into popular development tools:

  • Postman: Import → Link → https://payment.nexzoneo.com/api/merchant/docs/openapi.yaml
  • Insomnia: Import/Export → Import from URL
  • VS Code: Use OpenAPI extensions for auto-completion
  • Code Generators: Generate client SDKs using OpenAPI Generator