# 連結アカウントに対する API コールを実行する API コールに適切な情報を追加して、連結アカウントに対してコールを実行する方法について説明します。 連結アカウントに対して API コールを実行できます。 - リクエストごとに、[Stripe-Account ヘッダー](https://docs.stripe.com/connect/authentication.md#stripe-account-header)と連結アカウントの ID を使用してサーバ側で実行 - 連結アカウントの ID を引数としてクライアントライブラリに渡して、クライアント側で実行 パフォーマンスと信頼性を高めるために、Stripe では API エンドポイントに対して[レート制限と割り当て](https://docs.stripe.com/rate-limits.md)を設定しています。 ## サーバー側で Stripe-Account ヘッダーを追加する 連結アカウントに対してサーバー側の API コールを実行するには、`acct_` で始まるアカウント ID を指定した `Stripe-Account` ヘッダーを使用します。プラットフォームの [API シークレットキー](https://docs.stripe.com/keys.md)と連結アカウントの [Account (アカウント)](https://docs.stripe.com/api/accounts.md) ID を使用する 4 つの例を以下に示します。 #### PaymentIntent を作成 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -H "Stripe-Account: {{CONNECTEDACCOUNT_ID}}" \ -d amount=1000 \ -d currency=usd ``` #### 残高の取得 ```curl curl https://api.stripe.com/v1/balance \ -u "<>:" \ -H "Stripe-Account: {{CONNECTEDACCOUNT_ID}}" ``` #### 商品のリスト化 ```curl curl -G https://api.stripe.com/v1/products \ -u "<>:" \ -H "Stripe-Account: {{CONNECTEDACCOUNT_ID}}" \ -d limit=5 ``` #### 顧客の削除 ```curl curl -X DELETE https://api.stripe.com/v1/customers/{{CUSTOMER_ID}} \ -u "<>:" \ -H "Stripe-Account: {{CONNECTEDACCOUNT_ID}}" ``` URL に Stripe アカウント ID を含む API リクエストのすべてで、`Stripe-Account` ヘッダーによる方法が必要になります。下記は、URL 内のユーザーの[アカウント](https://docs.stripe.com/api/accounts.md) ID を使用して[アカウントを取得](https://docs.stripe.com/api/accounts/retrieve.md)する方法を示す例です。 ```curl curl https://api.stripe.com/v1/accounts/{{CONNECTEDACCOUNT_ID}} \ -u "<>:" ``` Stripe のすべてのサーバ側ライブラリでは、この方法がリクエストごとにサポートされます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -H "Stripe-Account: {{CONNECTEDACCOUNT_ID}}" \ --data-urlencode "email=person@example.com" ``` ## クライアント側の申し込みに連結アカウントの ID を追加する クライアント側ライブラリでは、連結アカウントの ID がクライアントアプリケーションへの引数として設定されます。 #### HTML + JS 連結アカウントの ID をクライアント側で渡すための JavaScript コードは、プレーン JS および ESNext の場合と同じです。 ```javascript var stripe = Stripe('<>', { stripeAccount: '{{CONNECTED_ACCOUNT_ID}}', }); ``` #### React ```javascript import {loadStripe} from '@stripe/stripe-js'; // Make sure to call `loadStripe` outside of a component's render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>', { stripeAccount: '{{CONNECTED_ACCOUNT_ID}}', }); ``` #### iOS #### Swift ```swift import UIKit import StripePayments @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { StripeAPI.defaultPublishableKey = "<>" STPAPIClient.shared.stripeAccount = "{{CONNECTED_ACCOUNT_ID}}" return true } } ``` #### Android #### Kotlin ```kotlin import com.stripe.android.PaymentConfiguration class MyActivity: Activity() { private lateinit var stripe: Stripe override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) stripe = Stripe( this, PaymentConfiguration.getInstance(this).publishableKey, "{{CONNECTED_ACCOUNT_ID}}" ) } } ``` #### React Native ```javascript import {StripeProvider} from '@stripe/stripe-react-native'; function App() { return ( {/* Your app code here */} ); } ``` ## Connect 埋め込みコンポーネントの使用 Stripe の API と直接連携する代わりに、[連結する埋め込みコンポーネント](https://docs.stripe.com/connect/get-started-connect-embedded-components.md)を使用して、プラットフォームの UI で連結アカウントに Stripe 機能を提供できます。これらのコンポーネントでは、すべての API コールを内部で実装して処理するためのコードが少なくて済みます。 たとえば、連結アカウントに Payments データを表示するには、プラットフォームの UI に [決済コンポーネント](https://docs.stripe.com/Connect/supported-embedded-components/payments.md)を埋め込みます。これにより、[Charges](https://docs.stripe.com/API/charges.md)、[Payment Intents](https://docs.stripe.com/API/payment_intents.md)、[Refunds](https://docs.stripe.com/API/refunds.md)、および [Disputes](https://docs.stripe.com/API/disputes.md) API を個別に呼び出す必要がなくなります。 Note: The following is a preview/demo component that behaves differently than live mode usage with real connected accounts. The actual component has more functionality than what might appear in this demo component. For example, for connected accounts without Stripe dashboard access (custom accounts), no user authentication is required in production. 使用可能な埋め込みコンポーネントの一覧については、[対応コンポーネント](https://docs.stripe.com/connect/supported-embedded-components.md)をご覧ください。 ## See also - [支払いを作成する](https://docs.stripe.com/connect/charges.md) - [サブスクリプションを使用する](https://docs.stripe.com/connect/subscriptions.md) - [Connect 埋め込みコンポーネントを始める](https://docs.stripe.com/connect//get-started-connect-embedded-components.md)