Skip to main content

Overview

The credit.purchased webhook is triggered when credits are purchased or provisioned for a customer in your Metrifox account. Credits can be used to pay for usage-based features or other charges.

When It’s Triggered

This event is sent immediately after credits are successfully purchased or provisioned, which can happen when:
  • A customer purchases credits through checkout
  • Credits are manually assigned to a customer
  • Credits are provisioned through the API
  • Credits are added as part of a plan or promotion

Payload Structure

{
  "id": "550e8400-e29b-41d4-a716-446655440008",
  "type": "credit.purchased",
  "created_at": 1704067680000,
  "data": {
    "credit_allocation": {
      "id": "401",
      "wallet_id": "wallet_123",
      "customer_id": "123",
      "customer_key": "cust_abc123",
      "amount": 1000.00,
      "currency": "USD",
      "credit_type": "prepaid",
      "expires_at": "2025-01-01T00:00:00Z",
      "tenant_id": "456",
      "created_at": "2024-01-01T00:08:00Z",
      "updated_at": "2024-01-01T00:08:00Z"
      // ... other credit allocation fields
    },
    "wallet": {
      "id": "wallet_123",
      "customer_id": "123",
      "balance": 1000.00,
      "currency": "USD"
      // ... other wallet fields
    }
  }
}

Data Fields

The payload includes credit allocation and wallet information:

data.credit_allocation

  • id: Internal credit allocation ID
  • wallet_id: ID of the wallet the credits were added to
  • customer_id: ID of the customer who received the credits
  • customer_key: Customer key
  • amount: Amount of credits purchased/provisioned
  • currency: Currency code (e.g., “USD”, “NGN”)
  • credit_type: Type of credit (e.g., “prepaid”, “promotional”)
  • expires_at: Expiration date for the credits (if applicable)
  • tenant_id: The tenant ID this credit allocation belongs to
  • created_at: Timestamp when the credits were purchased
  • updated_at: Timestamp when the credit allocation was last updated
  • Additional credit allocation-specific fields

data.wallet (optional)

  • id: Wallet ID
  • customer_id: ID of the customer who owns the wallet
  • balance: Current wallet balance after the credit purchase
  • currency: Currency code
  • Additional wallet-specific fields

Example Use Cases

  • Send credit purchase confirmation emails
  • Update customer credit balance in your system
  • Trigger notifications about available credits
  • Sync credit purchases to your accounting system
  • Track credit usage and analytics
  • Update customer dashboards with credit information