npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@one-payments/core

v1.2.0

Published

Headless payment SDK core - framework-agnostic business logic

Readme

@one-payments/core

Core SDK types, interfaces, and business logic for One Payments. This package provides the foundation for all platform-specific implementations.

Features

  • 🔒 Secure payment configuration with validation
  • 📝 Complete TypeScript definitions
  • 🌐 Platform-agnostic interfaces
  • 🔐 Built-in HMAC signature generation
  • 🎯 Type-safe event payloads
  • ⚙️ Environment configuration (dev, staging, prod)

Installation

npm install @one-payments/core
# or
yarn add @one-payments/core
# or
pnpm add @one-payments/core

Usage

PaymentConfig Class

The PaymentConfig class provides validation and type safety for your SDK configuration:

import { PaymentConfig } from '@one-payments/core';

// Recommended: Use PaymentConfig for automatic validation
const config = new PaymentConfig({
  apiKey: 'pk_...',
  secretKey: 'sk_...',
  environment: 'prod'
});

// Access validated config
console.log(config.apiKey);        // string
console.log(config.secretKey);     // string
console.log(config.environment);   // 'dev' | 'staging' | 'prod'

Plain Config Object

You can also use a plain object if you prefer:

import type { SDKConfig } from '@one-payments/core';

const config: SDKConfig = {
  apiKey: 'pk_...',
  secretKey: 'sk_...',
  environment: 'prod'
};

Development Environment

For local development and testing, use the 'dev' environment:

const config = new PaymentConfig({
  apiKey: 'your-dev-api-key',
  secretKey: 'your-dev-secret-key',
  environment: 'dev'
});

Note for TypeScript users: The TypeScript types currently show only 'prod' and 'staging', but the runtime fully supports 'dev'. Use type assertion if needed:

environment: 'dev' as any

Types

Core Interfaces

interface SDKConfig {
  apiKey: string;
  secretKey: string;
  environment: 'dev' | 'staging' | 'prod';
}

interface PaymentSucceededPayload {
  paymentIntent: {
    id: string;
    amount: number;
    currency: string;
    status: 'succeeded';
  };
  metadata?: Record<string, unknown>;
}

interface PaymentFailedPayload {
  error: {
    code: string;
    message: string;
    details?: Record<string, unknown>;
  };
}

interface StateChangedPayload {
  status: 'idle' | 'initializing' | 'ready' | 'processing' | 'requires_action' | 'succeeded' | 'failed';
  [key: string]: unknown;
}

Adapters Interface

Platform adapters provide implementations for HTTP, Storage, Crypto, and Timer operations:

interface Adapters {
  http: HttpAdapter;
  storage: StorageAdapter;
  crypto: CryptoAdapter;
  timer: TimerAdapter;
}

interface HttpAdapter {
  fetch(url: string, options?: RequestInit): Promise<Response>;
}

interface StorageAdapter {
  getItem(key: string): Promise<string | null>;
  setItem(key: string, value: string): Promise<void>;
  removeItem(key: string): Promise<void>;
}

interface CryptoAdapter {
  generateHMAC(message: string, secret: string): Promise<string>;
  randomUUID(): string;
}

interface TimerAdapter {
  setTimeout(callback: () => void, delay: number): number;
  clearTimeout(id: number): void;
}

Payment Method Types

type PaymentMethodId =
  | 'card'
  | 'paynow'
  | 'apple_pay'
  | 'google_pay';

interface PaymentMethodConfig {
  id: PaymentMethodId;
  enabled: boolean;
  displayName?: string;
}

Environment URLs

The SDK automatically selects the correct API endpoint based on the environment:

const ENVIRONMENT_URLS = {
  dev: 'https://public.dev.one.ooo',
  staging: 'https://public.staging.one.ooo',
  prod: 'https://public.one.ooo'
};

Framework Integration

This core package is used by all framework-specific wrappers:

Web Frameworks

Mobile

Platform Adapters

Server-Side Rendering (SSR)

This package is safe to import in SSR environments (Next.js, Nuxt, etc.) as it only contains types and pure functions. However, platform adapters should be initialized client-side only.

Next.js Example

'use client';

import { useState, useEffect } from 'react';
import { PaymentConfig } from '@one-payments/core';
import type { SDKConfig } from '@one-payments/core';

export default function CheckoutPage() {
  const [config, setConfig] = useState<SDKConfig | null>(null);

  useEffect(() => {
    // Initialize config on client-side
    setConfig(new PaymentConfig({
      apiKey: process.env.NEXT_PUBLIC_ONE_PAYMENTS_API_KEY!,
      secretKey: process.env.NEXT_PUBLIC_ONE_PAYMENTS_SECRET_KEY!,
      environment: 'prod'
    }));
  }, []);

  // ...
}

See the Next.js Integration Guide for complete instructions.

Validation

The PaymentConfig class validates:

  • ✅ Required fields (apiKey, secretKey, environment)
  • ✅ Environment value is valid
  • ✅ API keys are non-empty strings
  • ⚠️ Warnings for common mistakes (mixing environments, test keys in production)
// Throws error if invalid
const config = new PaymentConfig({
  apiKey: '',  // Error: apiKey is required
  secretKey: 'sk_...',
  environment: 'invalid'  // Error: environment must be dev/staging/prod
});

Security Best Practices

Environment Variables

Store API keys in environment variables, never commit them to version control:

React / CRA:

# .env
REACT_APP_ONE_PAYMENTS_API_KEY=pk_...
REACT_APP_ONE_PAYMENTS_SECRET_KEY=sk_...

Next.js:

# .env.local
NEXT_PUBLIC_ONE_PAYMENTS_API_KEY=pk_...
NEXT_PUBLIC_ONE_PAYMENTS_SECRET_KEY=sk_...

Vite:

# .env
VITE_ONE_PAYMENTS_API_KEY=pk_...
VITE_ONE_PAYMENTS_SECRET_KEY=sk_...

.gitignore

Ensure your .gitignore includes:

.env
.env.local
.env.*.local

TypeScript Configuration

Add these compiler options for optimal type checking:

{
  "compilerOptions": {
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "moduleResolution": "node"
  }
}

Related Packages

Requirements

  • TypeScript >= 5.0.0 (for TypeScript projects)
  • No runtime dependencies

License

MIT