# Create a Subscription Bot Payment Request

> Create a Telegram or Discord subscription bot checkout or an eligible manual trial, and handle completed receipts, payment links and retry errors.

Source: https://docs.botsubscription.com/api/payment-requests/create/

Create a plan checkout for a <strong>Telegram subscription bot</strong> or <strong>Discord subscription bot</strong>. An eligible trial can complete immediately without a payment link. Check the returned status before deciding what the customer should do next.

Keep the project API key on your server. Do not expose it in browser code.

<ApiEndpoint method="POST" endpoint="/v2/projects/{project_id}/payment-requests" />

<ApiAuthorization type="Bearer API Key" />

**API key scopes:** `payment-requests:add` and `payment-history:read` (required for restricted keys). Applying a coupon also requires `coupons:read`.

Response dates use the [UTC ISO format](https://docs.botsubscription.com/api/overview/#utc-iso-response-dates), including the manual-trial marker described below.

Supply the customer's `user_id` explicitly. Project API keys cannot debit the customer's wallet or charge a stored card or subscription instrument. Sending `payment_method_id` returns `403`.

**Retries:** `Idempotency-Key` binds the request to your intent, while this endpoint owns duplicate-submit recovery. Successful rich responses are normally recoverable for ten minutes; the shared 24-hour response replay does not apply.

## Handle the returned status

```text
Your website backend creates a Payment Request for user_id
  -> completed: show the receipt; no redirect is needed
  -> pending with a positive amount and payment_url: open hosted checkout
  -> another status: handle that state or the provider's payment instructions
```

An HTTP success does not necessarily mean a charge occurred. A completed, zero-price trial receipt can have `status: "completed"`, `amount: "0"` and no `payment_url`.

Create, resume and cancel responses use a payment-operation payload. It includes `payment_request_id`, `request_type`, `amount`, `currency`, `status`, `provider` and a required nullable `merchant_account_id`. `provider_payment_id`, `failure_reason` and `payment_error_code` may be omitted or null. `payment_url` may be omitted or null; terminal responses omit live checkout URLs. `payment_request_data` contains provider or receipt metadata.

These operation responses omit `user_id`, `created_at` and `settled_at`. Use [Get Payment Request](https://docs.botsubscription.com/api/payment-requests/get/) for the stored receipt's customer, plan and timestamps. Optional boolean `reused` identifies a reused checkout; optional boolean `superseded` identifies whether this checkout replaced an earlier one.

For hosted checkout, a browser redirect is a navigation step, not proof of payment. Treat a verified [`payment-request.completed` webhook](https://docs.botsubscription.com/webhooks/events/payments/payment-request-completed/) or the status returned by [Get Payment Request](https://docs.botsubscription.com/api/payment-requests/get/) as authoritative.

## Automatic trials for named members

The backend decides trial eligibility from the configured plan and the customer's history. There is no request switch to force, bypass or decline an eligible trial.

For an eligible recurring-plan trial, a project API key can grant access to the named `user_id` without customer sign-in. This is a **manual trial**: no stored-card charge, wallet debit or automatic renewal. The member needs a new payment to continue after the trial ends.

Use `merchant_account_id` for configured checkout. An active, permitted external merchant account supporting the receipt currency is required even for a zero-price manual trial. For eligible **recurring-plan** trials only, `provider: "internal"` can also complete as a manual zero-price grant; it gives the key no authority to spend the customer's wallet. Missing or unverifiable setup is refused.

For a **nonrecurring trial plan**, send `merchant_account_id`. An eligible customer can receive the configured zero-cost trial, such as seven days, without signing in, a wallet debit, stored-card use or a subscription. For these plans, `provider: "internal"` remains a wallet-funding input and returns `403 FORBIDDEN`, even when the customer qualifies for a trial.

Coupons cannot be combined with an eligible recurring-plan trial. Remove the coupon and retry the corrected request; the backend does not silently charge instead. Unverifiable eligibility or receipt recovery is also refused.

Where returned, `payment_request_data.manual_trial.starts_at` and `ends_at` are UTC ISO strings with milliseconds, for example `"2030-01-01T00:00:00.000Z"`. Nonrecurring trial receipts need not include this marker. Existing or ineligible members follow normal paid-plan eligibility checks. Trials do not refund or convert existing memberships.

## Open checkouts and retries

Creation also has a per-customer limit of five requests per ten-minute window, plus a project-key actor limit of sixty per ten-minute window. These checks apply in addition to HTTP route limits and can return `429 TOO_MANY_REQUESTS` with `error.retry_after_seconds`. Wait for that delay before retrying the same request and idempotency key; creating another plan does not reset the customer's limit.

An existing payable checkout can block a new trial with `409 SUBSCRIPTION_IN_PROGRESS`. Follow its cancel-or-expire guidance: use [Cancel Checkout](https://docs.botsubscription.com/api/payment-requests/cancel/) with the saved `payment_request_id`, or wait for provider expiry. Cancellation requires `payment-requests:update` for restricted keys, is provider-dependent and can itself return `409`.

The same error code can also describe ordinary work in progress. With `error.reason: "PREPARING"`, wait `error.retry_after_seconds`, then retry with the same key and unchanged body. A response saying that payment status is being confirmed also calls for retry recovery, rather than cancellation solely because it is a `409`.

A zero-price receipt that is genuinely still pending also returns `409` while unresolved. Wait and retry unchanged; do not present it as completed or redirect it to payment. If a stored receipt is completed but its access grant is still owed, retry the original request with the same key and body so the server can finish recovery of that receipt. Do not start a new purchase to repair it.

Once a failed checkout is confirmed to be dead, the server releases its stale cache before the next trial attempt. There is no need to wait out the old cache's full lifetime. If correcting a rejected request, such as removing a coupon, use a new idempotency key for the changed request.

## Use a custom return hostname when needed

You do not need to configure `custom_hostname` to create a Payment Request. No custom hostname setup is required when you omit `success_url` and `cancel_url` or use the default return hostname provided by BotSubscription.

Configure `custom_hostname` only when a supplied return URL should use your own hostname. See [Configure Custom Hostname](https://docs.botsubscription.com/api/settings/custom-hostname/) for the request, API key access requirements, value format, and possible conflicts.

## Return URL contract

`success_url` and `cancel_url` are checked independently. For each field you provide:

- The complete JSON value must be an `https://` URL.
- Its origin must be trusted for the project. Use the default return origin provided by BotSubscription or the exact configured `custom_hostname`. For example, a configured value of `example.com` does not authorize `www.example.com` or `subdomain.example.com`.
- Its path and query string may vary within that trusted origin.
- Validation uses the `success_url` and `cancel_url` JSON fields. HTTP `Origin` and `Referer` headers do not authorize a return URL.

If either supplied URL is malformed or uses an unauthorized hostname, the API rejects the request with `422`. It does not treat the current `Origin`, `Referer`, CORS configuration, or caller location as a substitute.

## Request

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="user_id" type="string" required description="Customer's platform ID as a string, or a linked customer-account UUID that resolves to this project's platform. A platform ID can identify a customer without an existing project record." />
  <ApiParameter name="plan_id" type="string" required description="Plan UUID. Its configuration and the customer's history determine the authoritative price, duration and trial eligibility." />
  <ApiParameter name="merchant_account_id" type="string" description="External merchant account UUID, required for hosted checkout and nonrecurring trial plans. A recurring-plan manual trial also needs an active, permitted external account supporting the receipt currency." />
  <ApiParameter name="amount" type="string|number" description="Omit for plan checkout. The backend determines the price; this field cannot override it or select a trial. Supplied values still undergo decimal range and numeric precision validation." />
  <ApiParameter name="coupon_id" type="string" description="Optional coupon UUID, applied against the authoritative plan price. Rejected when combined with an eligible recurring-plan trial; remove it and retry." />
  <ApiParameter name="pay_currency" type="string" description="Crypto payment currency advertised by the selected merchant's enabled requirements. Uppercase alphanumeric, 3 to 9 characters; use the returned value, which may include a network suffix." />
  <ApiParameter name="pay_network" type="string" description="Optional crypto network selector. Surrounding whitespace is trimmed; the value must contain 2 to 10 ASCII letters or digits and be allowed by the selected merchant." />
  <ApiParameter name="provider" type="string" description="Omit for configured checkout; merchant_account_id selects the gateway. The internal value returns 403 for nonrecurring trial plans, even when eligible. Only an eligible recurring-plan trial may complete through it as a zero-price manual grant; no wallet debit is authorized. Other values are ignored." />
  <ApiParameter name="success_url" type="string" description="Optional complete HTTPS URL for a successful return. Its origin must be trusted for the project; paths and queries may vary. Validation uses this JSON field, not Origin or Referer." />
  <ApiParameter name="cancel_url" type="string" description="Optional complete HTTPS URL for a cancelled return. Its origin must be trusted for the project; paths and queries may vary. Validation uses this JSON field, not Origin or Referer." />
</ApiSection>

For project-key creation, omit `"provider": "stripe"`. The selected `merchant_account_id` determines that Stripe is the payment gateway.

## Crypto currency and network selection

Read the selected merchant with `?expand=requirements.enabled` using [Get Provider Details](https://docs.botsubscription.com/api/merchant-accounts/get/) before selecting a crypto payment currency. Use its advertised `pay_currency` values, which can include a compound value such as `USDTTRC20`. There is no universal network enum shared by all merchants.

Prefer the advertised compound value unchanged, for example `{"pay_currency":"USDTTRC20"}`, and omit `pay_network`. A supported split selection can use `{"pay_currency":"USDT","pay_network":"TRC20"}`. A recognized currency's embedded network takes precedence over a separate network selector. Without an explicit network, selection may use one of the merchant's enabled networks; there is no fixed default.

Both selectors are optional, non-nullable strings in the general request schema, but the merchant's requirements still apply. NOWPayments requires a payment currency to complete a crypto checkout.

Invalid selector syntax returns `422 VALIDATION_ERROR`. A network that is not allowed by the merchant can return `422 MERCHANT_NETWORK_NOT_ALLOWED`. These selectors choose the payment route; they do not authorize a wallet debit or stored-payment-method charge.

Crypto `pay_currency` and response `crypto_currency` identify the provider's token or network-specific currency, rather than requiring a three-letter fiat code. Use an identifier accepted by the selected provider.

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X POST "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/payment-requests" \
  -H "Authorization: Bearer YOUR_PROJECT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: checkout-order-8472" \
  -d '{
    "user_id": "123456789012345678",
    "plan_id": "11111111-1111-4111-8111-111111111111",
    "merchant_account_id": "22222222-2222-4222-8222-222222222222",
    "success_url": "https://example.com/checkout/success?order=8472",
    "cancel_url": "https://example.com/checkout/cancel?order=8472"
  }'
```

```javascript
const projectId = 'YOUR_PROJECT_ID';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${projectId}/payment-requests`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_PROJECT_API_KEY',
    'Content-Type': 'application/json',
    'Idempotency-Key': 'checkout-order-8472'
  },
  body: JSON.stringify({
    user_id: '123456789012345678',
    plan_id: '11111111-1111-4111-8111-111111111111',
    merchant_account_id: '22222222-2222-4222-8222-222222222222',
    success_url: 'https://example.com/checkout/success?order=8472',
    cancel_url: 'https://example.com/checkout/cancel?order=8472'
  })
});
const result = await response.json();

if (!response.ok || !result.ok) {
  throw new Error(JSON.stringify(result.error ?? result.errors));
}
const receipt = result.data;
// A completed receipt, including a zero-price trial, needs no redirect.
const paymentUrl = receipt.status === 'pending' && Number(receipt.amount) > 0
  ? receipt.payment_url : undefined;
// Return the receipt status and any payment URL to your frontend; keep the API key private.
```

```python
import requests
from decimal import Decimal

project_id = 'YOUR_PROJECT_ID'
response = requests.post(
    f'https://api.botsubscription.com/v2/projects/{project_id}/payment-requests',
    headers={
        'Authorization': 'Bearer YOUR_PROJECT_API_KEY',
        'Content-Type': 'application/json',
        'Idempotency-Key': 'checkout-order-8472'
    },
    json={
        'user_id': '123456789012345678',
        'plan_id': '11111111-1111-4111-8111-111111111111',
        'merchant_account_id': '22222222-2222-4222-8222-222222222222',
        'success_url': 'https://example.com/checkout/success?order=8472',
        'cancel_url': 'https://example.com/checkout/cancel?order=8472'
    }
)
response.raise_for_status()
result = response.json()
receipt = result['data']
# Show completed receipts without redirecting, including zero-price trials.
payment_url = (receipt.get('payment_url')
               if receipt['status'] == 'pending' and Decimal(receipt['amount']) > 0 else None)
```

```php
$project_id = 'YOUR_PROJECT_ID';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/payment-requests");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_PROJECT_API_KEY',
    'Content-Type: application/json',
    'Idempotency-Key: checkout-order-8472'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'user_id' => '123456789012345678',
    'plan_id' => '11111111-1111-4111-8111-111111111111',
    'merchant_account_id' => '22222222-2222-4222-8222-222222222222',
    'success_url' => 'https://example.com/checkout/success?order=8472',
    'cancel_url' => 'https://example.com/checkout/cancel?order=8472'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$result = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
if (!($result['ok'] ?? false)) {
    throw new RuntimeException('Payment request rejected. Inspect error or errors in the response.');
}
$receipt = $result['data'];
// Show completed receipts without redirecting, including zero-price trials.
$paymentUrl = $receipt['status'] === 'pending' && (float) $receipt['amount'] > 0
    ? ($receipt['payment_url'] ?? null) : null;
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={201} description="Hosted checkout pending">

```json
{
  "ok": true,
  "request_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 201,
  "message": "Payment request created successfully",
  "data": {
    "payment_request_id": "11111111-1111-4111-8111-111111111111",
    "request_type": "invoice",
    "amount": "23.99",
    "currency": "USD",
    "status": "pending",
    "provider_payment_id": "cs_test_example",
    "merchant_account_id": "22222222-2222-4222-8222-222222222222",
    "failure_reason": null,
    "payment_error_code": null,
    "payment_url": "https://checkout.stripe.com/c/pay/cs_test_example",
    "provider": "stripe",
    "payment_request_data": {},
    "superseded": false
  }
}
```

  </ApiResponse>
  <ApiResponse status={201} description="Recurring-plan manual trial completed without a checkout URL">

```json
{
  "ok": true,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 201,
  "message": "Payment request created successfully",
  "data": {
    "payment_request_id": "33333333-3333-4333-8333-333333333333",
    "request_type": "invoice",
    "amount": "0",
    "currency": "USD",
    "status": "completed",
    "provider_payment_id": null,
    "merchant_account_id": "22222222-2222-4222-8222-222222222222",
    "failure_reason": null,
    "payment_error_code": null,
    "provider": "stripe",
    "payment_request_data": {
      "manual_trial": {
        "version": 1,
        "starts_at": "2026-10-21T09:00:00.000Z",
        "ends_at": "2026-10-24T09:00:00.000Z"
      }
    }
  }
}
```

  </ApiResponse>
  <ApiResponse status={201} description="Nonrecurring trial completed through a merchant account">

```json
{
  "ok": true,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 201,
  "message": "Payment request created successfully",
  "data": {
    "payment_request_id": "55555555-5555-4555-8555-555555555555",
    "request_type": "invoice",
    "amount": "0",
    "currency": "USD",
    "status": "completed",
    "provider_payment_id": null,
    "merchant_account_id": "22222222-2222-4222-8222-222222222222",
    "failure_reason": null,
    "payment_error_code": null,
    "provider": "stripe",
    "payment_request_data": {}
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Return URL rejected">

```json
{
  "ok": false,
  "request_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 422,
  "error": {
    "error_code": "PAYMENT_RETURN_URL_NOT_ALLOWED",
    "message": "success_url must use HTTPS and a hostname authorized for this project",
    "reason": "success_url"
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Active membership conflict">

```json
{
  "ok": false,
  "request_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 409,
  "error": {
    "error_code": "DUPLICATE_ACTIVE_MEMBERSHIP",
    "message": "You already have an active membership for this plan."
  }
}
```

  </ApiResponse>
  <ApiResponse status={400} description="Coupon cannot be combined with a trial">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 400,
  "error": {
    "error_code": "BAD_REQUEST",
    "message": "Coupons cannot be combined with this recurring trial."
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Open paid checkout blocks a trial">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 409,
  "error": {
    "error_code": "SUBSCRIPTION_IN_PROGRESS",
    "message": "A paid checkout is still open for this plan. Cancel it or wait for it to expire, then start your free trial."
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Creation is still in progress">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 409,
  "error": {
    "error_code": "SUBSCRIPTION_IN_PROGRESS",
    "message": "Your payment is being prepared. Please wait a moment and try again.",
    "reason": "PREPARING",
    "retry_after_seconds": 3
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Zero-price receipt is still pending">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 409,
  "error": {
    "error_code": "SUBSCRIPTION_IN_PROGRESS",
    "message": "Your payment status is being confirmed. Please wait a moment and try again."
  }
}
```

  </ApiResponse>
  <ApiResponse status={503} description="Trial eligibility could not be verified">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 503,
  "error": {
    "error_code": "SERVICE_UNAVAILABLE",
    "message": "Trial eligibility could not be verified. Please try again."
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Crypto network is not allowed">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 422,
  "error": {
    "error_code": "MERCHANT_NETWORK_NOT_ALLOWED",
    "message": "The selected network is not available for this merchant account."
  }
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
  <ApiResponse status={429} description="Payment creation rate limit reached">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 429,
  "error": {
    "error_code": "TOO_MANY_REQUESTS",
    "message": "Too many payment requests in a short period. Please wait before trying again.",
    "retry_after_seconds": 60
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Coupon leaves an unchargeable remainder">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests",
  "code": 422,
  "error": {
    "message": "Coupon is not eligible: REMAINDER_BELOW_MINOR_UNIT",
    "error_code": "VALIDATION_ERROR"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>

## Platform user and community behavior

A `user_id` may identify a platform user the project has not seen before. For Discord, you may supply that user's snowflake. The API can materialize the local user automatically, so the customer does not need to be in the corresponding Discord guild or Telegram community while paying.

Payment does not join the customer to a Discord guild, Telegram group, or Telegram channel. If the same platform account joins later, BotSubscription restores applicable access while the membership remains valid and the bot has the required permissions. For Discord, this includes restoring active membership roles.

## Confirm the outcome authoritatively

For hosted checkout, do not grant access from the `success_url` redirect alone. Customers can revisit or copy redirect URLs, and browser navigation can occur before asynchronous payment processing finishes.

Use a verified completion webhook or fetch the Payment Request until it reaches an authoritative status. The [webhook signature guide](https://docs.botsubscription.com/webhooks/signature-verification/) explains how to verify server-to-server events. A completed zero-price receipt can represent a free plan, fully discounted checkout or trial. If activation is still owed, use the same-request recovery described above.
