@synkolat/paymints
v0.0.2
Published
Minimal, ESM-only, tree-shakeable utilities for frontends.
Maintainers
Readme
@synkolat/paymints
Minimal, ESM-only, tree-shakeable utilities for integrating Paymints into browser frontends.
Installation
npm install @synkolat/paymints
# or
pnpm add @synkolat/paymints
# or
yarn add @synkolat/paymintsUsage
1. Initialize
Initialize the library with your public API key before using any other functionality. This is typically done at the root of your application (e.g., in App.tsx or main.ts).
import { config } from '@synkolat/paymints';
config.init({
key: 'pmts.your_public_key'
});2. Launch Checkout
Redirect the user to a hosted checkout page to subscribe to a plan. This function creates a checkout session and automatically handles the browser redirect.
import { subscription } from '@synkolat/paymints';
async function handleSubscribe() {
try {
await subscription.launchCheckout({
// The unique ID of the user in your system
customerReference: 'user_123456'
});
} catch (error) {
console.error('Failed to launch checkout:', error);
}
}3. Check Subscription Status
Check if a specific customer has an active subscription.
import { subscription } from '@synkolat/paymints';
async function checkUserSubscription() {
try {
const result = await subscription.checkStatus({
customerReference: 'user_123456'
});
if (result.hasActiveSubscription) {
console.log('User is subscribed to:', result.subscription?.productName);
console.log('Status:', result.subscription?.status);
} else {
console.log('No active subscription found.');
}
} catch (error) {
console.error('Failed to check status:', error);
}
}API Reference
config
init(config: PaymintsConfig): void
Initializes the Paymints SDK.
- key (required): Your Paymints public API key. Must start with
pmts.. - baseUrl (optional): Override the default API URL.
subscription
launchCheckout(params: CreateCheckoutParams): Promise<void>
Creates a checkout session and automatically redirects the browser to the payment page.
- customerReference (required): A unique identifier for the customer in your system.
checkStatus(params: CheckSubscriptionParams): Promise<SubscriptionCheckResponse>
Checks the subscription status for a customer.
- customerReference (required): The unique identifier for the customer.
Types
The package exports the following TypeScript interfaces for better type safety:
PaymintsConfigCreateCheckoutParamsCheckSubscriptionParamsCheckoutResponseSubscriptionCheckResponse
License
MIT
