-
Notifications
You must be signed in to change notification settings - Fork 366
Add Pay.sh pages for Accept Payments and Subscriptions #1525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lgalabru
merged 9 commits into
solana-foundation:main
from
datasalaryman:payments-with-paysh
Jul 9, 2026
+225
−2
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
caf0c0c
feat(payments): add with paysh sections
datasalaryman e747bf7
fix: add pay sh introduction to three pages
datasalaryman 0060f08
Update apps/docs/content/docs/en/payments/subscriptions/pay-sh.mdx
datasalaryman 66c4427
fix: remove topup step
datasalaryman 116506c
fix: fix server demo step
datasalaryman edc6757
fix: various fixes
datasalaryman ceaecfe
fix: even more various fixes
datasalaryman 8e63b22
fix: update subscriptions server paysh example
datasalaryman 6772ae8
fix: show json response instead
datasalaryman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
74
apps/docs/content/docs/en/payments/accept-payments/pay-sh.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` | ||
|
|
||
| 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 | ||
| ``` | ||
|
|
||
|
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). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
apps/docs/content/docs/en/payments/subscriptions/pay-sh.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
|
|
||
| ``` | ||
|
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 | ||
|
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). | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.