prices-as-code
Version:
Prices as Code (PaC) - Define your product pricing schemas with type-safe definitions
169 lines (144 loc) • 6.04 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stripe Provider - Prices as Code</title>
<meta name="description" content="Stripe integration for the Prices as Code TypeScript library">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="icon" href="https://raw.githubusercontent.com/wickdninja/assets/refs/heads/main/PaC.webp">
</head>
<body>
<header class="site-header">
<div class="container">
<div class="header-content">
<div class="logo">
<a href="../index.html">
<img src="https://raw.githubusercontent.com/wickdninja/assets/refs/heads/main/PaC.webp" alt="Prices as Code" width="40">
<span>Prices as Code</span>
</a>
</div>
<nav class="main-nav">
<ul>
<li><a href="../guides/index.html">Guides</a></li>
<li><a href="../api/index.html">API</a></li>
<li><a href="index.html" class="active">Providers</a></li>
<li><a href="https://github.com/wickdninja/prices-as-code" target="_blank">GitHub</a></li>
<li><a href="https://www.npmjs.com/package/prices-as-code" target="_blank">NPM</a></li>
</ul>
</nav>
</div>
</div>
</header>
<main class="content">
<div class="container">
<h1>Stripe Provider</h1>
<p>The Stripe provider allows you to synchronize your pricing configuration with the <a href="https://stripe.com" target="_blank">Stripe</a> billing platform.</p>
<h2>Setup</h2>
<p>To use the Stripe provider, you need to set up your Stripe API key. You can do this in several ways:</p>
<h3>Using Environment Variables</h3>
<p>Add your Stripe secret key to your environment variables:</p>
<div class="highlight">
<pre><code># .env file
STRIPE_SECRET_KEY=sk_test_your_stripe_key</code></pre>
</div>
<h3>Using Configuration Options</h3>
<p>Pass your Stripe secret key as a configuration option:</p>
<div class="highlight">
<pre><code class="language-typescript">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);
}</code></pre>
</div>
<h2>Configuration</h2>
<p>When using the Stripe provider, you can configure the following options:</p>
<div class="api-method">
<div class="method-title">StripeProviderOptions</div>
<div class="parameters">
<h4>Properties</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>secretKey</td>
<td>string</td>
<td>Your Stripe secret key</td>
</tr>
<tr>
<td>apiVersion</td>
<td>string</td>
<td>(Optional) The Stripe API version to use</td>
</tr>
</tbody>
</table>
</div>
</div>
<h2>Product Configuration</h2>
<p>When defining products for Stripe, you can use the following properties:</p>
<div class="highlight">
<pre><code class="language-typescript">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
}
};</code></pre>
</div>
<h2>Price Configuration</h2>
<p>When defining prices for Stripe, you can use the following properties:</p>
<div class="highlight">
<pre><code class="language-typescript">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'
}
};</code></pre>
</div>
<div class="warning">
<p>Never commit your Stripe secret key to version control. Always use environment variables or secure configuration management for sensitive keys.</p>
</div>
</div>
</main>
<footer class="site-footer">
<div class="container">
<div class="footer-content">
<p>Copyright © 2025 Nate Ross. Distributed by an <a href="https://github.com/wickdninja/prices-as-code/blob/main/LICENSE">MIT license.</a></p>
<p><a href="#top" class="back-to-top">Back to top</a></p>
</div>
</div>
</footer>
<script src="../assets/js/main.js"></script>
</body>
</html>