@plasmacheckout/sdk
v0.2.0
Published
Official Node.js/TypeScript SDK for the Plasma Checkout API
Maintainers
Readme
@plasmacheckout/sdk
Official Node.js/TypeScript SDK for the Plasma Checkout API.
Installation
npm install @plasmacheckout/sdk
# or
pnpm add @plasmacheckout/sdkQuick Start
import { PlasmaSDK } from '@plasmacheckout/sdk';
const plasma = new PlasmaSDK({
apiKey: 'pk_live_xxx',
secretKey: 'sk_live_xxx',
});Products
// List products
const { data, pagination } = await plasma.products.list({ limit: 10 });
// Get a product
const { data: product } = await plasma.products.get('product_id');
// Create a product
const { data: newProduct } = await plasma.products.create({
title: 'T-Shirt',
price: 9990,
status: 'active',
});
// Update a product
const { data: updated } = await plasma.products.update('product_id', {
title: 'Updated T-Shirt',
price: 12990,
});
// Delete a product
await plasma.products.delete('product_id');Orders
// List orders
const { data: orders } = await plasma.orders.list({ status: 'pending' });
// Get an order
const { data: order } = await plasma.orders.get('order_id');
// Create an order
const { data: newOrder } = await plasma.orders.create({
customer: { email: '[email protected]', name: 'John Doe' },
items: [{ title: 'T-Shirt', price: 9990, quantity: 2 }],
});
// Update order status
const { data: updatedOrder } = await plasma.orders.update('order_id', {
status: 'completed',
paymentStatus: 'paid',
});Checkout
// Create a checkout link
const { data: session } = await plasma.checkout.createLink({
items: [{ title: 'T-Shirt', price: 9990, quantity: 1 }],
successUrl: 'https://mystore.com/success',
cancelUrl: 'https://mystore.com/cancel',
});
console.log(session.checkoutUrl); // https://checkout.plasmacheckout.com/ck_xxx
// Get session details
const { data: details } = await plasma.checkout.getSession('ck_xxx');Customers
// List customers
const { data: customers } = await plasma.customers.list();
// Get customer by email
const { data: customer } = await plasma.customers.get('[email protected]', {
includeOrders: true,
ordersLimit: 5,
});Webhooks
// List deliveries
const { data: deliveries } = await plasma.webhooks.list();
// Get stats
const { data: stats } = await plasma.webhooks.stats();
// Verify webhook signature
import { verifyWebhookSignature } from '@plasmacheckout/sdk';
app.post('/webhooks', (req, res) => {
const signature = req.headers['x-plasma-signature'];
const isValid = verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET);
if (!isValid) return res.status(401).send('Invalid signature');
// Process webhook event...
});Error Handling
import { PlasmaError } from '@plasmacheckout/sdk';
try {
await plasma.products.get('nonexistent');
} catch (error) {
if (error instanceof PlasmaError) {
console.log(error.code); // 'NOT_FOUND'
console.log(error.statusCode); // 404
console.log(error.message); // 'Product not found'
}
}Configuration
const plasma = new PlasmaSDK({
apiKey: 'pk_live_xxx',
secretKey: 'sk_live_xxx',
baseUrl: 'https://api.plasmacheckout.com', // optional
timeout: 30000, // optional, in ms
});License
MIT
