Create a Payment Link
Create a reusable payment link for your product and share it with customers.
Create a Payment Link
A payment link is a reusable checkout URL. You create one for each product, plan, or price point you sell. Bag gives you a hosted checkout page your customers can pay through — no frontend work required.
Before you start
You'll need:
- A Bag account with an API key (how to get one)
- The
BAG_API_KEYenvironment variable set
Create a link
import { Bag } from "@getbagsapp/sdk";
const bag = new Bag({
apiKey: process.env.BAG_API_KEY!,
});
const link = await bag.paymentLinks.create({
name: "Pro Plan",
description: "Monthly subscription to the Pro plan",
amount: 29.99,
network: "base_sepolia",
});
console.log(`Checkout URL: https://justusebag.xyz/pay/${link._id}`);import os
import requests
API_KEY = os.environ["BAG_API_KEY"]
response = requests.post(
"https://justusebag.xyz/api/payment-links",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json={
"name": "Pro Plan",
"description": "Monthly subscription to the Pro plan",
"amount": 29.99,
"network": "base_sepolia",
},
)
link = response.json()["data"]
print(f"Checkout URL: https://justusebag.xyz/pay/{link['_id']}")curl -X POST https://justusebag.xyz/api/payment-links \
-H "Authorization: Bearer $BAG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Pro Plan",
"description": "Monthly subscription to the Pro plan",
"amount": 29.99,
"network": "base_sepolia"
}'Response
{
"status": "success",
"data": {
"_id": "665f1a2b3c4d5e6f7a8b9c0d",
"name": "Pro Plan",
"description": "Monthly subscription to the Pro plan",
"amount": 29.99,
"currency": "USD",
"network": "base_sepolia",
"token": "USDC",
"active": true,
"merchantWalletAddress": "0xYourWalletAddress",
"totalCollected": 0,
"totalTransactions": 0,
"createdAt": "2026-03-01T12:00:00.000Z",
"updatedAt": "2026-03-01T12:00:00.000Z"
}
}Your checkout page is live at https://justusebag.xyz/pay/{_id}. Share this URL with customers, embed it in your app, or redirect to it after a "Buy" button click.
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name shown on the checkout page |
amount | number | Yes | Price in USD |
network | string | Yes | Primary blockchain network |
description | string | No | Description shown on checkout |
currency | string | No | Defaults to USD |
token | string | No | Defaults to USDC |
networks | string[] | No | Allow payment on multiple chains |
merchantWalletAddress | string | No | Override the default receiving wallet |
merchantWalletAddresses | object | No | Per-network wallet addresses |
Supported networks
| Network | Value | Environment |
|---|---|---|
| Base | base | Production |
| Ethereum | ethereum | Production |
| Polygon | polygon | Production |
| Solana | solana | Production |
| Base Sepolia | base_sepolia | Sandbox |
| Ethereum Sepolia | eth_sepolia | Sandbox |
| Solana Devnet | solana_devnet | Sandbox |
Update a link
Change the name, amount, or deactivate a link:
const updated = await bag.paymentLinks.update("665f1a2b3c4d5e6f7a8b9c0d", {
amount: 39.99,
name: "Pro Plan (Annual)",
});curl -X PATCH https://justusebag.xyz/api/payment-links/665f1a2b3c4d5e6f7a8b9c0d \
-H "Authorization: Bearer $BAG_API_KEY" \
-H "Content-Type: application/json" \
-d '{"amount": 39.99, "name": "Pro Plan (Annual)"}'Deactivate a link
Deactivating a link prevents new payments. Existing transactions are unaffected.
await bag.paymentLinks.update("665f1a2b3c4d5e6f7a8b9c0d", {
active: false,
});Delete a link
await bag.paymentLinks.delete("665f1a2b3c4d5e6f7a8b9c0d");Deleting is permanent. If you might want to re-enable the link later, deactivate it instead.
List your links
const links = await bag.paymentLinks.list();
for (const link of links) {
console.log(`${link.name}: $${link.amount} — ${link.totalTransactions} payments`);
}Multi-chain payment links
To let customers pay on any supported chain, pass the networks array and per-network wallet addresses:
const link = await bag.paymentLinks.create({
name: "Pro Plan",
amount: 29.99,
network: "base",
networks: ["base", "ethereum", "polygon", "solana"],
merchantWalletAddresses: {
base: "0xYourBaseWallet",
ethereum: "0xYourEthWallet",
polygon: "0xYourPolygonWallet",
solana: "YourSolanaWalletAddress",
},
});The checkout page will show a network selector so the customer can choose where to pay. See Accept Payments on Multiple Chains for details.