# Naver Pay によるサブスクリプションを設定する Naver Pay でサブスクリプションを作成する方法をご紹介します。 支払い方法として [Naver Pay](https://docs.stripe.com/payments/naver-pay/accept-a-payment.md) を使用する*サブスクリプション* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)を設定します。 # SetupIntents API > This is a SetupIntents API for when api-integration is setupintents. View the full page at https://docs.stripe.com/billing/subscriptions/naver-pay?api-integration=setupintents. 2 回の API コールを使用してサブスクリプションを作成し、確定します。[最初の API コール](https://docs.stripe.com/billing/subscriptions/naver-pay.md#create-setup-intent)で顧客と商品の情報を [Subscriptions API](https://docs.stripe.com/api/subscriptions.md) に送信し、1 回のコールでサブスクリプションと PaymentIntent を作成します。レスポンスには PaymentIntent ID が含まれます。これを [Payment Intents API](https://docs.stripe.com/api/payment_intents.md) コールで使用して、支払いを確定する必要があります。 ## 商品と価格を作成する [ダッシュボード] [Products (商品)](https://docs.stripe.com/api/products.md) は、販売しているアイテムまたはサービスを表します。[Prices (価格)](https://docs.stripe.com/api/prices.md) は、商品の価格と請求頻度を定義します。これには、商品の価格、受け付ける通貨、および 1 回限りの支払いか継続支払いかが含まれます。商品と価格が数個のみの場合は、ダッシュボードでそれらを作成および管理します。 このガイドでは、例としてストックフォトサービスを使用し、100,000 KRW の月次サブスクリプションを顧客に請求します。これをモデル化するには、次のようにします。 1. [商品](https://dashboard.stripe.com/products?active=true)ページに移動し、**商品を作成**をクリックします。 1. 商品の**名前**を入力します。オプションで**説明**を追加して、商品の画像をアップロードできます。 1. **商品税コード**を選択します。[商品税コード](https://docs.stripe.com/tax/tax-codes.md)の詳細をご確認ください。 1. **継続**を選択します。次に、価格に**100,000**を入力し、通貨として**\**を選択します。 1. **価格に税金を含める**かどうかを選択します。[税金設定](https://dashboard.stripe.com/test/settings/tax)のデフォルト値を使用するか、値を手動で設定できます。この例では、**自動**を選択します。 1. **請求期間**で**月次**を選択します。 1. **その他の料金体系オプション**をクリックします。次に、この例の料金体系モデルとして**定額**を選択します。[定額料金](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate)とその他の[料金体系モデル](https://docs.stripe.com/products-prices/pricing-models.md)の詳細をご確認ください。 1. 将来的に特定の価格を整理、クエリ、更新するために、内部**価格の説明**と[検索キー](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) 追加します。 1. **次へ**をクリックします。次に、**商品を追加**をクリックします。 商品と価格を作成したら、価格 ID を記録しておき、後続のステップで使用できるようにします。ID は料金体系ページで `price_G0FvDp6vZvdwRZ` のように表示されます。 > この支払い方法を使用するには、価格を KRW に換算する必要があります。 ## SetupIntent を作成する [サーバー側] 今後の支払いに備えて顧客の支払い方法を保存するために、[SetupIntent (支払い方法設定インテント)](https://docs.stripe.com/api/setup_intents.md) を作成します。`SetupIntent` はこの設定プロセスのステップを追跡します。 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d confirm=true \ --data-urlencode "return_url=https://www.stripe.com" \ -d usage=off_session \ -d customer=cus_ODQluYFNl44ODI \ -d "payment_method_data[type]=naver_pay" \ -d "payment_method_types[]=naver_pay" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" ``` SetupIntent オブジェクトには `client_secret` が含まれています。これは、同意書の承認を得るために買い手を Naver Pay にリダイレクトする際に、クライアント側で Stripe.js に渡す必要がある一意のキーです。 ## サブスクリプションを作成する [サーバー側] 価格と顧客を含むサブスクリプションを作成します。`default_payment_method` パラメーターの値を SetupIntent から返された PaymentMethod ID に設定します。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "items[0][price]={{PRICE_ID}}" \ -d default_payment_method={{PAYMENT_METHOD_ID}} \ -d off_session=true ``` 事前設定されたデフォルトの支払い方法があるため、サブスクリプションを作成すると顧客に自動的に請求されます。支払いが成功すると、Stripe ダッシュボードのステータスが**有効**に変わります。すでに設定済みの価格によって以降の請求額が決まります。[無料のトライアル期間を利用してサブスクリプションを作成](https://docs.stripe.com/billing/subscriptions/naver-pay.md#trial-periods)する方法をご覧ください。 ## 支払いを確定する [サーバー側] サブスクリプションレスポンスの PaymentIntent ID を使用し、[PaymentIntents (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) で支払いを確定します。その後、PaymentIntent ID を URL パスに追加して、`payment_method_types` パラメーターの値を `naver_pay` に設定します。 ```curl curl https://api.stripe.com/v1/payment_intents/:id/confirm \ -u "<>:" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "payment_method_data[]=type" \ -d "payment_method_data[]=naver_pay" ``` PaymentIntent のレスポンスにはステータス `requires_action` が含まれます。これは、PaymentIntent を完了するには、顧客が Naver Pay から選択した支払い方法で支払いを完了する必要があることを示します。支払いが成功すると、サブスクリプションは有効になり、その支払い方法がデフォルトの支払い方法として保存されます。 # Subscriptions API > This is a Subscriptions API for when api-integration is subscription. View the full page at https://docs.stripe.com/billing/subscriptions/naver-pay?api-integration=subscription. 2 回の API コールを使用してサブスクリプションを作成し、確定します。[最初の API コール](https://docs.stripe.com/billing/subscriptions/naver-pay.md#pi-create-subscription)で顧客と商品の情報を [Subscriptions API](https://docs.stripe.com/api/subscriptions.md) に送信し、1 回のコールでサブスクリプションと PaymentIntent を作成します。レスポンスには PaymentIntent ID が含まれます。これを [Payment Intents API](https://docs.stripe.com/api/payment_intents.md) コールで使用して、[支払いを確定する](https://docs.stripe.com/billing/subscriptions/naver-pay.md#pi-confirm-payment)必要があります。 ## 商品と価格を作成する [ダッシュボード] [Products (商品)](https://docs.stripe.com/api/products.md) は、販売しているアイテムまたはサービスを表します。[Prices (価格)](https://docs.stripe.com/api/prices.md) は、商品の価格と請求頻度を定義します。これには、商品の価格、受け付ける通貨、および 1 回限りの支払いか継続支払いかが含まれます。商品と価格が数個のみの場合は、ダッシュボードでそれらを作成および管理します。 このガイドでは、例としてストックフォトサービスを使用し、100,000 KRW の月次サブスクリプションを顧客に請求します。これをモデル化するには、次のようにします。 1. [商品](https://dashboard.stripe.com/products?active=true)ページに移動し、**商品を作成**をクリックします。 1. 商品の**名前**を入力します。オプションで**説明**を追加して、商品の画像をアップロードできます。 1. **商品税コード**を選択します。[商品税コード](https://docs.stripe.com/tax/tax-codes.md)の詳細をご確認ください。 1. **継続**を選択します。次に、価格に**100,000**を入力し、通貨として**\**を選択します。 1. **価格に税金を含める**かどうかを選択します。[税金設定](https://dashboard.stripe.com/test/settings/tax)のデフォルト値を使用するか、値を手動で設定できます。この例では、**自動**を選択します。 1. **請求期間**で**月次**を選択します。 1. **その他の料金体系オプション**をクリックします。次に、この例の料金体系モデルとして**定額**を選択します。[定額料金](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate)とその他の[料金体系モデル](https://docs.stripe.com/products-prices/pricing-models.md)の詳細をご確認ください。 1. 将来的に特定の価格を整理、クエリ、更新するために、内部**価格の説明**と[検索キー](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) 追加します。 1. **次へ**をクリックします。次に、**商品を追加**をクリックします。 商品と価格を作成したら、価格 ID を記録しておき、後続のステップで使用できるようにします。ID は料金体系ページで `price_G0FvDp6vZvdwRZ` のように表示されます。 ## サブスクリプションを作成する [サーバー側] [payment_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-payment_behavior) パラメーターに `default_incomplete` の値を指定して、`incomplete` ステータスで価格と顧客を指定した [Subscription (サブスクリプション)](https://docs.stripe.com/api/subscriptions.md) を作成します。`payment_settings.save_default_payment_method=on_subscription` パラメーターを設定して、サブスクリプションが有効化されたときに支払い方法を保存します。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d payment_behavior=default_incomplete \ -d "items[0][price]={{PRICE_ID}}" \ -d "payment_settings[save_default_payment_method]=on_subscription" \ -d "expand[0]=latest_invoice.payments" \ -d "expand[1]=latest_invoice.confirmation_secret" ``` レスポンスには、*サブスクリプション* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)の最初の[請求書)](https://docs.stripe.com/api/invoices.md)が含まれます。これにはインボイスの支払いが含まれます。これには、Stripe がこのインボイスに対して生成したデフォルトの PaymentIntent と、PaymentIntent オブジェクト全体を渡す代わりにクライアント側で支払いプロセスを安全に完了するために使用できる Confirmation Secret が含まれます。支払いの確定に使用する必要がある PaymentIntent ID を `latest_invoice.payments` から取得します。`latest_invoice.confirmation_secret.client_secret` をフロントエンドに返して、支払いを完了します。[無料トライアル期間付きのサブスクリプションを作成](https://docs.stripe.com/billing/subscriptions/naver-pay.md#trial-periods)する方法をご覧ください。 ## 支払いを確定する [サーバー側] サブスクリプションレスポンスの PaymentIntent ID を使用し、[PaymentIntents (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) で支払いを確定します。その後、PaymentIntent ID を URL パスに追加して、`payment_method_types` パラメーターの値を `naver_pay` に設定します。 ```curl curl https://api.stripe.com/v1/payment_intents/:id/confirm \ -u "<>:" \ -d "payment_method_data[type]=naver_pay" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" \ -d "mandate_data[customer_acceptance][accepted_at]=1660000000" ``` PaymentIntent のレスポンスにはステータス `requires_action` が含まれます。これは、PaymentIntent を完了するにはユーザーが Naver Pay の認証を行う必要があることを示します。支払いが成功すると、サブスクリプションは有効になり、その支払い方法がデフォルトの支払い方法として保存されます。 # Stripe がオンラインで提供するページ > This is a Stripe がオンラインで提供するページ for when api-integration is checkout. View the full page at https://docs.stripe.com/billing/subscriptions/naver-pay?api-integration=checkout. [Checkout API](https://docs.stripe.com/api/checkout/sessions.md) を使用すると、構築済みの決済ページでサブスクリプションを作成して確認できます。 ## 商品と価格を作成する [ダッシュボード] [Products (商品)](https://docs.stripe.com/api/products.md) は、販売しているアイテムまたはサービスを表します。[Prices (価格)](https://docs.stripe.com/api/prices.md) は、商品の価格と請求頻度を定義します。これには、商品の価格、受け付ける通貨、および 1 回限りの支払いか継続支払いかが含まれます。商品と価格が数個のみの場合は、ダッシュボードでそれらを作成および管理します。 このガイドでは、例としてストックフォトサービスを使用し、100,000 KRW の月次サブスクリプションを顧客に請求します。これをモデル化するには、次のようにします。 1. [商品](https://dashboard.stripe.com/products?active=true)ページに移動し、**商品を作成**をクリックします。 1. 商品の**名前**を入力します。オプションで**説明**を追加して、商品の画像をアップロードできます。 1. **商品税コード**を選択します。[商品税コード](https://docs.stripe.com/tax/tax-codes.md)の詳細をご確認ください。 1. **継続**を選択します。次に、価格に**100,000**を入力し、通貨として**\**を選択します。 1. **価格に税金を含める**かどうかを選択します。[税金設定](https://dashboard.stripe.com/test/settings/tax)のデフォルト値を使用するか、値を手動で設定できます。この例では、**自動**を選択します。 1. **請求期間**で**月次**を選択します。 1. **その他の料金体系オプション**をクリックします。次に、この例の料金体系モデルとして**定額**を選択します。[定額料金](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate)とその他の[料金体系モデル](https://docs.stripe.com/products-prices/pricing-models.md)の詳細をご確認ください。 1. 将来的に特定の価格を整理、クエリ、更新するために、内部**価格の説明**と[検索キー](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) 追加します。 1. **次へ**をクリックします。次に、**商品を追加**をクリックします。 商品と価格を作成したら、価格 ID を記録しておき、後続のステップで使用できるようにします。ID は料金体系ページで `price_G0FvDp6vZvdwRZ` のように表示されます。 ## Checkout セッションを作成する [サーバー側] Stripe Checkout を使用した将来の支払いに Naver Pay アカウントを使用することを、顧客がお客様に許可する必要があります。これにより、Naver Pay による決済を受け付けることができます。サーバー側のエンドポイントを呼び出す決済ボタンをウェブサイトに追加して、[Checkout Session (セッション)](https://docs.stripe.com/api/checkout/sessions.md) を作成します。 ```html Checkout
``` `subscription` モードで Checkout セッションを作成して、必要な情報を収集します。Checkout セッションを作成したら、レスポンスで返される [URL](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-url) に顧客をリダイレクトします。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ --data-urlencode "success_url=https://example.com/success" \ -d "line_items[0][price]={{RECURRING_PRICE_ID}}" \ -d "line_items[0][quantity]=1" \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=naver_pay" \ -d mode=subscription ``` ## 実装内容をテストする [サーバー側] 支払い方法として Naver Pay を選択してから、「登録」をタップします。リダイレクトページで支払いを認証することで、支払いの成功ケースをテストできます。PaymentIntent のステータスが `requires_action` から `succeeded` に移行します。