メインコンテンツへスキップ
セッションの有効性: チェックアウトセッションはデフォルトで24時間有効です。リクエストにconfirm=trueを渡すと、セッションは15分間のみ有効になります。

前提条件

1

Dodo Paymentsアカウント

APIアクセスを持つアクティブなDodo Paymentsマーチャントアカウントが必要です。
2

API資格情報

Dodo PaymentsダッシュボードからAPI資格情報を生成します:
3

製品の設定

チェックアウトセッションを実装する前に、Dodo Paymentsダッシュボードで製品を作成します。

最初のチェックアウトセッションを作成する

import DodoPayments from 'dodopayments';

// Initialize the Dodo Payments client
const client = new DodoPayments({
  bearerToken: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode', // defaults to 'live_mode'
});

async function createCheckoutSession() {
  try {
    const session = await client.checkoutSessions.create({
      // Products to sell - use IDs from your Dodo Payments dashboard
      product_cart: [
        {
          product_id: 'prod_123', // Replace with your actual product ID
          quantity: 1
        }
      ],
      
      // Pre-fill customer information to reduce friction
      customer: {
        email: '[email protected]',
        name: 'John Doe',
        phone_number: '+1234567890'
      },
      
      // Billing address for tax calculation and compliance
      billing_address: {
        street: '123 Main St',
        city: 'San Francisco',
        state: 'CA',
        country: 'US', // Required: ISO 3166-1 alpha-2 country code
        zipcode: '94102'
      },
      
      // Where to redirect after successful payment
      return_url: 'https://yoursite.com/checkout/success',
      
      // Custom data for your internal tracking
      metadata: {
        order_id: 'order_123',
        source: 'web_app'
      }
    });

    // Redirect your customer to this URL to complete payment
    console.log('Checkout URL:', session.checkout_url);
    console.log('Session ID:', session.session_id);
    
    return session;
    
  } catch (error) {
    console.error('Failed to create checkout session:', error);
    throw error;
  }
}

// Example usage in an Express.js route
app.post('/create-checkout', async (req, res) => {
  try {
    const session = await createCheckoutSession();
    res.json({ checkout_url: session.checkout_url });
  } catch (error) {
    res.status(500).json({ error: 'Failed to create checkout session' });
  }
});

APIレスポンス

上記のすべてのメソッドは同じレスポンス構造を返します:
{
  "session_id": "cks_Gi6KGJ2zFJo9rq9Ukifwa",
  "checkout_url": "https://test.checkout.dodopayments.com/session/cks_Gi6KGJ2zFJo9rq9Ukifwa"
}
1

チェックアウトURLを取得

APIレスポンスからcheckout_urlを抽出します。
2

顧客をリダイレクト

顧客をチェックアウトURLに誘導して購入を完了させます。
// Redirect immediately
window.location.href = session.checkout_url;

// Or open in new window
window.open(session.checkout_url, '_blank');
3

戻りを処理

支払い後、顧客は支払い状況の追加クエリパラメータを持つreturn_urlにリダイレクトされます。

リクエストボディ

必須フィールド

すべてのチェックアウトセッションに必要な必須フィールド

オプションフィールド

チェックアウト体験をカスタマイズするための追加設定

必須フィールド

product_cart
array
required
チェックアウトセッションに含める製品の配列。各製品は、Dodo Paymentsダッシュボードからの有効なproduct_idを持っている必要があります。
重要: 複数の製品カートには、ワンタイム支払い製品のみを含めることができます。同じチェックアウトセッションでサブスクリプション製品とワンタイム製品を混在させることはできません。
製品IDを見つける: Dodo Paymentsダッシュボードの製品→詳細を表示で製品IDを見つけるか、製品リストAPIを使用してください。

オプションフィールド

これらのフィールドを設定して、チェックアウト体験をカスタマイズし、支払いフローにビジネスロジックを追加します。
customer
object
顧客情報。既存の顧客をIDで添付するか、チェックアウト中に新しい顧客レコードを作成できます。
IDを使用してチェックアウトセッションに既存の顧客を添付します。
billing_address
object
正確な税計算、詐欺防止、規制遵守のための請求先住所情報です。
confirmtrueに設定されている場合、すべての請求先住所フィールドはセッション作成の成功に必要です。
allowed_payment_method_types
array
チェックアウト中に顧客が利用できる支払い方法を制御します。これにより、特定の市場やビジネス要件に最適化できます。利用可能なオプション: creditdebitupi_collectupi_intentapple_paygoogle_payamazon_payklarnaaffirmafterpay_clearpaysepaachcashappmultibancobancontact_cardepsidealprzelewy24paypal
重要: 常にcreditdebitをフォールバックオプションとして含めて、好ましい支払い方法が利用できない場合のチェックアウト失敗を防ぎます。
:
["apple_pay", "google_pay", "credit", "debit"]
billing_currency
string
デフォルトの通貨選択を固定の請求通貨で上書きします。ISO 4217通貨コードを使用します。サポートされている通貨: USDEURGBPCADAUDINR、その他: "USD"(米ドル)、"EUR"(ユーロ)
このフィールドは、アダプティブプライシングが有効な場合にのみ効果があります。アダプティブプライシングが無効な場合、製品のデフォルト通貨が使用されます。
show_saved_payment_methods
boolean
default:"false"
リピート顧客のために以前に保存された支払い方法を表示し、チェックアウトのスピードとユーザー体験を向上させます。
return_url
string
成功した支払いまたはキャンセル後に顧客をリダイレクトするURLです。
confirm
boolean
default:"false"
trueの場合、すべてのセッション詳細を即座に確定します。必要なデータが欠けている場合、APIはエラーをスローします。
discount_code
string
チェックアウトセッションに割引コードを適用します。
metadata
object
セッションに関する追加情報を保存するためのカスタムキーと値のペアです。
force_3ds
boolean
このセッションのマーチャントデフォルトの3DS動作を上書きします。
minimal_address
boolean
default:"false"
最小限の住所収集モードを有効にします。有効にすると、チェックアウトでは次の情報のみを収集します:
  • : 税金の決定に常に必要
  • 郵便番号: 売上税、VAT、またはGST計算に必要な地域のみ
これにより、不要なフォームフィールドを排除することでチェックアウトの摩擦が大幅に軽減されます。
チェックアウトの完了を早めるために最小限の住所を有効にしてください。完全な住所収集は、完全な請求詳細が必要なビジネスのために引き続き利用可能です。
customization
object
チェックアウトインターフェースの外観と動作をカスタマイズします。
feature_flags
object
チェックアウトセッションの特定の機能と動作を設定します。
subscription_data
object
サブスクリプション製品を含むチェックアウトセッションの追加設定です。

使用例

さまざまなビジネスシナリオに対する異なるチェックアウトセッション設定を示す10の包括的な例を以下に示します:

1. シンプルな単一製品チェックアウト

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_ebook_guide',
      quantity: 1
    }
  ],
  customer: {
    email: '[email protected]',
    name: 'John Doe'
  },
  return_url: 'https://yoursite.com/success'
});

2. マルチ製品カート

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_laptop',
      quantity: 1
    },
    {
      product_id: 'prod_mouse',
      quantity: 2
    },
    {
      product_id: 'prod_warranty',
      quantity: 1
    }
  ],
  customer: {
    email: '[email protected]',
    name: 'John Doe',
    phone_number: '+1234567890'
  },
  billing_address: {
    street: '123 Tech Street',
    city: 'San Francisco',
    state: 'CA',
    country: 'US',
    zipcode: '94102'
  },
  return_url: 'https://electronics-store.com/order-confirmation'
});

3. 試用期間付きサブスクリプション

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_monthly_plan',
      quantity: 1
    }
  ],
  subscription_data: {
    trial_period_days: 14
  },
  customer: {
    email: '[email protected]',
    name: 'Jane Smith'
  },
  return_url: 'https://saas-app.com/onboarding',
  metadata: {
    plan_type: 'professional',
    referral_source: 'google_ads'
  }
});

4. 事前確認済みチェックアウト

confirmtrueに設定されている場合、顧客は確認ステップをバイパスして直接チェックアウトページに移動します。
const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_premium_course',
      quantity: 1
    }
  ],
  customer: {
    email: '[email protected]',
    name: 'Alex Johnson',
    phone_number: '+1555123456'
  },
  billing_address: {
    street: '456 University Ave',
    city: 'Boston',
    state: 'MA',
    country: 'US',
    zipcode: '02134'
  },
  confirm: true,
  return_url: 'https://learning-platform.com/course-access',
  metadata: {
    course_category: 'programming',
    enrollment_date: '2024-01-15'
  }
});

5. 通貨オーバーライド付きチェックアウト

billing_currencyオーバーライドは、アカウント設定でアダプティブ通貨が有効な場合にのみ効果があります。アダプティブ通貨が無効な場合、このパラメータは効果がありません。
const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_consulting_service',
      quantity: 1
    }
  ],
  customer: {
    email: '[email protected]',
    name: 'Oliver Williams'
  },
  billing_address: {
    street: '789 Business Park',
    city: 'London',
    state: 'England',
    country: 'GB',
    zipcode: 'SW1A 1AA'
  },
  billing_currency: 'GBP',
  feature_flags: {
    allow_currency_selection: true,
    allow_tax_id: true
  },
  return_url: 'https://consulting-firm.com/service-confirmation'
});

6. リピート顧客のための保存された支払い方法

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_monthly_subscription',
      quantity: 1
    }
  ],
  customer: {
    email: '[email protected]',
    name: 'Robert Johnson',
    phone_number: '+1555987654'
  },
  show_saved_payment_methods: true,
  feature_flags: {
    allow_phone_number_collection: true,
    always_create_new_customer: false
  },
  return_url: 'https://subscription-service.com/welcome-back',
  metadata: {
    customer_tier: 'premium',
    account_age: 'returning'
  }
});

7. 税ID収集を伴うB2Bチェックアウト

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_enterprise_license',
      quantity: 5
    }
  ],
  customer: {
    email: '[email protected]',
    name: 'Sarah Davis',
    phone_number: '+1800555000'
  },
  billing_address: {
    street: '1000 Corporate Blvd',
    city: 'New York',
    state: 'NY',
    country: 'US',
    zipcode: '10001'
  },
  feature_flags: {
    allow_tax_id: true,
    allow_phone_number_collection: true,
    always_create_new_customer: false
  },
  return_url: 'https://enterprise-software.com/license-delivery',
  metadata: {
    customer_type: 'enterprise',
    contract_id: 'ENT-2024-001',
    sales_rep: '[email protected]'
  }
});

8. 割引コード付きダークテーマチェックアウト

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_gaming_chair',
      quantity: 1
    }
  ],
  discount_code: 'BLACKFRIDAY2024',
  customization: {
    theme: 'dark',
    show_order_details: true,
    show_on_demand_tag: false
  },
  feature_flags: {
    allow_discount_code: true
  },
  customer: {
    email: '[email protected]',
    name: 'Mike Chen'
  },
  return_url: 'https://gaming-store.com/order-complete'
});

9. 地域の支払い方法(インドのUPI)

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_online_course_hindi',
      quantity: 1
    }
  ],
  allowed_payment_method_types: [
    'upi_collect',
    'upi_intent',
    'credit',
    'debit'
  ],
  customer: {
    email: '[email protected]',
    name: 'Priya Sharma',
    phone_number: '+919876543210'
  },
  billing_address: {
    street: 'MG Road',
    city: 'Bangalore',
    state: 'Karnataka',
    country: 'IN',
    zipcode: '560001'
  },
  billing_currency: 'INR',
  return_url: 'https://education-platform.in/course-access',
  metadata: {
    region: 'south_india',
    language: 'hindi'
  }
});

10. BNPL(今すぐ購入、後で支払い)チェックアウト

const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_luxury_watch',
      quantity: 1
    }
  ],
  allowed_payment_method_types: [
    'klarna',
    'affirm',
    'afterpay_clearpay',
    'credit',
    'debit'
  ],
  customer: {
    email: '[email protected]',
    name: 'Emma Thompson',
    phone_number: '+1234567890'
  },
  billing_address: {
    street: '555 Fashion Ave',
    city: 'Los Angeles',
    state: 'CA',
    country: 'US',
    zipcode: '90210'
  },
  feature_flags: {
    allow_phone_number_collection: true
  },
  return_url: 'https://luxury-store.com/purchase-confirmation',
  metadata: {
    product_category: 'luxury',
    price_range: 'high_value'
  }
});

ダイナミックリンクからチェックアウトセッションへの移行

主な違い

以前は、ダイナミックリンクで支払いリンクを作成する際に、顧客の完全な請求先住所を提供する必要がありました。 チェックアウトセッションでは、これがもはや必要ありません。お持ちの情報をそのまま渡すだけで、残りは私たちが処理します。例えば:
  • 顧客の請求国しか知らない場合は、それを提供するだけです。
  • チェックアウトフローは、顧客を支払いページに移動させる前に不足している詳細を自動的に収集します。
  • 一方、必要な情報がすべて揃っていて、支払いページに直接スキップしたい場合は、完全なデータセットを渡し、リクエストボディにconfirm=trueを含めることができます。

移行プロセス

ダイナミックリンクからチェックアウトセッションへの移行は簡単です:
1

統合を更新

新しいAPIまたはSDKメソッドを使用するように統合を更新します。
2

リクエストペイロードを調整

チェックアウトセッション形式に従ってリクエストペイロードを調整します。
3

それだけです!

はい。追加の処理や特別な移行手順は必要ありません。