# 請求クレジットの設定 請求クレジットを使用したプリペイド請求ソリューションの実装方法をご紹介します。 [Meter](https://docs.stripe.com/api/billing/meter.md) (メーター) と[請求クレジット](https://docs.stripe.com/billing/subscriptions/usage-based/billing-credits.md)を使用して、従量課金の商品やサービスの前払い時に、またはプロモーション商品として、顧客にクレジットを提供します。 ## はじめに 請求クレジットを使用する前に、[従量課金を設定](https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide.md)する必要があります。 1. [請求メーター](https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide.md#create-meter)を作成します。 1. [料金モデル](https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide.md#create-pricing-model)を作成し、メーターを追加します。 1. 顧客、商品、従量課金ベースの価格を含む[サブスクリプション](https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide.md#create-subscription)を作成します。 ## 顧客に請求クレジットを付与する Stripe ダッシュボードや API を使用して、顧客に対するクレジット付与を作成します。 請求クレジットは、[メーターの価格](https://docs.stripe.com/api/prices/object.md#price_object-recurring-meter)にリンクされている[サブスクリプション](https://docs.stripe.com/api/invoices/object.md#invoice_object-subscription)のラインアイテムにのみ適用されます。[Usage Records API](https://docs.stripe.com/api/usage_records.md) (使用状況の記録 API) はサポートされていません。 #### ダッシュボード 1. [顧客](https://dashboard.stripe.com/test/customers)ページで、顧客名を選択します。 1. 顧客ページの**クレジット付与**で、プラス (**+**) 記号をクリックします。 1. **新しいクレジット付与**ページで、次の操作を行います。 - **名前**には、クレジット付与の名前を入力します。 - **金額**には、クレジット付与の金額を指定します。 - (任意) **発効日**で、クレジットを付与する日付を指定します。 - (任意) **有効期限** で、クレジットの有効期限が切れる日付を指定します (ある場合)。 - (任意) **優先度** で、このクレジット付与の優先度を指定します。 - (任意) **利用資格** で、このクレジット付与が適用される従量制料金のリストを指定します。 - **付与を作成**をクリックします。 #### API ```curl curl https://api.stripe.com/v1/billing/credit_grants \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "name=Credit grant" \ -d "applicability_config[scope][price_type]=metered" \ -d category=paid \ -d "amount[type]=monetary" \ -d "amount[monetary][value]=1000" \ -d "amount[monetary][currency]=usd" ``` 特定の従量制課金アイテムにのみ適用されるクレジット付与を作成するには、[billable_items](https://docs.stripe.com/api/billing/credit-grant/create.md?api-version=preview#create_billing_credit_grant-applicability_config-scope-billable_items) 配列に ID を渡します。 ```curl curl https://api.stripe.com/v1/billing/credit_grants \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "name=Credit grant" \ -d "applicability_config[scope][billable_items][0][id]={{BILLABLE_ITEM_ID}}" \ -d category=paid \ -d "amount[type]=monetary" \ -d "amount[monetary][value]=1000" \ -d "amount[monetary][currency]=usd" ``` ## 請求クレジットを請求書に適用する 請求書が確定すると、Stripe は該当するすべての請求クレジットを自動的に適用します。クレジット付与の利用可能な残高は、請求書に適用された請求クレジットの金額に基づいて更新されます。 請求書に適用された請求クレジットの金額は、Stripe ダッシュボードで確認できます。 1. [顧客](https://dashboard.stripe.com/test/customers)ページで、顧客名を選択します。 1. 顧客ページの**請求書**で、請求書を選択します。 1. 請求書ページの**小計**で、**クレジット付与適用済み**の行を見つけます。 ## 利用可能な請求クレジット残高を取得する Stripe ダッシュボードまたは API を使用して、顧客の利用可能な請求クレジット残高を確認します。API を使用する場合は、[Credit Balance Summary](https://docs.stripe.com/api/billing/credit-balance-summary/retrieve.md) (クレジット残高サマリー) エンドポイントを取得します。 #### ダッシュボード 1. [顧客](https://dashboard.stripe.com/test/customers)ページで、顧客名を選択します。 1. 顧客ページの**クレジット付与**で、請求書に適用できるクレジット付与のリストを見つけます。クレジット付与の [available_balance](https://docs.stripe.com/api/billing/credit-balance-summary/object.md#billing_credit_balance_summary_object-balances-available_balance) は**利用可能**列で確認できます。 #### API ```curl curl -G https://api.stripe.com/v1/billing/credit_balance_summary \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "filter[type]=applicability_scope" \ -d "filter[applicability_scope][price_type]=metered" ``` ## クレジット付与の対象となる取引を一覧表示する Stripe ダッシュボードまたは API を使用して、特定のクレジット付与または顧客の取引を確認します。API を使用する場合は、[Credit Balance Transaction](https://docs.stripe.com/api/billing/credit-balance-transaction/list.md) (クレジット取引残高) エンドポイントを呼び出します。 #### ダッシュボード 1. [顧客](https://dashboard.stripe.com/test/customers)ページで、顧客名を選択します。 1. 顧客ページの**クレジット付与**で、クレジット付与を選択します。 1. クレジット残高取引の詳細を表示します。 #### API ```curl curl -G https://api.stripe.com/v1/billing/credit_balance_transactions \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d credit_grant={{CREDIT_GRANT_ID}} ``` ## Optional: クレジット付与に資金を追加する Stripe ダッシュボードや API を使用して 1 回限りの[請求書](https://docs.stripe.com/invoicing.md)を作成し、顧客から支払いを回収します。API を使用する場合は `invoice.paid` [Webhook](https://docs.stripe.com/webhooks.md) をリッスンし、顧客に請求クレジットを付与します。 #### ダッシュボード 1. [顧客](https://dashboard.stripe.com/test/customers)ページで、顧客名を選択します。 1. 顧客ページで、**請求書を作成**をクリックします。 1. 手順に従って[請求書を作成](https://docs.stripe.com/invoicing/dashboard.md)します。 #### API ```curl curl https://api.stripe.com/v1/invoices \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "description=credit purchase" \ -d collection_method=charge_automatically ``` ```curl curl https://api.stripe.com/v1/invoiceitems \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "description=billing credits purchase" \ -d unit_amount_decimal=1000 \ -d currency=usd \ -d invoice={{INVOICE_ID}} ``` ```curl curl https://api.stripe.com/v1/invoices/{{INVOICE_ID}}/finalize \ -u "<>:" \ -d auto_advance=true ``` ## See also - [クレジット申請資格](https://docs.stripe.com/billing/subscriptions/usage-based/billing-credits.md#credit-grant-eligibility) - [従量課金](https://docs.stripe.com/billing/subscriptions/usage-based.md)