Phoenix Wallet

Credits

API endpoint for adding funds to wallets

Credits add funds to a wallet. Each credit creates a new lot (value tranche) that can have its own attributes, expiry date, and restrictions.

Create Credit

Add funds to a wallet by creating a new lot.

POST /credits

Request Headers

HeaderRequiredDescription
AuthorizationYesBearer token
Content-TypeYesapplication/json
Idempotency-KeyYesUnique request identifier

Request Body

FieldTypeRequiredDescription
wallet_idstringYesTarget wallet ID
amountstringYesAmount to credit (decimal string)
assetstringYesAsset type (e.g., POINTS, BONUS)
referencestringNoYour reference for this transaction
metadataobjectNoCustom key-value pairs
lotobjectNoLot configuration

Lot Configuration

FieldTypeRequiredDescription
lot.expires_atstringNoISO 8601 expiration timestamp
lot.attributesobjectNoCustom lot attributes
lot.restrictionsarrayNoRestriction rules for this lot

Example Request

curl -X POST {{BASE_URL}}/credits \
  -H "Authorization: Bearer {{API_KEY}}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: {{IDEMPOTENCY_KEY}}" \
  -d '{
    "wallet_id": "wal_abc123def456",
    "amount": "500.00",
    "asset": "POINTS",
    "reference": "purchase_order_789",
    "metadata": {
      "source": "loyalty_program",
      "campaign": "winter_2024"
    },
    "lot": {
      "expires_at": "2024-12-31T23:59:59Z",
      "attributes": {
        "source": "promotion",
        "tier_multiplier": 1.5
      },
      "restrictions": [
        {
          "type": "category",
          "allowed": ["merchandise", "food"]
        }
      ]
    }
  }'

Example Response

{
  "data": {
    "id": "crd_xyz789abc123",
    "wallet_id": "wal_abc123def456",
    "amount": "500.00",
    "asset": "POINTS",
    "reference": "purchase_order_789",
    "status": "completed",
    "lot": {
      "id": "lot_mno456pqr789",
      "amount": "500.00",
      "asset": "POINTS",
      "expires_at": "2024-12-31T23:59:59Z",
      "attributes": {
        "source": "promotion",
        "tier_multiplier": 1.5
      },
      "restrictions": [
        {
          "type": "category",
          "allowed": ["merchandise", "food"]
        }
      ],
      "created_at": "2024-01-15T10:30:00Z"
    },
    "metadata": {
      "source": "loyalty_program",
      "campaign": "winter_2024"
    },
    "created_at": "2024-01-15T10:30:00Z"
  }
}

Error Codes

CodeDescription
WALLET_NOT_FOUNDTarget wallet does not exist
WALLET_SUSPENDEDCannot credit a suspended wallet
INVALID_AMOUNTAmount must be a positive decimal
INVALID_ASSETAsset type is not configured
POLICY_VIOLATIONCredit violates wallet policies
VALIDATION_ERRORRequest body validation failed

Credit with Policy Override

In some cases, you may need to credit a wallet while bypassing certain policy checks. This requires elevated permissions.

POST /credits

Additional Request Body Fields

FieldTypeRequiredDescription
skip_policiesarrayNoPolicy IDs to skip (requires elevated permissions)
reasonstringConditionalRequired when using skip_policies

Example Request

curl -X POST {{BASE_URL}}/credits \
  -H "Authorization: Bearer {{API_KEY}}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: {{IDEMPOTENCY_KEY}}" \
  -d '{
    "wallet_id": "wal_abc123def456",
    "amount": "1000.00",
    "asset": "POINTS",
    "reference": "manual_adjustment_001",
    "skip_policies": ["pol_max_balance"],
    "reason": "Customer service compensation - ticket #12345"
  }'

Error Codes

CodeDescription
INSUFFICIENT_PERMISSIONSAPI key does not have policy override permissions
REASON_REQUIREDReason is required when skipping policies

Bulk Credit

Credit multiple wallets in a single request.

POST /credits/bulk

Request Body

FieldTypeRequiredDescription
creditsarrayYesArray of credit objects (max 100)
atomicbooleanNoIf true, all credits succeed or all fail (default: false)

Example Request

curl -X POST {{BASE_URL}}/credits/bulk \
  -H "Authorization: Bearer {{API_KEY}}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: {{IDEMPOTENCY_KEY}}" \
  -d '{
    "credits": [
      {
        "wallet_id": "wal_abc123def456",
        "amount": "100.00",
        "asset": "POINTS",
        "reference": "bulk_credit_001"
      },
      {
        "wallet_id": "wal_def456ghi789",
        "amount": "100.00",
        "asset": "POINTS",
        "reference": "bulk_credit_002"
      }
    ],
    "atomic": false
  }'

Example Response

{
  "data": {
    "successful": [
      {
        "id": "crd_xyz789abc123",
        "wallet_id": "wal_abc123def456",
        "amount": "100.00",
        "asset": "POINTS",
        "reference": "bulk_credit_001",
        "status": "completed"
      }
    ],
    "failed": [
      {
        "wallet_id": "wal_def456ghi789",
        "reference": "bulk_credit_002",
        "error": {
          "code": "WALLET_SUSPENDED",
          "message": "Cannot credit a suspended wallet"
        }
      }
    ],
    "summary": {
      "total": 2,
      "successful": 1,
      "failed": 1
    }
  }
}

Error Codes

CodeDescription
BATCH_SIZE_EXCEEDEDMore than 100 credits in batch
ATOMIC_BATCH_FAILEDOne or more credits failed in atomic mode

Get Credit

Retrieve details of a specific credit transaction.

GET /credits/{{CREDIT_ID}}

Path Parameters

ParameterTypeDescription
credit_idstringThe credit ID (e.g., crd_xyz789abc123)

Example Request

curl -X GET {{BASE_URL}}/credits/{{CREDIT_ID}} \
  -H "Authorization: Bearer {{API_KEY}}"

Example Response

{
  "data": {
    "id": "crd_xyz789abc123",
    "wallet_id": "wal_abc123def456",
    "amount": "500.00",
    "asset": "POINTS",
    "reference": "purchase_order_789",
    "status": "completed",
    "lot": {
      "id": "lot_mno456pqr789",
      "amount": "500.00",
      "remaining": "350.00",
      "asset": "POINTS",
      "expires_at": "2024-12-31T23:59:59Z"
    },
    "metadata": {
      "source": "loyalty_program",
      "campaign": "winter_2024"
    },
    "created_at": "2024-01-15T10:30:00Z"
  }
}

Error Codes

CodeDescription
CREDIT_NOT_FOUNDNo credit exists with this ID