Initialization

import { coss } from '@coss';
coss.payments.init({
apiKey: process.env.COSS_KEY,
environment: 'production', // or 'sandbox'
});

Products

// Create a product
await coss.payments.products.create({
name: 'Pro Plan',
description: 'Access to premium features',
});
// List products
await coss.payments.products.list();
// Retrieve a product
await coss.payments.products.retrieve('prod_abc123');
// Update a product
await coss.payments.products.update('prod_abc123', {
description: 'Updated description',
});
// Delete a product
await coss.payments.products.delete('prod_abc123');

Prices

// Create a price for a product
await coss.payments.prices.create({
productId: 'prod_abc123',
unitAmount: 2000, // in cents
currency: 'usd',
recurring: { interval: 'month' },
});
// List prices
await coss.payments.prices.list();

Customers

// Create a customer
await coss.payments.customers.create({
email: 'jane@example.com',
name: 'Jane Doe',
});
// Retrieve a customer
await coss.payments.customers.retrieve('cus_abc123');

Subscriptions

// Create a subscription
await coss.payments.subscriptions.create({
customerId: 'cus_abc123',
priceId: 'price_abc123',
});
// Retrieve a subscription
await coss.payments.subscriptions.retrieve('sub_abc123');
// Update a subscription (e.g., upgrade plan)
await coss.payments.subscriptions.update('sub_abc123', {
priceId: 'price_def456',
});
// Cancel a subscription
await coss.payments.subscriptions.cancel('sub_abc123');

Invoices

// Create an invoice manually
await coss.payments.invoices.create({
customerId: 'cus_abc123',
items: [
{ priceId: 'price_abc123', quantity: 1 },
],
});
// Finalize and send the invoice
await coss.payments.invoices.finalize('inv_abc123');
// Pay an invoice
await coss.payments.invoices.pay('inv_abc123');

Webhooks

// Webhook events
coss.payments.webhooks.on('invoice.paid', (event) => {
console.log('Invoice paid:', event.data);
});
coss.payments.webhooks.on('subscription.created', (event) => {
console.log('Subscription created:', event.data);
});

Utilities

// Validate webhook signature
const isValid = coss.payments.utils.verifySignature({
payload: req.body,
signature: req.headers['coss-payments-signature'],
secret: 'whsec_payments_123',
});
Join the waitlistJoin the company