Payments
Order Webhook
Webhook endpoint for Midtrans to send payment status updates (server-to-server)
POST
Overview
This is a webhook endpoint that receives payment status notifications from Midtrans payment gateway. This endpoint is called server-to-server by Midtrans and should NOT be called directly by your application.Authentication
This endpoint does NOT require cookie-based authentication as it is called by Midtrans servers. However, Midtrans includes asignature_key in the payload that should be verified for security.
Request Body
Midtrans sends the following payload when a transaction status changes:ISO 8601 datetime when the transaction occurred
HTTP status code from the payment provider
The current status of the transactionPossible values:
capture- Payment captured (credit card)settlement- Payment settled successfullypending- Payment is pendingdeny- Payment was deniedcancel- Payment was cancelledexpire- Payment expiredfailure- Payment failedrefund- Full refund processedpartial_refund- Partial refund processedauthorize- Payment authorized (not yet captured)
Security signature from Midtrans for request verification
Total transaction amount as a string
The order ID (UUID) that was created by the “Request Order Token” endpoint
Unique transaction ID from Midtrans
The payment method used (e.g., “credit_card”, “bank_transfer”, “gopay”, etc.)
Fraud detection status from MidtransPossible values:
accept- Transaction is safedeny- Transaction flagged as fraudulent
Response
The endpoint returns a simple HTTP 200 status code to acknowledge receipt of the webhook.HTTP status code 200 for successful webhook processing
Webhook Behavior
Order Completion
When the webhook receives a notification withtransaction_status of either settlement or capture, the order’s completed_at timestamp is automatically set to the current time.
Other Status Updates
For all other transaction statuses (pending, deny, cancel, expire, failure, refund, etc.), the order status is updated but thecompleted_at field remains null.
Security Considerations
The
signature_key field in the webhook payload is included by Midtrans for security verification. While the current implementation includes this field in the schema, you should implement signature verification to ensure the webhook is genuinely from Midtrans.- Concatenate:
order_id + status_code + gross_amount + server_key - Hash the string using SHA512
- Compare the hash with the
signature_keyin the payload
Configuring the Webhook URL
In your Midtrans dashboard, configure the webhook notification URL to:Integration Flow
- Customer initiates payment via “Request Order Token” endpoint
- Customer completes payment on Midtrans payment page
- Midtrans sends webhook notification to this endpoint
- Server updates order status in database
- Your application polls “Check Order Status” endpoint to verify completion