multivendor-stripe
v0.0.1
Published
Framework-agnostic Stripe SDK wrapper for payment intents, checkout, webhooks, and refunds
Maintainers
Readme
multivendor-stripe
Framework-agnostic Stripe SDK wrapper for payment intents, checkout sessions, webhooks, and refunds.
Install
npm install multivendor-stripeThe stripe SDK is included as a dependency — you do not need to install stripe or @types/stripe separately.
Usage
import { StripeClient } from 'multivendor-stripe';
const client = new StripeClient({
secretKey: process.env.STRIPE_SECRET_KEY!,
publishableKey: process.env.STRIPE_PUBLISHABLE_KEY,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
});
// Create a payment intent
const paymentIntent = await client.createPaymentIntent({
amount: 99.99,
currency: 'usd',
description: 'Order #12345',
metadata: {
orderId: '12345',
orderPrefixId: 'ORD-12345',
customerId: '678',
},
});
// Verify webhook
const event = client.verifyWebhookSignature(rawBody, signature);
// Parse successful payment
const result = client.parsePaymentSuccess(paymentIntent);
// Create refund
const refund = await client.createRefund('pi_xxx', 50.0, 'requested_by_customer');API
| Method | Description |
|--------|-------------|
| getPublishableKey() | Returns configured publishable key |
| createPaymentIntent(params) | Create a PaymentIntent |
| confirmPaymentIntent(id, methodId?) | Confirm a PaymentIntent |
| confirmPaymentIntentWithMethod(id, methodId) | Attach method and confirm |
| retrievePaymentIntent(id) | Retrieve a PaymentIntent |
| findLatestPaymentIntentForOrder(orderId) | Search latest PI for order |
| findPaymentIntentByOrderId(orderId) | Search succeeded PI for order |
| cancelPaymentIntent(id) | Cancel a PaymentIntent |
| createCheckoutSession(params) | Create a Checkout Session |
| verifyWebhookSignature(body, sig) | Verify Stripe webhook signature |
| parsePaymentSuccess(paymentIntent) | Parse succeeded PI metadata |
| handleSuccessfulPayment(id) | Retrieve and parse succeeded PI |
| createRefund(id, amount?, reason?, metadata?) | Create full or partial refund |
| retrieveRefund(id) | Retrieve a refund |
| listRefunds(paymentIntentId) | List refunds for a PI |
| listAllRefunds(limit?, startingAfter?) | List all refunds (admin) |
Utilities
validateAndSanitizeMetadata(metadata)— Stripe metadata validationtoSmallestUnit(amount)/fromSmallestUnit(amount)— Currency conversion
License
MIT
