@devizovaburza/payments-api-sdk
v1.1.0
Published
Type-safe SDK for integrating with the Payments API. Provides a pre-configured [Hono RPC client](https://hono.dev/docs/guides/rpc) and cryptographic helpers for request signing.
Downloads
54
Readme
Payments API SDK
Type-safe SDK for integrating with the Payments API. Provides a pre-configured Hono RPC client and cryptographic helpers for request signing.
Installation
npm install @devizovaburza/payments-api-sdk
# or
yarn add @devizovaburza/payments-api-sdkUsage
API Client
The SDK exports a type-safe client generated from the Payments API schema:
import { createPartnerApiClient } from '@devizovaburza/payments-api-sdk/v1';
const client = createPartnerApiClient('https://api.payments.devizovka.cz');
// Authenticate
const { accessToken } = await client.v1.auth.token.$post({
json: { email: '...', password: '...' },
}).then(res => res.json());
// Send a payment
const payment = await client.v1.organizations[':id'].payments.$post({
param: { id: orgId },
json: { ... },
header: { 'x-idempotency-key': '...' },
}).then(res => res.json());Type Inference
You can infer request and response types from any endpoint using Hono's built-in helpers:
import type { InferRequestType, InferResponseType } from 'hono/client';
import { createPartnerApiClient } from '@devizovaburza/payments-api-sdk/v1';
const client = createPartnerApiClient('https://api.payments.devizovka.cz');
// Infer types from a specific endpoint
type SendPaymentRequest = InferRequestType<typeof client.v1.organizations[':id'].payments.$post>;
type SendPaymentResponse = InferResponseType<typeof client.v1.organizations[':id'].payments.$post>;
// Use in your code
async function sendPayment(orgId: string, body: SendPaymentRequest['json']) {
const res = await client.v1.organizations[':id'].payments.$post({
param: { id: orgId },
json: body,
header: { 'x-idempotency-key': crypto.randomUUID() },
});
const data: SendPaymentResponse = await res.json();
return data;
}Sign Payload
Signs a JSON payload using a base64-encoded RSA private key. Use this to generate the X-Signature header.
import { signPayload } from '@devizovaburza/payments-api-sdk/v1';
const signature = await signPayload({
payload: JSON.stringify({ amount: 1000 }),
privateKey: 'BASE64_ENCODED_PRIVATE_KEY',
});Verify Payload Signature
Verifies a signature using a base64-encoded RSA public key.
import { verifyPayloadSignature } from '@devizovaburza/payments-api-sdk/v1';
const isValid = await verifyPayloadSignature({
payload: JSON.stringify({ amount: 1000 }),
signature: 'GENERATED_SIGNATURE',
publicKey: 'BASE64_ENCODED_PUBLIC_KEY',
});