Stripe CLIのインストールが終われば、次はStripeアカウントへの接続です。
Stripe CLIはStripe APIを介してStripeのリソースにアクセスします。そのため、Stripeアカウントに接続してAPIキーを取得する必要があります。
stripe login
でStripeアカウントと接続
Stripeアカウントとの連携は、stripe login
コマンドで行います。
コマンドを実行すると、「Enterキーを押してブラウザを開いてね」とメッセージが表示されますので、[Enterキー]を押しましょう。
% stripe login
Your pairing code is: amuse-revive-timely-sturdy
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser (^C to quit)
Stripe Dashboardにログインしている状態であれば、以下の画像のようにアクセス権の確認画面が表示されます。
[アクセスを許可]をクリックすると、完了画面が表示されます。
Stripe CLIの画面に戻ると、接続が成功したことが英文で表示されています。
> Done! The Stripe CLI is configured for api-test with account id acct_xxxxxxxx
Please note: this key will expire after 90 days, at which point you'll need to re-authenticate.
stripe logout
で接続解除
そのStripeアカウントに接続する必要がなくなった場合、stripe logout
コマンドを実行することで接続を解除できます。
% stripe logout --project-name test
Logging out...
Credentials have been cleared for test.
なお、このコマンドだけでは発行された[制限付きキー]は削除されません。あくまでPC内の接続情報を削除するだけの挙動をしている様子です。
そのため、退職や部署移動などの場合、該当する[制限付きキー]をStripe Dashboardから削除しておくことをお勧めします。
stripe login
は90日毎に再認証が必要
Tips: stripe login
を実行すると、接続したStripeアカウントに[制限付きキー]が発行されます。
このキーは90日で期限が切れますので、91日目からは再度stripe login
を行う必要があります。
Tips: 発行された制限付きキーは絶対に共有やgit commitしない
stripe login
で発行される[制限付きキー]は、[全てのリソースの読み取り権限]を持ちます。
そのため、CIでの利用やプロジェクトメンバー同士での共有などを目的にGitでcommitしたり、不特定多数が閲覧する可能性のある場所にキー情報を記載してはいけません。
また、ユーザー毎にstripe login
経由で[制限付きキー]を発行することで、APIキー単位でのアクセスログを利用した監査が行えます。
インシデントが発生したと思われる場合などに、「どのAPIキーが漏洩したか」を追跡しやすくなりますので、原則「1環境1制限付きキー」で運用することをお勧めします。
キーが漏洩した可能性が出た場合は、Stripe DashboardからAPIキーを無効化し、再度stripe login
を実行して新しい[制限付きキー]を発行してもらうようにしましょう。
stripe open
コマンドでDashboard / Documentに簡単アクセス
Stripe CLIには、Stripeの各ページを開くopen
コマンドが用意されています。
% stripe open --help
The open command provices shortcuts to quickly let you open pages to Stripe with
in your browser. A full list of support shortcuts can be seen with 'stripe open --list'
Usage:
stripe open [flags]
Examples:
stripe open --list
stripe open api
stripe open docs
stripe open dashboard/webhooks
stripe open dashboard/billing --live
このコマンドを実行することで、DashboardへのアクセスやAPIドキュメントの確認をCLIから行うことができます。
例: DashboardのCustomer情報を開く
Stripe Dashboardをブラウザで開く場合、 stripe open dashboard/{RESOURCE_NAME}
コマンドを使います。
$ stripe open dashboard/customers
このコマンドを実行すると、デフォルトに設定しているブラウザでStripe DashboardのCustomerページ(test環境)が開きます。
Live環境を開きたい場合は、--live
フラグをコマンドに追加しましょう。
stripe open --list
で開けるページを確認する
stripe open
で開けるページを確認したい場合、--list
オプションを追加しましょう。
以下のように、コマンド別にどのURLが開くかを一覧で確認できます。
% stripe open --list
open quickly opens Stripe pages. To use, run 'stripe open <shortcut>'.
open supports the following shortcuts:
shortcut url
-------- ---------
api => https://stripe.com/docs/api
apiref => https://stripe.com/docs/api
cliref => https://stripe.com/docs/cli
dashboard => https://dashboard.stripe.com/test
dashboard/apikeys => https://dashboard.stripe.com/test/apikeys
dashboard/atlas => https://dashboard.stripe.com/test/atlas
dashboard/balance => https://dashboard.stripe.com/test/balance/overview
dashboard/billing => https://dashboard.stripe.com/test/billing
dashboard/connect => https://dashboard.stripe.com/test/connect/overview
dashboard/connect/accounts => https://dashboard.stripe.com/test/connect/accounts/overview
dashboard/connect/collected-fees => https://dashboard.stripe.com/test/connect/application_fees
dashboard/connect/transfers => https://dashboard.stripe.com/test/connect/transfers
dashboard/coupons => https://dashboard.stripe.com/test/coupons
dashboard/customers => https://dashboard.stripe.com/test/customers
dashboard/developers => https://dashboard.stripe.com/test/developers
dashboard/disputes => https://dashboard.stripe.com/test/disputes
dashboard/events => https://dashboard.stripe.com/test/events
dashboard/invoices => https://dashboard.stripe.com/test/invoices
dashboard/logs => https://dashboard.stripe.com/test/logs
dashboard/orders => https://dashboard.stripe.com/test/orders
dashboard/orders/products => https://dashboard.stripe.com/test/orders/products
dashboard/payments => https://dashboard.stripe.com/test/payments
dashboard/payouts => https://dashboard.stripe.com/test/payouts
dashboard/radar => https://dashboard.stripe.com/test/radar
dashboard/radar/list => https://dashboard.stripe.com/test/radar/list
dashboard/radar/reviews => https://dashboard.stripe.com/test/radar/reviews
dashboard/radar/rules => https://dashboard.stripe.com/test/radar/rules
dashboard/settings => https://dashboard.stripe.com/test/settings
dashboard/subscriptions => https://dashboard.stripe.com/test/subscriptions
dashboard/subscriptions/products => https://dashboard.stripe.com/test/subscriptions/products
dashboard/tax-rates => https://dashboard.stripe.com/test/tax-rates
dashboard/terminal => https://dashboard.stripe.com/test/terminal
dashboard/terminal/hardware_orders => https://dashboard.stripe.com/test/terminal/hardware_orders
dashboard/terminal/locations => https://dashboard.stripe.com/test/terminal/locations
dashboard/topups => https://dashboard.stripe.com/test/topups
dashboard/transactions => https://dashboard.stripe.com/test/balance
dashboard/webhooks => https://dashboard.stripe.com/test/webhooks
docs => https://stripe.com/docs