支付
ShipSaaS 支持多种支付提供商,您可以根据需要选择合适的支付方案。
自定义支付提供商
Section titled “自定义支付提供商”ShipSaaS 支持扩展新的支付提供商:
- 在
src/payment/provider目录中创建新的文件 - 从
types.ts实现PaymentProvider接口 - 在
index.ts中的providerRegistry注册新的提供商
新的支付服务提供商的示例实现:
src/payment/provider/my-provider.ts
import type { PaymentProvider, CreateCheckoutParams, CheckoutResult, CreatePortalParams, PortalResult,} from '../types';
export class MyProvider implements PaymentProvider { getProviderName(): string { return 'my-provider'; }
public async createCheckout(params: CreateCheckoutParams): Promise<CheckoutResult> { // Create checkout session implementation }
public async createCustomerPortal(params: CreatePortalParams): Promise<PortalResult> { // Create customer portal implementation }
public async handleWebhookEvent(payload: string, signature: string): Promise<void> { // Handle webhook events implementation }}然后在 index.ts 中的 providerRegistry 注册新的提供商:
src/payment/index.ts
import { MyProvider } from './provider/my-provider';
const providerRegistry: Record<PaymentProviderName, ProviderFactory> = { stripe: () => new StripeProvider(), creem: () => new CreemProvider(), 'my-provider': () => new MyProvider(),};