The foundation for all Reevit payment SDKs. It provides the shared API client, state machine logic, type definitions, and utility functions used by the React, Vue, and Svelte SDKs.
npm install @reevit/core
If you're building a custom integration or another framework SDK, you can use the core components directly.
import { ReevitAPIClient } from '@reevit/core';
const client = new ReevitAPIClient({
publicKey: 'pfk_test_xxx',
});
// Create a payment intent
const { data, error } = await client.createPaymentIntent({
amount: 5000,
currency: 'GHS',
email: '[email protected]',
idempotencyKey: 'order_12345',
}, 'card');
if (data) {
console.log('Intent created:', data.id);
}
Browser SDKs should prefer server-created checkout sessions. Use the session secret returned by your backend to load the payment intent without exposing private API credentials.
const { data, error } = await client.getCheckoutSession('cs_session_secret');
if (data) {
console.log('Ready to render:', data.payment_intent.id);
}
Core returns a consistent { data, error } result. Errors include code, message, recoverable, and details.httpStatus when the API returns a status code.
const result = await client.getCheckoutSession('cs_session_secret');
if (result.error) {
if (result.error.recoverable) {
// show retry UI
}
console.error(result.error.code, result.error.message);
}
import { formatAmount, validatePhone, detectNetwork } from '@reevit/core';
console.log(formatAmount(10000, 'GHS')); // "GH₵ 100.00"
console.log(validatePhone('0241234567')); // true
console.log(detectNetwork('0241234567')); // "mtn"
Core exports helpers to stabilize intent creation and dedupe in-flight requests.
import { resolveIntentIdentity } from '@reevit/core';
const { idempotencyKey, reference } = resolveIntentIdentity({
config: {
amount: 5000,
currency: 'GHS',
email: '[email protected]',
idempotencyKey: 'order_12345',
},
method: 'card',
});
MIT © Reevit