Create Payment Intent
Overview
- Function: Create a new payment intent for USDC settlement on Base chain
- Use Cases: E-commerce checkout, initiate payment request, automated payouts
- Authentication: Optional (public mode) or Required (authenticated mode with Bearer token)
JSON Schema Definition
{
"name": "create_payment_intent",
"description": "Creates a new payment intent for USDC settlement on Base chain. Returns an intent ID for subsequent operations.",
"input_schema": {
"type": "object",
"properties": {
"email": {
"type": "string",
"description": "Recipient email address. Required if recipient is not provided."
},
"recipient": {
"type": "string",
"description": "Recipient wallet address. Required if email is not provided."
},
"amount": {
"type": "string",
"description": "USDC amount as string (e.g. '100.50'). Minimum: 0.01, Maximum: 1,000,000. Up to 6 decimal places.",
"pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
},
"payer_chain": {
"type": "string",
"description": "Source chain identifier. See Supported Chains documentation for the full list of supported chains."
}
},
"required": ["amount", "payer_chain"],
"oneOf": [
{ "required": ["email"] },
{ "required": ["recipient"] }
]
},
"output_schema": {
"type": "object",
"properties": {
"intent_id": {
"type": "string",
"description": "Unique identifier for the created intent"
},
"status": {
"type": "string",
"enum": ["AWAITING_PAYMENT"],
"description": "Initial status of the intent"
},
"expires_at": {
"type": "string",
"format": "date-time",
"description": "ISO 8601 timestamp when the intent expires (10 minutes after creation)"
}
},
"required": ["intent_id", "status"]
}
}
Parameters
Amount Rules
- Minimum: 0.01 USDC
- Note: The JS/TS SDK enforces a 0.02 USDC minimum client-side (
MIN_SEND_AMOUNT_USDC). - Maximum: 1,000,000 USDC
- Precision: Up to 6 decimal places (e.g.
"0.000001","123.45")
Return Value
Success Response
{
"intent_id": "int_abc123xyz",
"status": "AWAITING_PAYMENT",
"expires_at": "2024-01-01T12:10:00Z",
"fee_breakdown": {
"source_chain": "base",
"source_chain_fee": "0.001",
"target_chain": "base",
"target_chain_fee": "0.0001",
"platform_fee": "1.00",
"platform_fee_percentage": "1.0",
"total_fee": "1.0011"
}
}
Error Response
See Error Handling for detailed error information.
Code Examples
TypeScript/JavaScript
import { PayClient } from '@cross402/usdc';
const client = new PayClient({
baseUrl: 'https://api-pay.agent.tech',
auth: { apiKey: 'your-api-key', secretKey: 'your-secret-key' },
});
// Create intent with email
const intent = await client.createIntent({
email: "merchant@example.com",
amount: "100.50",
payerChain: "base"
});
console.log(`Intent created: ${intent.intentId}`);
console.log(`Status: ${intent.status}`);
Go
package main
import (
"context"
"log"
"github.com/cross402/usdc-sdk-go"
)
func main() {
client, err := pay.NewClient(
"https://api-pay.agent.tech",
pay.WithBearerAuth(apiKey, secretKey),
)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Create intent with email
resp, err := client.CreateIntent(ctx, &pay.CreateIntentRequest{
Email: "merchant@example.com",
Amount: "100.50",
PayerChain: "base",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Intent created: %s", resp.IntentID)
log.Printf("Status: %s", resp.Status)
}
Error Handling
Common Errors
For comprehensive error handling patterns and retry strategies, see Error Handling.
Important Notes
Intent Expiration: Intents expire 10 minutes after creation. If not executed within this window, the status becomes
EXPIRED(terminal state).Authentication Modes:
- Public Mode: No auth required, uses
/apiendpoints - Authenticated Mode: Requires Bearer token, uses
/v2endpoints
- Public Mode: No auth required, uses
Chain Support: See Supported Chains for the full list of 7 supported chains.
Settlement: All payments ultimately settle on Base chain regardless of the source chain.