# 顧客の電話番号を収集する

顧客が支払いを行うときに、配送や請求処理のために電話番号を収集します。

# ホスト型ページ

> This is a ホスト型ページ for when payment-ui is stripe-hosted. View the full page at https://docs.stripe.com/payments/checkout/phone-numbers?payment-ui=stripe-hosted.

電話番号の収集は、`payment` および `subscription` [モード](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-mode) セッションのすべてで有効にできます(`setup` モードでは、電話番号の収集はサポートされていません)。電話番号は取引に必要な場合のみ収集します。

## 電話番号の収集を有効にする

電話番号の収集を有効にするには、Checkout セッションを作成する際に、[phone_number_collection[enabled]](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-phone_number_collection-enabled) を `true` に設定します。

```curl
curl https://api.stripe.com/v1/checkout/sessions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "line_items[0][price_data][unit_amount]=1000" \
  -d "line_items[0][price_data][product_data][name]=T-shirt" \
  -d "line_items[0][price_data][currency]=eur" \
  -d "line_items[0][quantity]=2" \
  -d "phone_number_collection[enabled]=true" \
  -d mode=payment \
  --data-urlencode "success_url=https://example.com/success"
```

電話番号の収集が有効になっている場合、Checkout は、支払いフォームに「必須の」電話番号フィールドを追加します。配送先住所を収集する場合には、住所フィールドの下に電話番号フィールドが表示されます。それ以外の場合には、Checkout はメールアドレスの入力フィールドの下に電話番号のフィールドを表示します。顧客は 1 回のセッションで電話番号を 1 件のみ入力できます。

## 電話番号を取得する

顧客が [Apple Pay](https://docs.stripe.com/apple-pay.md) や [Google Pay](https://docs.stripe.com/google-pay.md) などのサードパーティーのウォレットで決済する場合、これらのプラットフォームの制限により、電話番号の形式は一定ではなくなります。サードパーティーのウォレットから提供された電話番号の値が返されます。

顧客が[ウォレット決済](https://docs.stripe.com/payments/wallets.md)を使用しない場合、電話番号は必ず [E.164](https://en.wikipedia.org/wiki/E.164) 形式になります。

セッション後の `Account`、`Customer`、または *Checkout Session* (A Checkout Session represents your customer's session as they pay for one-time purchases or subscriptions through Checkout. After a successful payment, the Checkout Session contains a reference to the Customer, and either the successful PaymentIntent or an active Subscription) オブジェクトから顧客の電話番号を取得できます:

- [顧客設定済みAccount上の場合](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer)：Checkout は収集した電話番号を `Account` の [contact_phone](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-contact_phone) プロパティに保存します。API を使用して値を [取得](https://docs.stripe.com/api/v2/core/accounts/retrieve.md) するか、*webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) で [v2.core.account.created](https://docs.stripe.com/api/v2/core/events/event-types.md#v2_event_types-v2.core.account.created) イベントを受信して確認できます。また、顧客の電話番号は [ダッシュボード](https://dashboard.stripe.com/customers) でも確認できます。
- [Customer上の場合](https://docs.stripe.com/api/customers.md)：Checkout は収集した電話番号を `Customer` の [phone](https://docs.stripe.com/api/customers/object.md#customer_object-phone) プロパティに保存します。API を使用して値を [取得](https://docs.stripe.com/api/customers/retrieve.md) するか、*webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) で [customer.created](https://docs.stripe.com/api/events/types.md#event_types-customer.created) イベントを受信して確認できます。また、顧客の電話番号は [ダッシュボード](https://dashboard.stripe.com/customers) でも確認できます。
- [Checkout Session上の場合](https://docs.stripe.com/api/checkout/sessions.md)：Checkout Session でも、顧客の電話番号が [customer_details.phone](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-customer_details-phone) プロパティに保存されます。*webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) で [checkout.session.completed](https://docs.stripe.com/api/events/types.md#event_types-checkout.session.completed) イベントを受信すると、電話番号を含む Checkout Session オブジェクトを取得できます。

## 既存の顧客の電話番号を収集する

電話番号が入力された既存の顧客を[決済セッション](https://docs.stripe.com/api/checkout/sessions.md)に渡すと、電話番号フィールドが事前入力されます。顧客設定の`アカウント`の場合は [contact_phone](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-contact_phone) プロパティ、`顧客`の場合は [phone](https://docs.stripe.com/api/customers/object.md#customer_object-phone) プロパティを使用します。

顧客によって更新された電話番号は、`Account` オブジェクトの `contact_phone` プロパティまたは`Customer` オブジェクトの `phone` プロパティに保持され、以前に保存された電話番号はすべて上書きされます。

### カスタマーポータルで電話番号を更新する

カスタマーポータルでは、顧客自らアカウントを管理させることができます ([電話番号の更新](https://docs.stripe.com/api/customer_portal/configurations/create.md#create_portal_configuration-features-customer_update-allowed_updates)など)。

## See also

- [カスタマーポータルを実装する](https://docs.stripe.com/customer-management.md)


# 埋め込み型ページ

> This is a 埋め込み型ページ for when payment-ui is embedded-form. View the full page at https://docs.stripe.com/payments/checkout/phone-numbers?payment-ui=embedded-form.

電話番号の収集は、`payment` および `subscription` [モード](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-mode) セッションのすべてで有効にできます(`setup` モードでは、電話番号の収集はサポートされていません)。電話番号は取引に必要な場合のみ収集します。

## 電話番号の収集を有効にする

電話番号の収集を有効にするには、Checkout セッションを作成する際に、[phone_number_collection[enabled]](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-phone_number_collection-enabled) を `true` に設定します。

```curl
curl https://api.stripe.com/v1/checkout/sessions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "line_items[0][price_data][unit_amount]=1000" \
  -d "line_items[0][price_data][product_data][name]=T-shirt" \
  -d "line_items[0][price_data][currency]=eur" \
  -d "line_items[0][quantity]=2" \
  -d "phone_number_collection[enabled]=true" \
  -d mode=payment \
  -d ui_mode=embedded_page \
  --data-urlencode "return_url=https://example.com/return"
```

電話番号の収集が有効になっている場合、Checkout は、支払いフォームに「必須の」電話番号フィールドを追加します。配送先住所を収集する場合には、住所フィールドの下に電話番号フィールドが表示されます。それ以外の場合には、Checkout はメールアドレスの入力フィールドの下に電話番号のフィールドを表示します。顧客は 1 回のセッションで電話番号を 1 件のみ入力できます。

## 電話番号を取得する

顧客が [Apple Pay](https://docs.stripe.com/apple-pay.md) や [Google Pay](https://docs.stripe.com/google-pay.md) などのサードパーティーのウォレットで決済する場合、これらのプラットフォームの制限により、電話番号の形式は一定ではなくなります。サードパーティーのウォレットから提供された電話番号の値が返されます。

顧客が[ウォレット決済](https://docs.stripe.com/payments/wallets.md)を使用しない場合、電話番号は必ず [E.164](https://en.wikipedia.org/wiki/E.164) 形式になります。

セッション後の `Account`、`Customer`、または *Checkout Session* (A Checkout Session represents your customer's session as they pay for one-time purchases or subscriptions through Checkout. After a successful payment, the Checkout Session contains a reference to the Customer, and either the successful PaymentIntent or an active Subscription) オブジェクトから顧客の電話番号を取得できます:

- [顧客設定済みAccount上の場合](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer)：Checkout は収集した電話番号を `Account` の [contact_phone](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-contact_phone) プロパティに保存します。API を使用して値を [取得](https://docs.stripe.com/api/v2/core/accounts/retrieve.md) するか、*webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) で [v2.core.account.created](https://docs.stripe.com/api/v2/core/events/event-types.md#v2_event_types-v2.core.account.created) イベントを受信して確認できます。また、顧客の電話番号は [ダッシュボード](https://dashboard.stripe.com/customers) でも確認できます。
- [Customer上の場合](https://docs.stripe.com/api/customers.md)：Checkout は収集した電話番号を `Customer` の [phone](https://docs.stripe.com/api/customers/object.md#customer_object-phone) プロパティに保存します。API を使用して値を [取得](https://docs.stripe.com/api/customers/retrieve.md) するか、*webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) で [customer.created](https://docs.stripe.com/api/events/types.md#event_types-customer.created) イベントを受信して確認できます。また、顧客の電話番号は [ダッシュボード](https://dashboard.stripe.com/customers) でも確認できます。
- [Checkout Session上の場合](https://docs.stripe.com/api/checkout/sessions.md)：Checkout Session でも、顧客の電話番号が [customer_details.phone](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-customer_details-phone) プロパティに保存されます。*webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) で [checkout.session.completed](https://docs.stripe.com/api/events/types.md#event_types-checkout.session.completed) イベントを受信すると、電話番号を含む Checkout Session オブジェクトを取得できます。

## 既存の顧客の電話番号を収集する

電話番号が入力された既存の顧客を[決済セッション](https://docs.stripe.com/api/checkout/sessions.md)に渡すと、電話番号フィールドが事前入力されます。顧客設定の`アカウント`の場合は [contact_phone](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-contact_phone) プロパティ、`顧客`の場合は [phone](https://docs.stripe.com/api/customers/object.md#customer_object-phone) プロパティを使用します。

顧客によって更新された電話番号は、`Account` オブジェクトの `contact_phone` プロパティまたは`Customer` オブジェクトの `phone` プロパティに保持され、以前に保存された電話番号はすべて上書きされます。

### カスタマーポータルで電話番号を更新する

カスタマーポータルでは、顧客自らアカウントを管理させることができます ([電話番号の更新](https://docs.stripe.com/api/customer_portal/configurations/create.md#create_portal_configuration-features-customer_update-allowed_updates)など)。

## See also

- [カスタマーポータルを実装する](https://docs.stripe.com/customer-management.md)

