# カーボン除去の支払いを受け付ける 顧客が支払いシステムで Climate API を使用して炭素除去を購入できるようにします。 # Climate の注文のクイックスタート 顧客が支払いシステムで [Climate Orders (Climate の注文) API](https://docs.stripe.com/api/climate/order.md) を使用して炭素除去を購入できるようにします。 ### Stripe Node ライブラリーをインストールする パッケージをインストールし、それをコードにインポートします。また、まったくゼロから開始していて package.json ファイルが必要な場合には、コードエディターのダウンロードリンクを使用してプロジェクトファイルをダウンロードします。 #### npm ライブラリーをインストールします。 ```bash npm install --save stripe ``` #### GitHub または、stripe-node ライブラリーのソースコードを直接 [GitHub から](https://github.com/stripe/stripe-node)ダウンロードします。 ### Stripe Ruby ライブラリーをインストールする Stripe ruby gem をインストールし、require を指定してコードに読み込みます。または、まったくゼロから開始していて Gemfile が必要な場合には、コードエディターのリンクを使用してプロジェクトファイルをダウンロードします。 #### Terminal gem をインストールします。 ```bash gem install stripe ``` #### Bundler この行を Gemfile に追加します。 ```bash gem 'stripe' ``` #### GitHub または、stripe-ruby gem のソースコードを直接 [GitHub から](https://github.com/stripe/stripe-ruby)ダウンロードします。 ### Stripe Java ライブラリーをインストールする ビルドに依存関係を追加し、ライブラリーをインポートします。まったくゼロから開始していてサンプルの pom.xml ファイル (Maven 用) が必要な場合は、コードエディターのリンクを使用してプロジェクトファイルをダウンロードします。 #### Maven POM に以下の依存関係を追加し、{VERSION} を使用するバージョン番号に置き換えます。 ```bash \ncom.stripe\nstripe-java\n{VERSION}\n ``` #### Gradle build.gradle ファイルに依存関係を追加し、{VERSION} を使用するバージョン番号に置き換えます。 ```bash implementation "com.stripe:stripe-java:{VERSION}" ``` #### GitHub JAR を直接 [GitHub から](https://github.com/stripe/stripe-java/releases/latest)ダウンロードします。 ### Stripe Python パッケージをインストールする Stripe パッケージをインストールし、コードにインポートします。まったくゼロから開始していて requirements.txt が必要な場合には、コードエディターのリンクを使用してプロジェクトファイルをダウンロードします。 #### pip pip を使用してパッケージをインストールします。 ```bash pip3 install stripe ``` #### GitHub stripe-python ライブラリのソースコードを [GitHub から](https://github.com/stripe/stripe-python)直接ダウンロードします。 ### Stripe PHP ライブラリーをインストールする Composer を使用してライブラリーをインストールし、シークレット API キーで初期化します。まったくゼロから開始していて composer.json ファイルが必要な場合には、コードエディターのリンクを使用してファイルをダウンロードします。 #### Composer ライブラリーをインストールします。 ```bash composer require stripe/stripe-php ``` #### GitHub または、stripe-php ライブラリーのソースコードを直接 [GitHub から](https://github.com/stripe/stripe-php)ダウンロードします。 ### サーバーを設定する ビルドに依存関係を追加し、ライブラリーをインポートします。まったくゼロから開始していて go.mod ファイルが必要な場合には、コードエディターのリンクを使用してプロジェクトファイルをダウンロードします。 #### Go 必ず Go モジュールを使用してを初期化してください。 ```bash go get -u github.com/stripe/stripe-go/v85 ``` #### GitHub または、stripe-go モジュールのソースコードを直接 [GitHub から](https://github.com/stripe/stripe-go)ダウンロードします。 ### Stripe.net ライブラリーをインストールする .NET または NuGet でパッケージをインストールします。まったくゼロから開始する場合には、設定済みの .csproj ファイルが含まれるファイルをダウンロードします。 #### dotnet ライブラリーをインストールします。 ```bash dotnet add package Stripe.net ``` #### NuGet ライブラリーをインストールします。 ```bash Install-Package Stripe.net ``` #### GitHub または、Stripe.net ライブラリーのソースコードを直接 [GitHub から](https://github.com/stripe/stripe-dotnet)ダウンロードします。 ### Stripe ライブラリーをインストールする パッケージをインストールし、コードにインポートします。まったくゼロから開始していて `package.json` が必要な場合には、コードエディターのリンクを使用してプロジェクトファイルをダウンロードします。 ライブラリーをインストールします。 ```bash npm install --save stripe @stripe/stripe-js next ``` ### リクエストを処理するエンドポイントを作成する [Checkout セッション](https://docs.stripe.com/api/checkout/sessions.md)を作成するエンドポイントをサーバーに追加します。Checkout セッションは、支払いページで顧客に表示される内容を制御します。 ### 注文金額を計算する 最新の価格を取得して、注文金額の合計を計算するには、[Climate Products (Climate 製品)](https://docs.stripe.com/api/climate/product.md) を使用します。 ### 顧客を作成 データベースで [Customer (顧客)](https://docs.stripe.com/api/customers.md) を検索するか、請求先を表す新しい `Customer` を作成します。 ### 空の請求書を作成する 必ず `metadata` で [product.id](https://docs.stripe.com/api/climate/product/object.md#climate_product_object-id) を渡し、[collection_method](https://docs.stripe.com/api/invoices/object.md#invoice_object-collection_method) 属性を `send_invoice` に設定します。Stripe が請求書を期日経過としてマークできるようにするには、[days_until_due](https://docs.stripe.com/api/invoices/create.md#create_invoice-days_until_due) パラメーターを追加する必要があります。請求書を送ると、Stripe は請求書および支払い手順をメールで顧客に送信します。請求書のカスタマイズオプションについて、詳細は [Invoices (請求書)](https://docs.stripe.com/api/invoices.md) をご覧ください。 ### 請求書アイテムを作成する `customer.id`、`invoice.id`、および注文の `amount_total` と `currency` を渡して請求書アイテムを作成します。 ### 請求書を送信する 顧客に関連付けられたメールアドレスに請求書を送信し、成功ページにリダイレクトします。 請求書が送信されるとすぐに、Stripe は請求書を確定します。多くの管轄区域では、確定済みの請求書は法的文書と見なされ、一部のフィールドは変更できなくなります。支払い済みの請求書を送信する場合、メールに支払いの参照情報は記載されません。 確定された請求書では、[PDF](https://docs.stripe.com/api/invoices/object.md#invoice_object-invoice_pdf) をダウンロードして送るか、関連付けられた[オンライン請求書ページ](https://docs.stripe.com/invoicing/hosted-invoice-page.md)の[リンクを作成](https://docs.stripe.com/api/invoices/object.md#invoice_object-hosted_invoice_url)できます。 ### Checkout セッションを作成する `Checkout Session` を作成して購入者から支払いを回収します。 ### Checkout セッションを設定する 必ず `metadata` で [product.id](https://docs.stripe.com/api/climate/product/object.md#climate_product_object-id) を渡してください。Checkout セッションのカスタマイズオプションについて、詳細は [Checkout](https://docs.stripe.com/api/checkout/sessions.md) をご覧ください。 ### 成功時の URL とキャンセル時の URL を指定する 成功ページとキャンセルページの URL を指定します。Stripe が購入者をリダイレクトできるように、それらのページが一般のアクセスが可能な公開ページであることを確認してください。同じ URL で成功とキャンセルの両方のステータスを処理することもできます。 ### Checkout にリダイレクトする セッションの作成後に、レスポンスで返された Checkout ページの URL に購入者をリダイレクトします。 ### トップアップを作成する この結果、アカウントに関連付けられている銀行口座を使用して注文に使用される残高が補充され、[product.id](https://docs.stripe.com/api/climate/product/object.md#climate_product_object-id) が `metadata` に渡されます。ご使用の銀行口座で Stripe からの引き落としが可能で、注文に充当できる十分な残高があることを確認してください。 ### 炭素除去の注文を作成する [Climate Order (Climate の注文)](https://docs.stripe.com/api/climate/order.md) は炭素除去をリザーブし、達成されるまで追跡します。合計額は [Stripe 残高](https://docs.stripe.com/api/balance.md)から差し引かれます。 > 本番環境のコードでは、Climate Order の作成をオフラインプロセスに移動して、重複するイベントを処理します。詳細については、[Webhook 使用のベストプラクティス](https://docs.stripe.com/webhooks.md#best-practices) をご覧ください。 ### 炭素除去の注文を作成する ユーザーが請求書に対して支払うときに、[Climate Order (Climate の注文)](https://docs.stripe.com/api/climate/order.md) を作成します。合計額は [Stripe 残高](https://docs.stripe.com/api/balance.md) から差し引かれます。 > 本番環境のコードでは、Climate Order の作成をオフラインプロセスに移動して、重複するイベントを処理します。詳細については、[Webhook 使用のベストプラクティス](https://docs.stripe.com/webhooks.md#best-practices) をご覧ください。 ### 炭素除去の注文を作成する ユーザーが Checkout で支払いを完了したら、[Climate Order (Climate の注文)](https://docs.stripe.com/api/climate/order.md) を作成します。合計額は [Stripe 残高](https://docs.stripe.com/api/balance.md) から差し引かれます。 > 本番環境のコードでは、Climate Order の作成をオフラインプロセスに移動して、重複するイベントを処理します。詳細については、[Webhook 使用のベストプラクティス](https://docs.stripe.com/webhooks.md#best-practices) をご覧ください。 ### 炭素除去の注文を作成する トップアップが成功したら、[Climate Order (Climate の注文)](https://docs.stripe.com/api/climate/order.md) を作成します。合計額は [Stripe 残高](https://docs.stripe.com/api/balance.md) から差し引かれます。 > 本番環境のコードでは、Climate Order の作成をオフラインプロセスに移動して、重複するイベントを処理します。詳細については、[Webhook 使用のベストプラクティス](https://docs.stripe.com/webhooks.md#best-practices) をご覧ください。 ### 注文のプレビューページを追加する 販売する炭素除去のプレビューを表示するページを追加し、顧客からメールアドレスを収集します。ここにマーケティングアセットを表示し、予定達成日と適用される製品保証を明確に説明します。 ### 注文のプレビューページを追加する 販売中の炭素除去のプレビューページを追加します。ここにマーケティングアセットを表示し、商品の予定達成日と適用される保証を明確に説明します。 ### 注文ボタンを追加する 注文を行って請求書を送信するボタンを追加します。 ### 注文ボタンを追加する 注文を行うボタンを追加します。購入者がこのボタンをクリックすると、Stripe がオンラインで提供する支払いフォームにリダイレクトされます。 ### Checkout からのリダイレクトを処理する リダイレクトされて自社のページに戻ったときに顧客にメッセージを表示します。 ### 注文ページを追加する アプリケーションに注文を行うページを作成します。 ### アセットキットをダウンロードする [アセットキット](https://stripe-images.s3.amazonaws.com/content-store/climate/APIAssetKit.zip)を使用して、炭素除去プロダクトを顧客に紹介します。 ### 環境変数を設定する 公開可能キーとシークレットキーを `.env` ファイルに追加します。これらのキーは Next.js によって自動的に[環境変数](https://nextjs.org/docs/basic-features/environment-variables)としてアプリケーションに読み込まれます。Webhook シークレットも含めます。このシークレットは[ダッシュボード](https://dashboard.stripe.com/webhooks)または [Stripe CLI](https://docs.stripe.com/stripe-cli.md) で作成できます。 ### アプリケーションを実行する `npm run dev` でアプリを起動し、 に移動します。 ### 試してみる **購入**をクリックすると、Stripe の決済ページにリダイレクトされます。いずれかのテストカードを使用して支払いをシミュレーションします。 | Scenario | Card Number | | ----------------------------------- | ---------------- | | Payment succeeds | 4242424242424242 | | Payment requires 3DS authentication | 4000002500003155 | | Payment is declined | 4000000000009995 | ### 試してみる **注文する**をクリックすると、テスト請求書が送信されます。いずれかのテストカードを使用して支払いをシミュレーションします。 | Scenario | Card Number | | ----------------------------------- | ---------------- | | Payment succeeds | 4242424242424242 | | Payment requires 3DS authentication | 4000002500003155 | | Payment is declined | 4000000000009995 | ### 炭素除去の注文を確認する [Stripe ダッシュボード](https://dashboard.stripe.com/climate/orders)で `Climate Order` を表示し、注文が正常に作成されたことを確認します。 // Check to see if this is a redirect back from the server const query = new URLSearchParams(window.location.search); if (query.get("success")) { setMessage("Order placed!"); } if (query.get("canceled")) { setMessage("Order canceled."); }

Frontier's 2027 offtake portfolio

$550.00/ton

Frontier's 2027 offtake portfolio

$550.00/ton
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); export default async function handler(req, res) { const currency = 'usd'; const {data: products} = await stripe.climate.products.list(); // Select which carbon removal product you want to order const climateProduct = products.find((p) => p.id === 'climsku_frontier_offtake_portfolio_2027'); // Calculate the total amount based on the number of tons const unit_amount = 1.0 * climateProduct.current_prices_per_metric_ton[currency].amount_total; // Look up a product in your database or create a new one const product = await stripe.products.create({ name: climateProduct.name, }); // Create Checkout Sessions from body params. const session = await stripe.checkout.sessions.create({ line_items: [ { price_data: { unit_amount, currency, product: product.id, }, quantity: 1, }, ], mode: 'payment', metadata: { climate_product: climateProduct.id }, success_url: `${req.headers.origin}?success=true`, }); res.redirect(303, session.url); const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); export default async function handler(req, res) { const currency = 'usd'; const {data: products} = await stripe.climate.products.list(); // Select which carbon removal product you want to order const climateProduct = products.find((p) => p.id === 'climsku_frontier_offtake_portfolio_2027'); // Calculate the total amount based on the number of tons const unit_amount = 1.0 * climateProduct.current_prices_per_metric_ton[currency].amount_total; // Look up a customer in your database or create a new one const customer = await stripe.customers.create({email: 'TODO@example.com'}); // Create an Invoice const invoice = await stripe.invoices.create({ customer: customer.id, collection_method: 'send_invoice', days_until_due: 1, metadata: { climate_product: climateProduct.id }, }); // Look up a product in your database or create a new one const product = await stripe.products.create({ name: climateProduct.name, }); // Create an Invoice Item with the Price, and Customer you want to charge await stripe.invoiceItems.create({ customer: customer.id, invoice: invoice.id, price_data: { unit_amount, currency, product: product.id, }, }); // Send the Invoice await stripe.invoices.sendInvoice(invoice.id); res.redirect(303, req.headers.origin + '?success=true'); const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); export default async function handler(req, res) { const currency = 'usd'; const {data: products} = await stripe.climate.products.list(); // Select which product you want to order const product = products.find((product) => product.id === 'climsku_frontier_offtake_portfolio_2027'); // Calculate the total amount based on the number of tons const amount = 1.0 * product.current_prices_per_metric_ton[currency].amount_total; // Create a top-up await stripe.topups.create({ amount, currency, metadata: { climate_product: product.id }, }); res.redirect(303, req.headers.origin + '?success=true'); const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); export default async function handler(req, res) { const order = await stripe.climate.orders.create({ metric_tons: '1.0', product: 'climsku_frontier_offtake_portfolio_2027', }); res.redirect(303, req.headers.origin + '?success=true'); case 'invoice.paid': { const invoice = event.data.object; if (invoice.metadata.climate_product) { await stripe.climate.orders.create({ amount: invoice.total, currency: invoice.currency, product: invoice.metadata.climate_product, }); } break; } case 'checkout.session.completed': { const session = event.data.object; if (session.metadata.climate_product) { await stripe.climate.orders.create({ amount: session.amount_total, currency: session.currency, product: session.metadata.climate_product, }); } break; } case 'topup.succeeded': { const topup = event.data.object; if (topup.metadata.climate_product) { await stripe.climate.orders.create({ amount: topup.amount, currency: topup.currency, product: topup.metadata.climate_product, }); } break; } \# https://dashboard.stripe.com/apikeys STRIPE_SECRET_KEY=<> \# Set this environment variable to support webhooks — https://stripe.com/docs/webhooks#verify-events STRIPE_WEBHOOK_SECRET=whsec_12345