Configuration
The BuyButton component accepts various configuration props to customize its behavior and appearance. This page documents all available configuration options.
BuyButton Props
| Name | Type | Default |
|---|---|---|
config | BuyButtonConfigPayment configuration object containing backend URL, callback URL, products, and metadata | |
label | stringText displayed on the button | |
variant | 'default' | 'outline' | 'ghost' | 'destructive'Visual style variant of the button | |
size | 'sm' | 'md' | 'lg'Size of the button | |
disabled | booleanWhether the button is disabled | |
className | stringAdditional CSS classes to apply to the button | |
style | React.CSSPropertiesInline styles to apply to the button | |
onSuccess | (sessionId: string) => voidCallback function called when payment session is successfully created | |
onError | (error: string) => voidCallback function called when payment session creation fails | |
BuyButtonConfig Interface
The config prop accepts a BuyButtonConfig object with the following properties:
| Name | Type | Default |
|---|---|---|
backendUrl | stringYour API endpoint URL for creating payment sessions (e.g., '/api/okito') | |
callbackUrl | stringURL where users are redirected after successful payment (your app's success page) | |
products | Product[]Array of products to purchase | |
metadata | Record<string, any>Optional metadata object for tracking and analytics | |
Product Interface
Each product in the products array should follow the Product interface:
| Name | Type | Default |
|---|---|---|
id | stringUnique identifier for the product | |
name | stringDisplay name of the product | |
price | numberPrice of the product in USD | |
description | stringOptional description of the product | |
quantity | numberQuantity of the product (defaults to 1) | |
metadata | Record<string, any>Optional product-specific metadata | |
Configuration Examples
Basic Configuration
<BuyButton
config={{
backendUrl: "/api/okito",
callbackUrl: "https://your-app.com/success",
products: [
{ name: "Premium Plan", price: 29.99 }
]
}}
label="Subscribe Now"
/>Advanced Configuration
<BuyButton
config={{
backendUrl: "/api/okito",
callbackUrl: "https://your-app.com/success",
products: [
{
id: "premium-monthly",
name: "Premium Plan",
price: 29.99,
description: "Monthly subscription with all features",
quantity: 1,
metadata: {
category: "subscription",
plan: "premium"
}
}
],
metadata: {
userId: "user-123",
source: "landing-page",
campaign: "summer-sale"
}
}}
label="Get Premium"
variant="outline"
size="lg"
onSuccess={(sessionId) => {
console.log("Payment started:", sessionId);
// Track analytics or redirect
}}
onError={(error) => {
console.error("Payment failed:", error);
// Show error message to user
}}
/>Styling Configuration
<BuyButton
config={config}
className="w-full bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600"
style={{
borderRadius: "12px",
fontWeight: "bold"
}}
size="lg"
/>Required vs Optional Props
Required Props
config: Must includebackendUrl,callbackUrl, andproductsproducts: Each product must havenameandprice
Optional Props
- All other props have default values or are optional
metadatacan be omitted if not neededonSuccessandonErrorcallbacks are optional but recommended
Best Practices
- Always provide meaningful product names for better user experience
- Use descriptive callback URLs that clearly indicate success
- Include metadata for analytics and tracking purposes
- Handle errors gracefully with the
onErrorcallback - Test thoroughly with different product configurations
- Use HTTPS for callback URLs in production
- Validate products on your backend before creating payment sessions
TypeScript Support
The component is fully typed with TypeScript interfaces:
interface BuyButtonConfig {
backendUrl: string;
callbackUrl: string;
products: Product[];
metadata?: Record<string, any>;
}
interface Product {
id?: string;
name: string;
price: number;
description?: string;
quantity?: number;
metadata?: Record<string, any>;
}This ensures type safety and provides excellent IDE support with autocomplete and error checking.
Last updated on