Browser helpers (@payinference/sdk-js)
@payinference/sdk-js is a small, deliberately limited package for the checkout page. It contains no authentication and no PayInference API access, because the browser must never talk to PayInference directly.
browser ──(your endpoint, your auth)──▶ your backend ──@payinference/sdk-node──▶ PayInference
What it gives the frontend: shared types for the decision your backend chooses to forward, a typed fetch helper for your endpoint, and a card-data guard.
Types#
import type { ClientDecision, DecisionAction, Provider } from '@payinference/sdk-js';
// ClientDecision is the safe subset a backend may forward to the browser:
// { decision_id, action, route, reason_codes, ttl_ms }
Calling your backend#
import { BackendDecisionClient } from '@payinference/sdk-js';
const client = new BackendDecisionClient({
endpoint: '/api/checkout', // YOUR endpoint, YOUR auth
headers: { 'x-csrf-token': token }, // whatever your app uses
});
const decision = await client.getDecision({ order_id: 'order_456', amount: 14900 });
The payload goes to your backend, which calls PayInference server-side and returns whatever subset of the decision you deem safe.
Helpers#
import { shouldProceed, requiresStepUp, isHeld, isExpired } from '@payinference/sdk-js';
if (isHeld(decision)) {
showPendingReview(); // hold: paused until review/approval completes
} else if (requiresStepUp(decision)) {
startThreeDS();
} else if (shouldProceed(decision)) {
openPspSession(decision.route!.primary_provider);
} else {
showPaymentUnavailable(); // block, or no route
}
// Decisions go stale; re-request instead of acting on an old one.
if (isExpired(decision, decidedAtMs)) {
refreshDecision();
}
Card-data guard#
BackendDecisionClient.getDecision() refuses to send payloads containing card-data-shaped keys (card_number, pan, cvv, cvc, expiry, and variants), throwing before any request is made. Card details belong in your PSP's fields only. The guard is also exported directly:
import { assertNoCardData } from '@payinference/sdk-js';
assertNoCardData(payload); // throws if the payload looks like card data
What this package will not do#
- Hold or transmit an API key
- Call the PayInference API
- Collect or forward card data
If you find yourself wanting any of those in the browser, the integration is shaped wrong; move the logic to your backend and see Backend checkout integration.