@fanbasis/checkout-core

中文文档
0.6.0发布于 2026/10/09TypeScriptESM + CJS近 30 天下载 1.1万

Core payment checkout functionality for Fanbasis SDK

原始使用文档
文档目录22 节
  1. 🚀 Quick Start
  2. Installation
  3. Basic Usage
  4. 📦 Package Contents
  5. Core Exports
  6. Embed Exports
  7. 🎯 Key Features
  8. 📋 Configuration
  9. Required Parameters
  10. Optional Parameters
  11. 🔧 Integration Methods
  12. 1. Configuration Object
  13. 2. Fluent Builder
  14. 3. Data Attributes (Embed)
  15. 📡 Event Handling
  16. 🌐 Hosted JavaScript
  17. 📚 Documentation
  18. 🧪 Testing
  19. 📦 Build
  20. 🔍 Bundle Analysis
  21. 📄 License
  22. 🆘 Support

@fanbasis/checkout-core

Core payment checkout functionality for the Fanbasis SDK. This package provides the foundational JavaScript library for integrating Fanbasis checkout into any web application.

🚀 Quick Start

Installation

npm install @fanbasis/checkout-core

Basic Usage

import { PaymentCheckout } from '@fanbasis/checkout-core';

const checkout = PaymentCheckout.create({
  creatorId: 'your-creator-id',
  productId: 'your-product-id',
  checkoutSessionSecret: 'your-session-secret',
  environment: 'sandbox'
});

// Attach to DOM element and initialize
const container = document.getElementById('checkout-container');
checkout.attachToElement(container);
await checkout.init();

📦 Package Contents

Core Exports

  • PaymentCheckout - Main checkout class for creating and managing checkout instances
  • EventEmitter - Event system for handling checkout lifecycle events
  • Type definitions - Complete TypeScript support

Embed Exports

  • /embed - Hosted JavaScript solution for CDN integration
  • Global API - window.PaymentCheckout for browser environments
  • Attribute parsing - Automatic configuration from HTML data attributes

🎯 Key Features

  • Framework Agnostic - Works with any JavaScript framework or vanilla JS
  • TypeScript Support - Full type definitions included
  • Event System - Comprehensive event handling for checkout lifecycle
  • Theme Customization - Extensive styling and layout options
  • Multiple Integration Methods - Configuration objects, fluent builder, data attributes
  • Hosted Solution - CDN-ready embed script for quick integration
  • Production Ready - Built-in error handling, validation, and security features

📋 Configuration

Required Parameters

interface CheckoutConfig {
  creatorId: string;              // Your creator identifier
  productId: string;              // The product to sell
  checkoutSessionSecret: string;  // Session secret for security
  environment: 'sandbox' | 'production';
}

Optional Parameters

interface CheckoutConfig {
  // Additional products to offer
  bumpProductIds?: string[];
  
  // Pre-applied coupon and affiliate tracking
  couponCode?: string;
  affiliateCode?: string;
  
  // Custom API endpoint
  overrideBaseUrl?: string;
  
  // Theme customization
  theme?: CustomizationParams;
  
  // Container styling
  containerOptions?: {
    width?: string;
    height?: string;
  };
  
  // Redirect behavior
  redirectSettings?: RedirectSettings;
  
  // Submit button control
  showSubmitButton?: boolean;
}

🔧 Integration Methods

1. Configuration Object

const checkout = PaymentCheckout.create({
  creatorId: 'creator_123',
  productId: 'product_456',
  checkoutSessionSecret: 'secret_789',
  environment: 'sandbox'
});

2. Fluent Builder

const checkout = PaymentCheckout.create()
  .creatorId('creator_123')
  .productId('product_456')
  .checkoutSessionSecret('secret_789')
  .environment('sandbox')
  .theme({
    theme: 'dark',
    accent_color: '#ff6b6b'
  })
  .build();

3. Data Attributes (Embed)

<div data-checkout
     data-creator-id="creator_123"
     data-product-id="product_456"
     data-checkout-session-secret="secret_789"
     data-environment="sandbox">
</div>

📡 Event Handling

checkout.on('checkout:opened', () => {
  console.log('Checkout opened');
});

checkout.on('checkout:success', (data) => {
  console.log('Payment successful:', data.transactionId);
});

checkout.on('checkout:error', (error) => {
  console.error('Payment failed:', error.message);
});

🌐 Hosted JavaScript

For quick integration without a build process, use the hosted JavaScript:

<script src="https://cdn.embedded.fanbasis.io/embed/index.js"></script>
<script>
  PaymentCheckout.create({
    creatorId: 'creator_123',
    productId: 'product_456',
    checkoutSessionSecret: 'secret_789',
    environment: 'sandbox'
  }).attachTo(document.getElementById('checkout-container'));
</script>

📚 Documentation

🧪 Testing

# Run unit tests
npm test

# Run tests in watch mode
npm run test:watch

# Run integration tests
npm run test:e2e

# Run with coverage
npm run test:coverage

📦 Build

# Development build
npm run build

# Production build
npm run build:prod

# CDN build
npm run build:cdn

🔍 Bundle Analysis

# Analyze bundle size
npm run analyze

# Check size limits
npm run size

📄 License

This package is part of the Fanbasis Payment SDK. See the main project for license information.

🆘 Support


Size: ~50KB (gzipped)
Dependencies: eventemitter3
Browser Support: Modern browsers with ES2020+ support

版本与发布记录

@fanbasis/checkout-core 共发布 8 个版本,首次发布于 2025/10/16;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.6.0latest2026/10/091 个月前
0.5.02026/05/146 个月前
0.4.02026/04/296 个月前
0.3.92026/03/267 个月前
0.3.52026/01/169 个月前
0.3.42026/01/169 个月前

关于 @fanbasis/checkout-core 的常见问题

@fanbasis/checkout-core 是什么?

Core payment checkout functionality for Fanbasis SDK

如何安装 @fanbasis/checkout-core?

在项目目录运行 npm install @fanbasis/checkout-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typescript(>=5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fanbasis/checkout-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fanbasis/checkout-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fanbasis/checkout-core 可以商用吗?

@fanbasis/checkout-core 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@fanbasis/checkout-core 的下载量有多少?

根据 npm 官方下载统计,@fanbasis/checkout-core 在 2026/10/14 – 2026/11/12 这 30 天内被下载 10,620 次,日均约 354 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fanbasis/checkout-core 还在维护吗?

最新版本 0.6.0 发布于 2026/10/09(1 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 7 个;首次发布于 2025/10/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。