Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Accept Payments",
"pages": ["payment-button", "verification-tools", "indexing"],
"pages": ["payment-button", "verification-tools", "indexing", "pay-sh"],
"defaultOpen": false
}
74 changes: 74 additions & 0 deletions apps/docs/content/docs/en/payments/accept-payments/pay-sh.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: With Pay.sh
description: Accept payments with Pay.sh.
---

You can accept payments on API requests via Pay.sh by setting up a Pay server.
Install Pay with:

```bash
brew install pay
```

or

```bash
npm install -g @solana/pay
```
Comment thread
datasalaryman marked this conversation as resolved.

Verify the installation with:

```bash
pay --version
```

The toolchain will set up your address for you. Run the following to setup and
topup your wallet:

```bash
pay setup
```

## Setting up the demo server

You can start accepting payments by starting your server. You can see a demo
server in action with:

```bash
pay server demo
```

This does two things. It starts a live Pay server which you can query via HTTP
request, and it generates a `pay-demo.yml` file in your current directory.

All API routes are configured via the `endpoints` YAML config. In order to
accept payments, you have to add a `metering:` attribute. The
`/api/v1/reports/usage` route has been done as an example for you:

```yaml
endpoints:
- method: GET
path: "api/v1/reports/usage"
resource: "reports"
description: "Usage report — flat fee, no splits."
metering:
dimensions:
- direction: usage
unit: requests
scale: 1
tiers:
- price_usd: 0.01
```

Comment thread
datasalaryman marked this conversation as resolved.
You can test that the payments work by running the following command as a client
on another terminal:

```bash
pay --sandbox curl http://127.0.0.1:1402/api/v1/reports/usage
```

You can learn more about how to define pricing in the
[Pay.sh Building with Pay > Pricing docs](https://pay.sh/docs/building-with-pay/pricing)

Learn more about setting up Pay.sh in production in the
[Pay.sh Configuration docs](https://pay.sh/docs/toolchain/configuration).
25 changes: 25 additions & 0 deletions apps/docs/content/docs/en/payments/agentic-payments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ APIs without provider accounts or API keys. When an API returns an MPP or x402
`402 Payment Required` challenge, `pay` asks your local wallet to approve
signing.

You can install Pay with:

```bash
brew install pay
```

or

```bash
npm install -g @solana/pay
```

Verify the installation with:

```bash
pay --version
```

The toolchain will set up your address for you. Run the following to setup and
topup your wallet:

```bash
pay setup
```

## The x402 Protocol

Agentic payments need a way for clients and servers to negotiate payment terms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"fixed-delegation",
"recurring-delegation",
"subscription-plan",
"close-subscription-authority"
"close-subscription-authority",
"pay-sh"
],
"defaultOpen": false
}
127 changes: 127 additions & 0 deletions apps/docs/content/docs/en/payments/subscriptions/pay-sh.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
title: With Pay.sh
description: Create subscriptions with Pay.sh.
---

You can set up subscriptions via Pay.sh by setting up a Pay client on your
device or by setting up a Pay server. Install Pay with:

```bash
brew install pay
```

or

```bash
npm install -g @solana/pay
```

Verify the installation with:

```bash
pay --version
```

The toolchain will set up your address for you. Run the following to setup and
topup your wallet:

```bash
pay setup
```

## Subscriptions as a client

Users subscribe to subscription-gated API endpoints by invoking pay like normal.
It is on the API to send the subscription details in the initial `402 Status`
Response. Pay handles the subscription automatically, including instruction
invocation on the Solana SPL Subscriptions Program.

Users can manage their subscriptions using the following commands:

```bash
pay subscriptions # default: list + show available subcommands
pay subscriptions list # same, scriptable
pay subscriptions list --network mainnet
pay subscriptions list --json
```

You can learn more about managing your subscriptions as a user in the
[Pay.sh > Using Pay > Manage Subscriptions docs](https://pay.sh/docs/using-pay/subscriptions).

## Managing subscriptions as a provider (demo)

Pay servers allow for configuring subscribers and their subscriptions for each
endpoint. The following is an endpoint example that uses pay you can try with
your project:

```yaml
# monthly.yml
name: Subscriptions Example
subdomain: subscriptions-example
title: "Subscription Example"
description: "Demo Subscriptions"
category: ai_ml
version: v1
routing:
type: respond
operator:
currencies:
usd: ["USDC", "USDT", "CASH"]
network: "localnet"
fee_payer: true
challenge_binding_secret: d858d9104afd728f58a1f73d806dd75d8f32ebd37c9707145816b490e8631d41
# insert your own challenge_binding_secret here. use `openssl rand -hex 32`

endpoints:
- method: GET
path: "api/v1/pro/feed"
resource: "pro-feed"
description: "Pro feed — monthly subscription, 30-day billing period."
subscription:
period: "30d"
price_usd: 9.99
currency: USDC
plan_id_numeric: 1
```

Pay handles subscriptions using the `subscription:` attribute in its `endpoints`
YAML specification. This is opposed to the `metering:` attribute for pay-per-use
endpoints.

Starting the server in the above example creates an endpoint called
`api/v1/pro/feed` that requires a user to make recurring payments of 9.99 USDC
to it every 30 days.

You can try it by running the following command:

```bash
pay server start monthly.yml
```

Running this command will prompt you to create a plan. This creates a plan and
updates the yml file. If you're going to use it again, remember the plan address
and use that in your config as you're making changes.

You can test that the subscriptions work by running the following commands as a
client on another terminal:

```bash
# First call — activates the subscription, $9.99 USDC charge settles.
pay --sandbox curl http://127.0.0.1:1402/api/v1/pro/feed

# Same call within 30 days — no payment prompt, just the response.
pay --sandbox curl http://127.0.0.1:1402/api/v1/pro/feed
```

You should see an OK status as a response like this:

```
Comment thread
datasalaryman marked this conversation as resolved.
Outdated
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:
100 15 100 15 0 0 14272 0 --:--:-- --:--:-- --:--:-- 15000
Comment thread
datasalaryman marked this conversation as resolved.
Outdated
{"status":"ok"}
```

You can learn more about managing subscriptions on a Pay server via the
[Pay.sh > Building with Pay > Subscriptions > YAML Specification docs](https://pay.sh/docs/building-with-pay/subscriptions/yaml-specification).
Loading