<!-- ZenPays documentation · https://docs.zenpayz.com/docs/rest-api/endpoints/billing/payment-links/create-payment-link -->

# Create Payment Link

Create a new payment link that can be shared with customers to collect payments.

<EndpointHeader verb="POST" path="/merchant/api/v1/payment-links" />

## Request

### Headers

<ParamTable
  label="Header"
  rows={[
    { name: "Authorization", required: true, desc: "`Bearer {api_key}`" },
    { name: "X-Signature", required: true, desc: "HMAC-SHA256 signature" },
    { name: "X-Timestamp", required: true, desc: "ISO 8601 timestamp" },
    { name: "X-Secret-Salt", required: true, desc: "Secret salt for HMAC validation" },
    { name: "Content-Type", required: true, desc: "`application/json`" },
  ]}
/>

### Body Parameters

<ParamTable
  rows={[
    { name: "title", type: "string", required: true, desc: "Payment link title (1-255 characters)" },
    { name: "description", type: "string", desc: "Payment link description" },
    { name: "amount", type: "number", required: true, desc: "Payment amount (minimum 0.01)" },
    { name: "currency", type: "string", desc: "Currency code (default: `INR`)" },
    { name: "usageType", type: "string", desc: "Usage type (default: `SINGLE`). One of `SINGLE`, `MULTI`" },
    { name: "maxUses", type: "number", desc: "Maximum number of uses (minimum 1, only for `MULTI` type)" },
    { name: "expiresAt", type: "string", desc: "Expiration date (ISO 8601)" },
    { name: "productId", type: "string", desc: "Associated product ID" },
    { name: "customerId", type: "string", desc: "Associated customer ID" },
    { name: "invoiceId", type: "string", desc: "Associated invoice ID" },
    { name: "invoiceIds", type: "string[]", desc: "Array of associated invoice IDs" },
    { name: "metadata", type: "object", desc: "Custom key-value pairs" },
  ]}
/>

## Response

### Success (201 Created)

```json
{
  "success": true,
  "data": {
    "linkId": "pl_a1b2c3d4e5f6g7h8",
    "title": "Pro Plan Payment",
    "description": "Payment for Pro Plan subscription",
    "amount": 4999,
    "currency": "INR",
    "status": "ACTIVE",
    "usageType": "SINGLE",
    "maxUses": null,
    "usageCount": 0,
    "expiresAt": "2024-02-15T23:59:59.000Z",
    "productId": "prod_a1b2c3d4e5f6g7h8",
    "customerId": null,
    "invoiceId": null,
    "paymentUrl": "https://pay.zenpayz.com/pl_a1b2c3d4e5f6g7h8",
    "shortCode": "ZP-XYZ789",
    "shortUrl": "https://pay.zenpayz.com/s/ZP-XYZ789",
    "metadata": {},
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:30:00.000Z"
  },
  "message": "Payment link created successfully",
  "error": null,
  "meta": {
    "request_id": "req_xxxxx",
    "timestamp": "2024-01-15T10:30:00.000Z",
    "processing_time_ms": 55,
    "api_version": "v1",
    "endpoint": "POST /payment-links",
    "user_type": "merchant"
  }
}
```

### Error Responses

<ErrorTable
  rows={[
    { code: "VALIDATION_ERROR", status: "400", message: "Invalid request parameters" },
    { code: "UNAUTHORIZED", status: "401", message: "Invalid API key" },
    { code: "PRODUCT_NOT_FOUND", status: "404", message: "Associated product does not exist" },
    { code: "INVOICE_NOT_FOUND", status: "404", message: "Associated invoice does not exist" },
  ]}
/>

<CodeRail>

## Examples

<Tabs groupId="language">
  <TabItem value="curl" label="cURL" default>

```bash
curl -X POST https://api.zenpayz.com/merchant/api/v1/payment-links \
  -H "Authorization: Bearer zp_test_xxxxx" \
  -H "X-Timestamp: 2024-01-15T10:30:00.000Z" \
  -H "X-Signature: a1b2c3d4e5f6..." \
  -H "X-Secret-Salt: your_secret_salt" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Pro Plan Payment",
    "description": "Payment for Pro Plan subscription",
    "amount": 4999,
    "currency": "INR",
    "usageType": "SINGLE",
    "expiresAt": "2024-02-15T23:59:59.000Z",
    "productId": "prod_a1b2c3d4e5f6g7h8"
  }'
```

  </TabItem>
  <TabItem value="javascript" label="JavaScript">

```javascript
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/payment-links', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'X-Timestamp': timestamp,
    'X-Signature': signature,
    'X-Secret-Salt': secretSalt,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    title: 'Pro Plan Payment',
    description: 'Payment for Pro Plan subscription',
    amount: 4999,
    currency: 'INR',
    usageType: 'SINGLE',
    expiresAt: '2024-02-15T23:59:59.000Z',
    productId: 'prod_a1b2c3d4e5f6g7h8',
  }),
});

const result = await response.json();
console.log(result.data.linkId); // pl_a1b2c3d4e5f6g7h8
console.log(result.data.shortUrl); // "https://pay.zenpayz.com/s/ZP-XYZ789"
```

  </TabItem>
  <TabItem value="sdk" label="SDK">

```javascript
const link = await zenpays.paymentLinks.create({
  title: 'Pro Plan Payment',
  description: 'Payment for Pro Plan subscription',
  amount: 4999,
  currency: 'INR',
  usageType: 'SINGLE',
  expiresAt: '2024-02-15T23:59:59.000Z',
  productId: 'prod_a1b2c3d4e5f6g7h8',
});

console.log(link.linkId); // pl_a1b2c3d4e5f6g7h8
console.log(link.shortUrl); // "https://pay.zenpayz.com/s/ZP-XYZ789"
```

  </TabItem>
</Tabs>

</CodeRail>

## Related Endpoints

- [List Payment Links](/docs/rest-api/endpoints/billing/payment-links/list-payment-links)
- [Get Payment Link](/docs/rest-api/endpoints/billing/payment-links/get-payment-link)
- [Update Payment Link](/docs/rest-api/endpoints/billing/payment-links/update-payment-link)
- [Payment Link Analytics](/docs/rest-api/endpoints/billing/payment-links/payment-link-analytics)
