Skip to main content
Use new-api’s built-in Epay integration to collect balance top-ups with KyrenPay. This guide applies to QuantumNous/new-api at commit 56758ed, verified on October 1, 2026, using go-epay v0.0.4. Older releases and forks may use different menus or amount calculations.

Before you start

  • Prepare a KyrenPay merchant account with the required payment provider bound and credentials active. Enable only methods available to that account.
  • Obtain the merchant account ID and the complete, current API key beginning with kyren_live_. The raw API key, including its prefix, is the Epay merchant secret; a masked key or Webhook secret will not work.
  • Deploy new-api behind a public HTTPS domain, for example https://ai.example.com, with its API callback routed to the backend.
See Developer settings and Epay compatibility.

Configure Epay

  1. Open System Settings > Billing & Payments > Payment Gateway (/system-settings/billing/payment).
  2. For the initial setup, the root administrator must read and complete the page’s Compliance Confirmation. Payment settings and online top-ups remain locked until confirmation is complete. Skip this step if the page already shows Compliance Confirmed.
  3. Under Epay, enter the payment endpoint, merchant ID, merchant secret key and callback base address (CustomCallbackAddress). Enter only the public site origin for the callback address, without the notification path.
  4. Under General, configure the price, minimum top-up, payment methods, preset recharge amounts and discounts, then click Save All Settings.
new-api Epay settings: payment endpoint, callback address, merchant ID and secret key The screenshot shows an example interface in Simplified Chinese. Use the endpoint and credentials from the table below for your integration. If the custom callback address is empty, new-api uses ServerAddress. It appends /api/user/epay/notify; enter the origin rather than the full callback path. The SDK appends submit.php to the payment address while retaining /epay, resulting in https://api.kyrenpay.com/epay/submit.php. Settings UI, callback origin, SDK URL construction.

Configure payment methods

The General settings offer a visual editor and JSON editor for PayMethods. The type is sent to Epay. Start with the methods enabled for your merchant, for example:
This verified version accepts custom Epay method types. You can add entries with type equal to creditcard, crypto or paynow, and a suitable display name, when those methods are enabled for your KyrenPay account. Do not use another gateway’s aliases. The documented KyrenPay codes here are alipay, wxpay, creditcard, crypto and paynow. Payment-method settings, method passed to Epay.

Set the amount and credited balance

The built-in client does not send money_type, so KyrenPay charges CNY. A USD or CNY display preference does not change that request currency. For USD display with a requested balance amount A, the Epay base amount in CNY is A × Price × user-group recharge ratio × preset discount, formatted to two decimals. The credited internal quota is A × QuotaPerUnit. For an initial check, use USD display, group ratio 1 and discount 1. If you deliberately configure Price = 7.00, requesting USD 10.00 balance sends an Epay base amount of CNY 70.00 and credits USD 10.00 balance. 7.00 is an example configuration, not a current exchange-rate quote. The Epay base amount is not always the final checkout total. KyrenPay may add a customer-paid fee according to your payment channel’s fee-sharing settings. The example total is exactly CNY 70.00 only when no KyrenPay customer-paid fee applies. Epay notification and order-query money report the base amount; new-api credits the quota from its stored recharge amount, rather than any additional fee. Compare the base amount, displayed checkout total and expected credited balance separately. In TOKENS display mode, the request is converted through QuotaPerUnit; check the installed version’s rounding and recharge presets before using that mode. Confirm the charge and credited balance in a small payment before enabling public top-ups. Amount calculation and request, credit calculation.

Verify payment and crediting

  1. Sign in as a test user, record the starting balance and create a small recharge. Record out_trade_no, the Epay base amount and the displayed CNY checkout total.
  2. Complete payment and confirm the corresponding KyrenPay order is paid. Confirm the new-api recharge record is successful and the intended balance increase is present.
  3. Check that the public backend receives KyrenPay’s signed GET notification at https://ai.example.com/api/user/epay/notify. The built-in handler verifies Epay MD5, handles TRADE_SUCCESS, credits the stored recharge order and returns the plain text success.
  4. Confirm a repeated notification for that order does not add quota again. The verified implementation uses a database transaction and order-state check to prevent duplicate crediting. Do not credit from the browser return URL or treat a return-page visit as payment proof.
Callback implementation, transactional crediting. See Epay MD5 signatures and Paid but not credited.

Common configuration problems

Acceptance limits in the documented version

Local tests against the pinned commit’s actual controller, Epay SDK and SQLite transaction logic confirmed ordinary crediting and duplicate protection. They also found that EpayNotify does not compare signed callback money with the stored TopUp.Money: a stored CNY 70.00 purchase accepted a correctly signed CNY 0.01 callback and credited its full stored entitlement. Changing an unsigned amount still fails signature verification; this finding concerns a signed amount mismatch. Before production readiness, require that mismatch to be rejected by a verified application version or an explicitly reviewed application change. Do not mark this acceptance check passed for the documented commit. In TOKENS display, requesting 5,250,000 quota units with QuotaPerUnit = 500,000 and Price = 7.00 sent CNY 73.50 but persisted integer Amount = 10 and credited 5,000,000 quota units. Start with the documented USD/integer-balance configuration and verify fractional TOKENS conversion before enabling it. These are isolated source-level tests, not a payment on your deployment.
  • Wrong payment URL: preserve /epay/ in PayAddress; the SDK adds submit.php itself.
  • Wrong charge: check Price, group recharge ratio, preset discounts, quota display mode and KyrenPay customer-paid fees together. Display currency does not select KyrenPay’s charge currency.
  • Paid but not credited: check callback origin, public HTTPS access, GET query forwarding and backend logs. The callback must not redirect to login or require a browser challenge.
  • IP allowlist: this built-in purchase flow uses browser submit.php. Do not add customer IPs to the server API allowlist; server-side mapi.php calls require the calling server’s outbound IP when the allowlist is enabled.
  • Key rotation: regenerating the KyrenPay API key invalidates the old Epay secret. Update EpayKey immediately, then check a new payment and pending callbacks. Keep secrets out of logs and support tickets.
These instructions were checked against source code; they do not represent a live payment test on your deployment.