Essentials

Webhook Configuration

Set up and handle real-time payment notifications from DVPay

Webhooks enable your application to receive real-time notifications about payment events. DVPay sends HTTP POST requests to your configured webhook endpoint whenever specific events occur.

Setup Your Webhook

Step 1: Create an Endpoint

Create a publicly accessible HTTPS endpoint in your application to receive webhook events.

package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

type WebhookPayload struct {
    AccountName      string  `json:"accountName"`
    AccountNumber    string  `json:"accountNumber"`
    Amount           float64 `json:"amount"`
    AppID            int64   `json:"appId"`
    CreateTimeMilli  int64   `json:"createTimeMilli"`
    Currency         string  `json:"currency"`
    OrderID          int64   `json:"orderId"`
    Status           string  `json:"status"`
    TransactionID    int64   `json:"transactionId"`
}

func webhookHandler(w http.ResponseWriter, r *http.Request) {
    // Read the request body
    body, err := io.ReadAll(r.Body)
    if err != nil {
        http.Error(w, "Failed to read request body", http.StatusBadRequest)
        return
    }
    defer r.Body.Close()

    // Parse webhook payload
    var payload WebhookPayload
    if err := json.Unmarshal(body, &payload); err != nil {
        http.Error(w, "Invalid JSON", http.StatusBadRequest)
        return
    }

    // Process the webhook event
    switch payload.Status {
    case "SUCCESS":
        fmt.Printf("Payment successful - Order ID: %d, Transaction ID: %d\n", payload.OrderID, payload.TransactionID)
        // Update your database, send confirmation email, etc.
    case "FAILED":
        fmt.Printf("Payment failed - Order ID: %d\n", payload.OrderID)
        // Handle failed payment
    case "REFUNDED":
        fmt.Printf("Refund completed - Order ID: %d\n", payload.OrderID)
        // Update order status
    }

    // Respond with 200 OK
    w.WriteHeader(http.StatusOK)
    w.Write([]byte(`{"status":"received"}`))
}

func main() {
    http.HandleFunc("/webhooks/dvpay", webhookHandler)
    fmt.Println("Webhook server listening on :8080")
    http.ListenAndServe(":8080", nil)
}

Step 2: Configure in DVPay App

After creating your endpoint, register it in the DVPay merchant dashboard:

Open DVPay Mobile App

Navigate to your merchant dashboard in the DVPay mobile application.

Go to API Settings

Tap on SettingsAPI ConfigurationWebhook Settings

Enter Your Webhook URL

Input your publicly accessible HTTPS endpoint (e.g., https://yourdomain.com/webhooks/dvpay)

Webhook URLs must use HTTPS. HTTP endpoints will be rejected.

Select Event Types

Choose which events you want to receive:

  • payment.success - Payment completed successfully
  • payment.failed - Payment attempt failed
  • payment.pending - Payment is awaiting confirmation
  • refund.completed - Refund processed successfully
  • order.cancelled - Order was cancelled

Save Configuration

Click Save to activate your webhook endpoint.

Webhook Status Values

DVPay webhooks include a status field with the following possible values:

SUCCESS
string
Triggered when a payment is successfully completed. Update your order status and fulfill the order.
FAILED
string
Triggered when a payment attempt fails. Notify the customer and provide alternative payment options.
PENDING
string
Triggered when a payment is initiated but awaiting confirmation. Hold the order until final status.
REFUNDED
string
Triggered when a refund is successfully processed. Update order status and notify the customer.
CANCELLED
string
Triggered when an order is cancelled before payment. Release any reserved inventory.

Webhook Events

Coming Soon: Event-based webhooks with granular event types (e.g., payment.success, payment.failed, refund.completed) will be available in a future release. Currently, all webhooks use the status field to indicate transaction state.

Payload Structure

All webhook events follow this JSON structure:

{
  "accountName": "testPg0",
  "accountNumber": "838825694",
  "amount": 0.05,
  "appId": 9328657108474192,
  "createTimeMilli": 1772453630058,
  "currency": "USD",
  "orderId": 779539349308101,
  "status": "SUCCESS",
  "transactionId": 779539365712584
}
accountName
string required
The merchant account name
accountNumber
string required
The merchant account number
amount
number required
Payment amount
appId
number required
Application identifier (X-App-Id)
createTimeMilli
number required
Unix timestamp in milliseconds when the transaction was created
currency
string required
Currency code (USD or KHR)
orderId
number required
Unique identifier for the order
status
string required
Payment status (SUCCESS, FAILED, PENDING, REFUNDED, CANCELLED)
transactionId
number required
Unique transaction identifier assigned by DVPay

Security Best Practices

Testing Webhooks

Local Development with ngrok

Expose your local server for webhook testing:

# Install ngrok
npm install -g ngrok

# Start your local server
node server.js

# Expose port 8080
ngrok http 8080

Use the generated ngrok URL (e.g., https://abc123.ngrok.io/webhooks/dvpay) in your webhook configuration.

Manual Testing

Test your webhook endpoint manually:

curl -X POST https://yourdomain.com/webhooks/dvpay \
  -H "Content-Type: application/json" \
  -d '{
    "accountName": "testPg0",
    "accountNumber": "838825694",
    "amount": 0.05,
    "appId": 9328657108474192,
    "createTimeMilli": 1772453630058,
    "currency": "USD",
    "orderId": 779539349308101,
    "status": "SUCCESS",
    "transactionId": 779539365712584
  }'

Retry Logic

If your webhook endpoint returns an error or doesn't respond within 5 seconds, DVPay will retry:

  • 1st retry: After 1 minute
  • 2nd retry: After 10 minutes
  • 3rd retry: After 1 hour
  • Final retry: After 6 hours
After 4 failed attempts, the webhook will be marked as failed. You can view failed webhooks in your merchant dashboard.

Troubleshooting

Next Steps

Error Handling

Learn how to handle API errors and webhook failures

Security Best Practices

Secure your API integration and webhook endpoints