API Integration
Cancel Transaction
Cancel a pending transaction by vendor reference
Cancel Transaction
Cancel a transaction that is still in PENDING status, using the same vendorReference you used when creating the transaction.
Endpoint
PUT /api/v1/public/partner/transactions/vendor/{vendorReference}/cancelHeaders
| Header | Required | Value |
|---|---|---|
X-Api-Key | Yes | Your API key |
Example
curl -X PUT "https://api.alyapay.com/api/v1/public/partner/transactions/vendor/ORDER-2024-001/cancel" \
-H "X-Api-Key: sk_live_xxx.yyy"Response
Success (200 OK)
The transaction was canceled. The body matches the Get Transaction response shape, with status set to CANCELED.
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"orderReference": "AB12345",
"vendorReference": "ORDER-2024-001",
"status": "CANCELED",
"totalAmount": 500.00,
"currency": "MAD",
"customerPhone": "212612345678",
"merchantName": "My Store",
"storeName": "Downtown Branch",
"items": [...],
"createdAt": "2024-12-08T10:30:00Z",
"updatedAt": "2024-12-08T10:35:00Z"
}Error (400 Bad Request)
Returned when the transaction exists but is not in PENDING status (for example, it is already APPROVED, CANCELED, or COMPLETED).
{
"error": {
"message": "Transaction is not in PENDING status"
}
}Other error fields (such as code) may appear and follow the same pattern as Get Transaction errors.
| Status | Description |
|---|---|
| 400 | Transaction is not in PENDING status |
Use Cases
- Void an order in your system before the customer confirms in the AlyaPay app
- Clean up duplicate or mistaken transaction creation while still
PENDING
Note: If the transaction is not found or does not belong to your merchant account, you may receive the same 404 / TRANSACTION_NOT_FOUND response as Get by vendor reference.