支払いサブスクリプション

Pay.shを使用する

Pay.shを通じてサブスクリプションを設定するには、デバイスにPayクライアントをセットアップするか、Payサーバーをセットアップします。Payをインストールするには:

brew install pay

または

npm install -g @solana/pay

インストールを確認するには:

pay --version

ツールチェーンがアドレスを自動的に設定します。以下を実行してウォレットのセットアップとチャージを行ってください:

pay setup

クライアントとしてのサブスクリプション

ユーザーは通常通りpayを呼び出すことで、サブスクリプション制限付きAPIエンドポイントにサブスクライブします。APIは最初の402 Statusレスポンスでサブスクリプションの詳細を送信する必要があります。Payはサブスクリプションを自動的に処理し、Solana SPL Subscriptions Programでのinstructionsの実行も含まれます。

ユーザーは以下のコマンドを使用してサブスクリプションを管理できます:

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

ユーザーとしてサブスクリプションを管理する方法の詳細については、Pay.sh > Payを使う > サブスクリプション管理ドキュメントをご覧ください。

プロバイダーとしてのサブスクリプション管理(デモ)

Payサーバーでは、各エンドポイントのサブスクライバーとそのサブスクリプションを設定できます。以下は、プロジェクトで試すことができるpayを使用したエンドポイントの例です:

# 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はsubscription: YAMLスペックのendpoints属性を使用してサブスクリプションを処理します。これは従量課金エンドポイントのmetering:属性とは異なります。

上記の例でサーバーを起動すると、api/v1/pro/feedというエンドポイントが作成され、ユーザーは30日ごとに9.99 USDCの定期支払いが必要になります。

以下のコマンドを実行して試すことができます:

pay server start monthly.yml

このコマンドを実行すると、プランの作成を求めるプロンプトが表示されます。これによりプランが作成され、ymlファイルが更新されます。再度使用する場合は、プランのアドレスを控えておき、変更を加える際にconfigで使用してください。

別のターミナルでクライアントとして以下のコマンドを実行することで、サブスクリプションが正常に機能しているかテストできます:

# 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

以下のようなOKステータスのレスポンスが表示されるはずです:

{ "status": "ok" }

Payサーバーでのサブスクリプション管理の詳細については、 Pay.sh > Building with Pay > Subscriptions > YAML Specification docs をご参照ください。

Is this page helpful?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。