@coherentx/coherent

中文文档
0.0.61发布于 2026/07/20UNLICENSEDTypeScriptCommonJS近 30 天下载 1.2万

Coherent Payments Gateway Client Library

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Payments
  4. Recurring Payments and Holds (aka Payment Plans)
  5. Partner Merchant Management

Coherent API

Installation

Install the API using the following command

npm install coherent

Add --save if building a deployable.

Usage

Import and initialise the connection

import {Coherent} from "coherent";

const coherent = new Coherent({
    environment: "TEST", // or "PRODUCTION"
    token: process.env.COHERENT_TOKEN
})

Payments

Create a Transaction (aka Payment)

Create a payment link, notifying an email or phone number optionally

const transaction = await coherent.transactions.create({
    amount: 1000, // The amount in the smallest regular unit, e.g. pennies (£10 = 1000)
    name: `John Smith`, // The name of the patient,
    note: "A test", //optional, what this transaction involves
    email: "[email protected]", //optional
    emailNotify: true, //optional, `email` receives payment request notification
    patientNote: "Thanks for your payment", //optional, a note visible to the patient during payment
    phone: "+44...", //optional
    smsNotify: true, //optional, `phone` receives SMS payment request notification
    successUrl: "https://example.com/success", //optional, where to redirect to after successful payment
    failureUrl: "https://example.com/failure", //optional, where to redirect to after rejected payment
})

console.log(transaction.uuid)
console.log(transaction.status)
console.log(transaction.paymentUrl)

Get a payment

const transaction = await coherent.transactions.get(
    transaction.uuid
)

Void a payment

await coherent.transactions.updateStatus(
    transaction.uuid,
    'void'
)

#### Refunds

```js
await coherent.transactions.refund({
    transactionUuid: transaction.uuid,
    amount: 100,
    reason: 'Anything'
})

Terminals

List terminals

await coherent.terminals.list()

Name the terminal

await coherent.terminals.rename({
    terminalId: '<TYPE>-123455678',
    name: 'The Trusty Terminal'
})

Send for payment

await coherent.terminals.setTransaction({
    terminalId: '<TYPE>-123455678',
    transactionUuid: 'abcd-1234'
})

Clear the terminal

await coherent.terminals.clearTransaction({
    terminalId: '<TYPE>-123455678'
})

Transaction Status Webhooks

See Transaction Status Webhooks in the main documentation

Recurring Payments and Holds (aka Payment Plans)

Create a Payment Plan, currently limited to monthly recurring payments, or payment holds for charging on demand

const plan = await coherent.paymentPlans.create({
    amount: 1000, // The amount in the smallest regular unit, e.g. pennies (£10 = 1000)
    name: `John Smith`, // The name of the patient,
    note: "A test", //optional, what this transaction involves
    startDate: new Date("2025-01-01"), //required except if creating an on_demand plan
    endDate: new Date("2025-03-01"), //optional, the date of the last payment occurrence
    transactionReference: "Invoice123456", //optional, but recommended, and unique per clinic. Transactions relating to this payment plan will have this set
    email: "[email protected]", //optional
    emailNotify: true, //optional, defaults to true if email is provided
    phone: "+44...", //optional
    smsNotify: true, //optional, defaults to true if phone is provided
    type: "recurring", //optional, defaults to recurring, can be on_demand
    method: "direct_debit", //optional, defaults to direct_debit, can be card
    successUrl: "https://app.coherenthealthcare.com/receipt?token=example", //optional, where the user is sent after successful payment. NOTE: only supported for type = card
})

console.log(plan.uuid)
console.log(plan.status)
console.log(plan.paymentUrl)

Get a payment plan

const plan = await coherent.paymentPlans.get(
    plan.uuid
)

Pause or cancel a payment plan

await coherent.paymentPlans.setStatus(
    plan.uuid,
    PaymentPlanStatus.Void 
    // OR PaymentPlanStatus.Paused
    // OR PaymentPlanStatus.Resumed
)

You can set the second parameter to one of:

  • Void: Cancels the payment plan and associated schedule
  • Paused: Pauses the payment plan's schedule, scheduled occurences that fall when the plan is paused are skipped forever
  • Resumed: Resumes the payment plan's schedule, restoring it to the state it was in before it became paused or errored.

Resend a notification

await coherent.paymentPlans.notify(
    plan.uuid
)

Charge an on-demand payment plan

await coherent.paymentPlans.charge(
    plan.uuid,
    { amount: 2000, reference: "INVOICE-1234" } // optional
)

Recover a Direct Debit plan that failed collection for insufficient funds (PaymentPlanStatus.InsufficientFunds) — resumes the plan and immediately charges the current instalment in one call:

const { transactionUuid } = await coherent.paymentPlans.resumeAndCharge(
    plan.uuid
)

Each recurrence of a payment plan will create a Transaction, and in turn trigger a Transaction webhook as usual.

To link transactions generated to payment plans, set the transactionReference on payment plan creation.

You will not have a record of the transaction with the given UUID when the webhook is received, but when you get the transaction, it should contain the reference set earlier at {}.paymentPlan.transactionReference.

Partner Merchant Management

Partners can manage their merchants, including listing merchants, managing API keys, and configuring webhook URLs.

Note: An API key and webhook URL are created automatically during onboarding (startOnboarding). The endpoints below are only needed if you want to rotate keys or change the webhook URL after onboarding.

List all merchants belonging to this partner

const merchants = await coherent.merchants.listMerchants()
// Returns: [{ uuid, name, email, phone?, onboarded }]

API Key Management

Create a new API key for a merchant

const result = await coherent.merchants.createApiKey('merchant-uuid')
console.log(result.apiKey) // Store this securely — it cannot be retrieved again

List existing API keys for a merchant

const keys = await coherent.merchants.listApiKeys('merchant-uuid')
// Returns: [{ uuid, createdTime }]

Webhook URL Management

Get the current webhook URL for a merchant

const webhook = await coherent.merchants.getWebhookUrl('merchant-uuid')
console.log(webhook.webhookUrl) // null if not set

Update a merchant's webhook URL

await coherent.merchants.updateWebhookUrl('merchant-uuid', 'https://example.com/webhook')

版本与发布记录

@coherentx/coherent 共发布 61 个版本,首次发布于 2024/06/17;过去 12 个月发布了 8 个版本。

版本发布日期距今
0.0.61latest2026/07/203 个月前
0.0.602026/07/173 个月前
0.0.592026/07/034 个月前
0.0.582026/07/034 个月前
0.0.572026/03/108 个月前
0.0.562025/12/1011 个月前

关于 @coherentx/coherent 的常见问题

@coherentx/coherent 是什么?

Coherent Payments Gateway Client Library

如何安装 @coherentx/coherent?

在项目目录运行 npm install @coherentx/coherent,或使用 pnpm add / yarn add / bun add。

@coherentx/coherent 支持 TypeScript 吗?

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

@coherentx/coherent 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@coherentx/coherent 可以商用吗?

@coherentx/coherent 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@coherentx/coherent 的下载量有多少?

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

@coherentx/coherent 还在维护吗?

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