Charge Management API
Create Wallet Charge
Creates a new payment charge for the wallet with QR code generation.
Endpoint
http
POST /api/wallet/{wallet}/charge/createParameters
wallet(integer): Wallet ID
Request Body
json
{
"token": "ETH",
"amount": 0.1,
"expires": 300,
"mode": "dynamic"
}Request Parameters
token(string, required): Token symbolamount(numeric, required): Charge amountexpires(numeric, optional): Expiration time in seconds (default: 300)mode(string, optional): Charge mode - "dynamic" or "static" (default: "dynamic")
Response
json
{
"status": "success",
"message": "Wallet charge made successfully",
"data": {
"id": 1,
"wallet_id": 1,
"sub_wallet_id": null,
"token_id": 1,
"amount": "0.100000000000000000",
"status": "pending",
"mode": "dynamic",
"expires": 300,
"content": "ethereum:0x0b88b41fdc5b2127c4082145fc34828b7d20a301@97?data=0xa9059cbb0000000000000000000000000b88b41fdc5b2127c4082145fc34828b7d20a3010000000000000000000000000000000000000000000000000058d15e17628000",
"info": null,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00"
}
}Example Request
bash
curl -X POST \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{"token":"ETH","amount":0.1,"expires":300,"mode":"dynamic"}' \
https://zafira-app.vratts.com/api/wallet/1/charge/createGet Wallet Charge
Retrieves details for a specific charge.
Endpoint
http
GET /api/wallet/{wallet}/charge/show/{charge}Parameters
wallet(integer): Wallet IDcharge(integer): Charge ID
Response
json
{
"status": "success",
"message": "Charge fetched successfully",
"data": {
"id": 1,
"wallet_id": 1,
"sub_wallet_id": null,
"token_id": 1,
"amount": "0.100000000000000000",
"status": "pending",
"mode": "dynamic",
"expires": 300,
"content": "ethereum:0x0b88b41fdc5b2127c4082145fc34828b7d20a301@97?data=0xa9059cbb0000000000000000000000000b88b41fdc5b2127c4082145fc34828b7d20a3010000000000000000000000000000000000000000000000000058d15e17628000",
"info": null,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00"
}
}Example Request
bash
curl -H "Authorization: Bearer {token}" \
https://zafira-app.vratts.com/api/wallet/1/charge/show/1Charge Model Details
Fields
id(integer): Unique charge identifierwallet_id(integer): Associated wallet IDsub_wallet_id(integer, nullable): Associated sub-wallet IDtoken_id(integer): Associated token IDamount(decimal): Charge amount (18 decimal places)status(string): Charge status (auto-calculated)mode(string): Charge mode ("dynamic" or "static")expires(integer): Expiration time in seconds from creationcontent(text): QR code content for paymentinfo(text, nullable): Additional charge informationuuid(string): Unique identifier for payment linkcreated_at(datetime): Creation timestampupdated_at(datetime): Last update timestamp
Charge Status Logic
The status is automatically calculated based on expiration time:
pending: Charge created but not yet paidconfirmed: Charge has been paidfailed: Payment failedexpired: Charge expired without payment
Charge Modes
dynamic: Amount can be adjusted by payerstatic: Fixed amount, cannot be changed
Payment Link Generation
QR Code Content
The content field contains the QR code data in URI format:
ethereum:0x0b88b41fdc5b2127c4082145fc34828b7d20a301@97?data=0xa9059cbb...Payment Link URL
Use the UUID to generate payment links:
https://zafira-app.domain.com/wallet/pay/{uuid}For example, with UUID edc86a93-f0ef-4bd7-a203-b48ee02f5c06:
https://zafira-app.domain.com/wallet/pay/edc86a93-f0ef-4bd7-a203-b48ee02f5c06QR Code Integration
The content field can be used directly with QR code generation libraries:
javascript
// Example QR code generation
const QRCode = require('qrcode');
const qrContent = charge.data.content;
const qrCodeImage = await QRCode.toDataURL(qrContent);Charge Expiration
Expiration Handling
- Charges automatically expire after the specified time
- Expiration time is calculated from creation timestamp
- Expired charges cannot be paid
- Status automatically updates to "expired"
Default Expiration
- Default expiration: 300 seconds (5 minutes)
- Maximum expiration: 3600 seconds (1 hour)
- Minimum expiration: 60 seconds (1 minute)
Error Handling
Common Errors
Charge Not Found (404)
json
{
"status": "error",
"message": "Charge not found",
"data": null
}Invalid Amount (422)
json
{
"status": "error",
"message": "The amount field is required",
"data": {
"amount": ["The amount field is required."]
}
}Invalid Token (422)
json
{
"status": "error",
"message": "The token field is required",
"data": {
"token": ["The token field is required."]
}
}Invalid Expiration (422)
json
{
"status": "error",
"message": "The expires field must be between 60 and 3600",
"data": {
"expires": ["The expires field must be between 60 and 3600."]
}
}Charge Expired (400)
json
{
"status": "error",
"message": "Charge has expired",
"data": null
}Charge Lifecycle
1. Creation
- Charge is created with specified amount and expiration
- UUID is generated for payment link
- QR code content is generated
- Status is set to "pending"
2. Payment Processing
- Payment is detected on blockchain
- Status updates to "confirmed"
- Webhook notifications are triggered
- Balance is updated
3. Expiration
- If not paid within expiration time
- Status automatically updates to "expired"
- Charge becomes unusable
4. Completion
- Charge remains in database for record keeping
- Can be retrieved for historical purposes
- Status reflects final state
Webhook Integration
Charge Events
Charges trigger webhook events:
charge.created: When charge is createdcharge.paid: When payment is confirmedcharge.expired: When charge expirescharge.failed: When payment fails
Webhook Payload Example
json
{
"event": "charge.paid",
"data": {
"charge_id": 1,
"wallet_id": 1,
"amount": "0.100000000000000000",
"token": "ETH",
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"status": "confirmed"
}
}Best Practices
Charge Management
- Set appropriate expiration times based on use case
- Use descriptive charge information for tracking
- Monitor charge status through webhooks
- Implement proper error handling for expired charges
Security Considerations
- Validate all incoming payment data
- Use HTTPS for payment links
- Implement rate limiting for charge creation
- Monitor for suspicious charge patterns
Next Steps
- Webhook Management - Set up charge notifications
- Transaction Management - Handle payment transactions
- API Examples - Practical charge usage examples