Stripe Provider
The Stripe provider allows you to synchronize your pricing configuration with the Stripe billing platform.
Setup
To use the Stripe provider, you need to set up your Stripe API key. You can do this in several ways:
Using Environment Variables
Add your Stripe secret key to your environment variables:
# .env file
STRIPE_SECRET_KEY=sk_test_your_stripe_key
Using Configuration Options
Pass your Stripe secret key as a configuration option:
import { pac } from 'prices-as-code';
async function syncPricing() {
const result = await pac({
configPath: './pricing.ts',
providers: [
{
provider: 'stripe',
options: {
secretKey: 'sk_test_your_stripe_key',
}
}
]
});
console.log('Sync result:', result);
}
Configuration
When using the Stripe provider, you can configure the following options:
StripeProviderOptions
Properties
Name | Type | Description |
---|---|---|
secretKey | string | Your Stripe secret key |
apiVersion | string | (Optional) The Stripe API version to use |
Product Configuration
When defining products for Stripe, you can use the following properties:
const product = {
provider: 'stripe',
name: 'Basic Plan',
description: 'For individuals and small teams',
features: ['5 projects', '10GB storage', 'Email support'],
active: true, // Whether the product is active
images: [], // Array of image URLs
metadata: { // Custom metadata
displayOrder: 1
}
};
Price Configuration
When defining prices for Stripe, you can use the following properties:
const price = {
provider: 'stripe',
name: 'Basic Monthly',
nickname: 'Basic Monthly',
unitAmount: 999, // Amount in cents
currency: 'usd',
type: 'recurring',
recurring: {
interval: 'month', // 'day', 'week', 'month', or 'year'
intervalCount: 1, // Billing frequency
usageType: 'licensed' // 'licensed' or 'metered'
},
productKey: 'basic_plan',
metadata: {
displayName: 'Basic Monthly'
}
};
Never commit your Stripe secret key to version control. Always use environment variables or secure configuration management for sensitive keys.