Convert to Credit Webhooks

Overview

Convert to Credit (C2C) webhooks enable users to exchange their Lucra cash balance for credits in your system. When a user initiates a C2C transaction, Lucra temporarily holds the dollar amount and sends a webhook to your endpoint for credit fulfillment.

Prerequisites

Important Constraints

  • The C2CWithdrawal subscription can only exist in one webhook configuration at a time

  • See Webhook Setup for details on subscription restrictions

C2CWithdrawal Event

The C2CWithdrawal event fires when a user requests to convert their Lucra balance to credits in your system.

Webhook Flow

  1. User initiates Convert to Credit transaction

  2. Lucra temporarily holds the dollar amount

  3. Amount is deducted from user's balance

  4. Webhook sent to your endpoint

  5. Your system grants credits

  6. Your endpoint returns success/failure response

  7. Lucra finalizes or reverses the transaction based on response

Payload

Field Descriptions

Field
Type
Description

intentId

string

UUID passed from SDK - use for idempotency tracking

userId

string

Lucra's canonical user identifier (UUID)

amount

number

Dollar amount deducted from user's Lucra balance

convertedAmount

number

Credit amount to grant after multiplier applied

conversionMetadata

object|null

Custom data passed via SDK (null by default)

Notes:

  • intentId is unique per transaction - use for idempotency

  • amount is what the user paid in dollars

  • convertedAmount reflects any conversion multiplier (e.g., 1.2x bonus)

  • conversionMetadata can contain arbitrary custom data for tracking

Response Format

Your endpoint must respond synchronously with a JSON object indicating transaction outcome.

Success Response

Failure Response

Pending Response

Response Fields

Field
Type
Required
Description

status

string

Yes

Transaction status: COMPLETED, FAILED, or PENDING (case-sensitive)

responseText

string

Yes

User-facing message displayed in the UI

responseDetails

any

No

Arbitrary JSON data stored for support inquiries

Status Values:

  • COMPLETED: Credits successfully granted. Dollar amount remains deducted from user's Lucra balance.

  • FAILED: Credits not granted. Dollar amount returned to user's Lucra balance.

  • PENDING: Processing continues asynchronously. Dollar amount remains deducted. Use for delayed fulfillment scenarios.

Important:

  • responseText is shown directly to the user - make it clear and friendly

  • responseDetails is for internal tracking and support purposes

  • Status values are case-sensitive

Implementation Examples

Basic Implementation (Node.js/Express)

Advanced Implementation with Validation

Async Processing with PENDING Status

Best Practices

1. Idempotency

Always check for duplicate processing using intentId:

2. User-Friendly Messages

Craft clear responseText messages for different scenarios:

3. Comprehensive Logging

Log all C2C transactions for audit and support:

4. Error Recovery

Implement graceful error handling with meaningful responses:

5. Conversion Metadata Usage

Leverage conversionMetadata for business logic:

6. Timeout Handling

Set appropriate timeouts for synchronous processing:

TypeScript Types

Security Considerations

  1. Signature Verification: Always verify webhook signatures per Webhook Setup

  2. HTTPS Only: C2C webhooks must be received over HTTPS

  3. Idempotency: Use intentId to prevent duplicate credit grants

  4. User Validation: Verify user exists and is eligible before granting credits

  5. Rate Limiting: Prevent abuse by limiting conversions per user per time period

  6. Audit Logging: Log all transactions for compliance and fraud detection

Testing

Test Payload

Last updated