API Reference
This section provides detailed documentation for the Prices as Code API.
Core API
pac(options: PacOptions): Promise<PacResult>
The main function to synchronize your pricing configuration with providers.
Parameters
Name | Type | Description |
---|---|---|
options | PacOptions | Configuration options for the synchronization |
Returns
A Promise that resolves to a PacResult object containing the synchronization results.
Example
import { pac } from 'prices-as-code';
async function syncPricing() {
try {
const result = await pac({
configPath: './pricing.ts',
providers: [
{
provider: 'stripe',
options: {
secretKey: process.env.STRIPE_SECRET_KEY,
}
}
]
});
console.log('Sync result:', result);
} catch (error) {
console.error('Sync failed:', error);
}
}
syncPricing();
Types
Config
Represents the pricing configuration.
Properties
Name | Type | Description |
---|---|---|
products | Product[] | Array of product definitions |
prices | Price[] | Array of price definitions |
Product
Represents a product definition.
Properties
Name | Type | Description |
---|---|---|
provider | string | The provider to create the product with (e.g., 'stripe') |
name | string | The name of the product |
description | string | The description of the product |
features | string[] | Features included with the product |
highlight | boolean | Whether to highlight this product as recommended |
metadata | Record<string, any> | Additional metadata to associate with the product |
Price
Represents a price definition.
Properties
Name | Type | Description |
---|---|---|
provider | string | The provider to create the price with (e.g., 'stripe') |
name | string | The name of the price |
nickname | string | A shorter name for the price that will appear on invoices |
unitAmount | number | The amount in the smallest currency unit (e.g., cents) |
currency | string | The three-letter ISO currency code |
type | string | The price type (e.g., 'one_time', 'recurring') |
recurring | object | Recurring price configuration |
productKey | string | Key of the product this price belongs to |
metadata | Record<string, any> | Additional metadata to associate with the price |
For more detailed API documentation, please refer to the TypeScript type definitions or check the GitHub repository.