@faiber/faiber-payment

中文文档
2.8.0发布于 2026/11/14TypeScriptES Module近 30 天下载 3802

Gateway administration, payment creation, transaction lookup, daily income, browser callbacks, and payment status pages.

原始使用文档
文档目录10 节
  1. Install
  2. Configure
  3. Complete capability
  4. Authentication and authorization
  5. Inputs, queries, responses, and transport
  6. Errors and cancellation
  7. Verified checkout and readiness
  8. Gateway and transaction administration
  9. Configured reward-pack checkouts
  10. Funded reward refunds

@faiber/faiber-payment

Gateway administration, payment creation, transaction lookup, daily income, browser callbacks, and payment status pages.

Install

npm install @faiber/faiber-payment

Configure

import { FaiberClient, MemoryTokenProvider } from "@faiber/sdk-core";
import { PaymentApi } from "@faiber/faiber-payment";

const tokens = new MemoryTokenProvider();
const client = new FaiberClient("payment", {
  domains: { payment: process.env.FAIBER_PAYMENT_URL! },
  tokenProvider: tokens,
  axios: { timeout: 15_000, withCredentials: true },
});
const api = new PaymentApi(client);

const gateways = await api.gateways.list();
const payment = await api.createPayment({
  amount: 4900,
  service_name: "my-service",
  service_model: "order",
  service_id: "order-42",
  queue_name: "my_service_queue",
  callback_url: "https://merchant.example/payment-result",
  idempotency_key: "my-service:order-42",
});

Complete capability

This package exposes 36 registered operations from the payments service. Common workflows have concise methods on api; every registered backend route is also available as a named function on api.operations. Generated operation input, query, response, path, verb, and permission contracts are exported from operations.types.

AreaOperationsHTTP methods
asset-checkout1GET
fitness3GET, POST
gateway7DELETE, GET, PATCH, POST
integration2GET
payment1POST
payment-web3GET, POST
product-plans3GET, POST
router5GET
session1GET
settings2GET, PATCH
shop-checkout3GET, POST
transaction5GET, POST

Browser callback and verification routes are exposed in api.operations; callers should preserve the provider query parameters returned by the payment service.

Authentication and authorization

Use a TokenProvider to forward the signed-in user's Bearer token, or enable withCredentials for secure HttpOnly cookie sessions. Permission requirements copied from service route guards are included in each operation's JSDoc. The SDK does not embed API keys, credentials, localhost URLs, sandbox hosts, or production hosts.

Inputs, queries, responses, and transport

All methods return the complete Axios response, including status, headers, and request IDs. Request bodies and query objects are named exported interfaces. Nested pagination uses keys such as page[number] and page[size] where required by the service. Standard Axios request options, headers, timeouts, adapters, interceptors, and AbortSignal cancellation are supported as the final argument.

Generic REST resources are capability-guarded. Calling a legacy method that the service does not register throws UnsupportedOperationError before sending a request instead of producing a backend 405.

Errors and cancellation

try {
  await api.client.get("/health", undefined, { signal: AbortSignal.timeout(5_000) });
} catch (error) {
  // Axios errors retain response.status and the service error body.
}

Use @faiber/faiber-ts-sdk when one application needs multiple Faiber services with one configuration.

Verified checkout and readiness

operations.gatewaySetupCheckPost() performs a read-only live-provider check with admin:gateway:read. Product-specific payment operations cover 2done, fitness and storefront checkout. Internal endpoints require their product's trusted server credential; an end-user token alone does not grant access.

operations.assetCheckoutReceiptGet(purchaseId, options) accepts x-asset-payment-token through options.headers and returns a raw verified receipt with purchaseId, transaction, integer IRR amount, providerVerified and status (pending, accepted, or rejected). Other product receipt operations retain their service envelopes. Payment creation uses stable product-specific idempotency keys; retry fitness checkout through fitnessRetryPost rather than creating an unrelated transaction.

Gateway and transaction administration

Gateway identifiers are integers. gateways.list({ status: "active", "page[number]": 1, "page[size]": 20 }) returns data.data and data.meta. Gateway create/update supports sandbox; nullable response fields are always present. The options response is opaque stored provider configuration and may contain encrypted values: do not populate editable credential fields from it or log it. Delete returns the removed gateway record, not a boolean result. Gateway calls require the corresponding admin:gateway:read, create, update, or delete permission.

transactions.list() returns a nested data.transactions page, filtered aggregate summaries, service names and gateway options. Transaction records use uuid; they declare no currency field. transactions.show(uuid) and transactionStatus(uuid) return status only. Administration requires admin:transaction:read, and verify/reject requires admin:transaction:verify plus an authenticated verifier. Verification may contact a payment provider; inspect its successful result rather than equating HTTP200 with a successful payment.

gatewayOptions() returns { providers, statuses } label/value arrays. dailyIncomeFor({ days: 7 }) returns UTC date/amount points, including zero dates; the backend clamps the day window to1–90. No count field is returned. createPayment() accepts an optional idempotency_key; trusted product, fitness, Asset and storefront purchases must use their dedicated server-authorized checkout contracts. Generic creation is not an authorization bypass for those purchases.

Payment navigation operations return text/HTML, not JSON envelopes. Provider callbacks accept Authority, transid or paymentNumber in the query for both GET and POST. A callback may return303 with a Location header for a configured allowed HTTPS origin; otherwise it returns the payment result page. In Node, pass maxRedirects: 0 and a validateStatus that accepts303 to inspect that response. A result page with HTTP200 can describe a failed payment. These routes may contact the real provider and are not read-only health checks.

Configured reward-pack checkouts

rewardCheckouts.create(product, body, options) and rewardCheckouts.receipt(product, transactionId, options) require that product's configured backend Bearer credential. The server validates model, order, idempotency key and HTTPS callback origin. These endpoints create/read verified Payment transactions; Asset alone credits a wallet after independently matching the receipt. Pending or cancelled payments never issue coins. Product settings belong in service configuration, and these credentials must stay off clients.

Funded reward refunds

PaymentApi.rewardRefunds exposes list, show, start, confirm, and reopen. These operator calls require IDP authentication and the applicable transaction permission. Writes additionally require assignment to the configured product. The payer cannot verify its own refund. Preserve operation_id and version when retrying an unchanged request; changed semantics or stale rounds return HTTP 409. The methods preserve Axios responses and accept RequestOptions, including an abort signal.

Bank execution takes place in the original merchant portal. Two distinct assigned operators then verify the full refund to the original payer. Reopening a review round never executes another bank refund. rewardCheckout.refund is a trusted backend integration and requires an existing Asset escrow; never expose its service credential in browser code. Readiness reports configuration only.

版本与发布记录

@faiber/faiber-payment 共发布 66 个版本,首次发布于 2026/07/18;过去 12 个月发布了 66 个版本。

版本发布日期距今
2.8.0latest2026/11/14今天
2.7.02026/11/059 天前
2.6.02026/11/049 天前
2.5.02026/11/049 天前
2.4.02026/11/0310 天前
2.3.02026/11/0211 天前

关于 @faiber/faiber-payment 的常见问题

@faiber/faiber-payment 是什么?

Gateway administration, payment creation, transaction lookup, daily income, browser callbacks, and payment status pages.

如何安装 @faiber/faiber-payment?

在项目目录运行 npm install @faiber/faiber-payment,或使用 pnpm add / yarn add / bun add。

@faiber/faiber-payment 支持 TypeScript 吗?

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

@faiber/faiber-payment 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@faiber/faiber-payment 可以商用吗?

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

@faiber/faiber-payment 的下载量有多少?

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

@faiber/faiber-payment 还在维护吗?

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