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

ParameterTypeRequiredDescription
order_idstringYesOrder identifier to cancel
reasonstringNoCancellation 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)
}

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