Api References
Cancel Order
Cancels an existing order before completion.
Endpoint
POST https://merchant.dv.vai247.pro/api/v1/payment-gateway/order/cancel
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
order_id | string | Yes | Order identifier to cancel |
reason | string | No | Cancellation reason |
Code Examples
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
)
type CancelRequest struct {
OrderID string `json:"order_id"`
Reason string `json:"reason,omitempty"`
}
type CancelResponse struct {
OrderID string `json:"order_id"`
Status string `json:"status"`
CancelledAt string `json:"cancelled_at"`
}
func cancelOrder(orderID string, reason string) (*CancelResponse, error) {
url := "https://merchant.dv.vai247.pro/api/v1/payment-gateway/order/cancel"
payload := CancelRequest{
OrderID: orderID,
Reason: reason,
}
jsonData, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
return nil, err
}
// Add authentication headers
req.Header.Set("X-App-Id", "your-app-id")
req.Header.Set("X-Api-Key", "your-api-key")
req.Header.Set("X-Timestamp", fmt.Sprintf("%d", time.Now().Unix()))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var result CancelResponse
if err := json.Unmarshal(body, &result); err != nil {
return nil, err
}
return &result, nil
}
func main() {
cancel, err := cancelOrder("ord_abc123xyz", "Customer changed mind")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Order %s cancelled at %s\n", cancel.OrderID, cancel.CancelledAt)
}
const axios = require('axios');
async function cancelOrder(orderId, reason = '') {
const url = 'https://merchant.dv.vai247.pro/api/v1/payment-gateway/order/cancel';
const headers = {
'X-App-Id': 'your-app-id',
'X-Api-Key': 'your-api-key',
'X-Timestamp': Math.floor(Date.now() / 1000).toString(),
'Content-Type': 'application/json'
};
const payload = {
order_id: orderId,
...(reason && { reason })
};
try {
const response = await axios.post(url, payload, { headers });
return response.data;
} catch (error) {
console.error('Error cancelling order:', error.response?.data || error.message);
throw error;
}
}
// Usage
(async () => {
try {
const result = await cancelOrder('ord_abc123xyz', 'Customer changed mind');
console.log(`Order ${result.order_id} cancelled at ${result.cancelled_at}`);
} catch (error) {
console.error('Failed to cancel order');
}
})();
Response
{
"order_id": "ord_abc123xyz",
"status": "cancelled",
"cancelled_at": "2025-10-04T11:15:00Z"
}
Notes
- Only pending or processing orders can be cancelled
- Completed orders must use the refund endpoint instead
- Cancelled orders cannot be reinstated