# Google Pay

Google Pay を使用した決済の受け付け方法をご紹介します。

決済手段の取引手数料については、[料金体系の詳細](https://stripe.com/pricing/local-payment-methods)をご覧ください。

Google Pay を使用すると、Google Play、YouTube、Chrome、Android デバイスなど、Google アカウントに保存されているクレジットカードやデビットカードを使用して、アプリやウェブサイトで支払いを行うことができます。Google Pay API を使用して、顧客の Google アカウントに保存されているクレジットカードまたはデビットカードをリクエストします。

Google Pay は Stripe のプロダクトや機能 (継続支払いなど) と完全な互換性があるため、通常は従来の支払いフォームの代わりに使用できます。物品、寄付、*サブスクリプション* (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)の受け付けに使用します。

> #### Google Pay の規約
> 
> Google Pay を組み込むことで、Google の[利用規約](https://payments.developers.google.com/terms/sellertos)に同意したことになります。

#### 支払い方法のプロパティ

- **顧客の場所**

  インドを除く世界各地

- **取引通貨**

  [サポートされている取引通貨](https://docs.stripe.com/currencies.md#presentment-currencies)を参照してください

- **支払いの確定**

  顧客主導

- **支払い方法の種類**

  ウォレット

- **継続支払い**

  あり

- **入金タイミング**

  標準の入金タイミングを適用

- **Connect のサポート**

  あり

- **不審請求の申請に関するサポート**

  [可](https://docs.stripe.com/google-pay.md#disputed-payments)

- **手動キャプチャーのサポート**

  あり

- **返金 / 一部返金**

  [可 / 可](https://docs.stripe.com/google-pay.md#refunds)

#### ビジネスの所在地

インドを除く世界各地の Stripe アカウントは、Google Pay による支払いを現地通貨決済で受け付けることができます。

#### 製品のサポート

- Connect
- Checkout
- Payment Links
- Elements
- Subscriptions
- Invoicing

## Stripe および Google Pay の利用と Google Play の課金システムの利用について

このガイドでは、物理的な製品、サービス、その他の対象となる品目に対し、Google Pay を受け付けるようにアプリを設定する方法について説明します。Stripe はこれらの決済を処理し、Stripe の[処理手数料](https://stripe.com/pricing)のみを支払います。

アメリカまたは EEA (欧州経済領域) で販売されるデジタル商品、コンテンツ、サブスクリプションの場合、Android アプリは、Stripe などのサードパーティーの決済代行業者を通じてアプリ内で直接決済を受け付けることができます。以下の決済 UI を使用できます。

- アプリ内で直接決済を受け付ける[モバイル決済 Element](https://docs.stripe.com/payments/mobile.md)
- 顧客を Stripe がホストする決済ページにリダイレクトするには、[Stripe Checkout](https://docs.stripe.com/mobile/digital-goods/checkout.md) を使用します。
- 限られた数の商品と価格向けの [Payment Links](https://docs.stripe.com/mobile/digital-goods/payment-links.md)

Google Play の課金システムを使用しなければならない購入の詳細については、Google Play の[開発者向け利用規約](https://support.google.com/googleplay/android-developer/answer/10281818)をご覧ください。

# React Native


Stripe の React Native SDK は、React Native アプリで Google Pay の受け付けを開始するための最も早くて簡単な方法です。[PlatformPayButton](https://stripe.dev/stripe-react-native/api-reference/index.html#PlatformPayButton) コンポーネントには Google の必要な UI がラップされており、また `confirmPlatformPayPayment` と `createPlatformPayPaymentMethod` メソッドを使用して、アプリから最小限の設定でシームレスに支払いを回収または作成できます。

> React Native と Expo を使用している場合、Expo Go は Google Pay に対応していません。Google Pay を Expo で使用するには、[開発ビルド](https://docs.expo.dev/get-started/set-up-your-environment/?mode=development-build&platform=android)を作成する必要があります。すでに Expo Go プロジェクトがある場合は、[開発ビルドに移行](https://docs.expo.dev/develop/development-builds/expo-go-to-dev-build/)できます。

## Stripe を設定する [サーバ側] [クライアント側]

### サーバ側

この組み込みには、Stripe API と通信するエンドポイントがサーバ上に必要です。Stripe の公式ライブラリを使用して、サーバから Stripe API にアクセスします。

#### Ruby

```bash
# Available as a gem
sudo gem install stripe
```

```ruby
# If you use bundler, you can add this line to your Gemfile
gem 'stripe'
```

### クライアント側

[React Native SDK](https://github.com/stripe/stripe-react-native) はオープンソースであり、詳細なドキュメントが提供されています。内部では、[ネイティブの iOS](https://github.com/stripe/stripe-ios) および [Android](https://github.com/stripe/stripe-android) の SDK を使用します。Stripe の React Native SDK をインストールするには、プロジェクトのディレクトリーで (使用するパッケージマネージャーによって異なる) 次のいずれかのコマンドを実行します。

#### yarn

```bash
yarn add @stripe/stripe-react-native
```

#### npm

```bash
npm install @stripe/stripe-react-native
```

次に、その他の必要な依存関係をインストールします。

- iOS の場合は、**ios** ディレクトリに移動して `pod install` を実行し、必要なネイティブ依存関係もインストールします。
- Android の場合は、依存関係をインストールする必要はありません。

> [公式の TypeScript ガイド](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project)に従って TypeScript のサポートを追加することをお勧めします。

### Stripe の初期化

React Native アプリで Stripe を初期化するには、決済画面を `StripeProvider` コンポーネントでラップするか、`initStripe` 初期化メソッドを使用します。`publishableKey` の API [公開可能キー](https://docs.stripe.com/keys.md#obtain-api-keys)のみが必要です。次の例は、`StripeProvider` コンポーネントを使用して Stripe を初期化する方法を示しています。

```jsx
import { useState, useEffect } from 'react';
import { StripeProvider } from '@stripe/stripe-react-native';

function App() {
  const [publishableKey, setPublishableKey] = useState('');

  const fetchPublishableKey = async () => {
    const key = await fetchKey(); // fetch key from your server here
    setPublishableKey(key);
  };

  useEffect(() => {
    fetchPublishableKey();
  }, []);

  return (
    <StripeProvider
      publishableKey={publishableKey}
      merchantIdentifier="merchant.identifier" // required for Apple Pay
      urlScheme="your-url-scheme" // required for 3D Secure and bank redirects
    >
      {/* Your app code here */}
    </StripeProvider>
  );
}
```

> テストおよび開発時には API の[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。

## Google Pay を有効にする

Google Pay を使用するには、まず以下を **AndroidManifest.xml** の `<application>` に追加し、Google Pay API を有効化します。

```xml
<application>
  ...
  <meta-data
    android:name="com.google.android.gms.wallet.api.enabled"
    android:value="true" />
</application>
```

詳細は、Google Pay の Android 向け [Google Pay API を設定する](https://developers.google.com/pay/api/android/guides/setup) を参照してください。

## PaymentIntent を作成する [サーバー側]

まず、サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。

```curl
curl https://api.stripe.com/v1/payment_intents \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d amount=1099 \
  -d currency=usd
```

PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これを React Native アプリで使用することで、PaymentIntent オブジェクト全体を渡すことなく安全に支払いプロセスを完了できます。アプリで、サーバーの PaymentIntent をリクエストし、その client secret を保存します。

## Google Pay を初期化する [クライアント側]

まず、`isPlatformPaySupported` を呼び出して、デバイスが Google Pay をサポートしているかどうかを確認します。

```javascript
import { usePlatformPay } from '@stripe/stripe-react-native';

function PaymentScreen() {
  const { isPlatformPaySupported } = usePlatformPay();

  React.useEffect(() => {
    (async function () {
      if (!(await isPlatformPaySupported({ googlePay: {testEnv: true} }))) {
        Alert.alert('Google Pay is not supported.');
        return;
      }
    })();
  }, []);

  ...

  return (
    <View >
      ...
    </View>
  );
}
```

## Google Pay 支払い画面を表示する [クライアント側]

Google Pay が利用可能であることが分かり、アプリが `PaymentIntent` または `SetupIntent` の client secret を取得したら、`confirmPlatformPayPayment` を呼び出します。`SetupIntent` を確定する際は、代わりに `confirmPlatformPaySetupIntent` を使用します。

```javascript
import {PlatformPayButton, usePlatformPay} from '@stripe/stripe-react-native';

function PaymentScreen() {
  const {
    isPlatformPaySupported,
    confirmPlatformPayPayment,
  } = usePlatformPay();

  React.useEffect(() => {
    ... // see above
  }, []);

  const fetchPaymentIntentClientSecret = async () => {
    // Fetch payment intent created on the server, see above
    const response = await fetch(`${API_URL}/create-payment-intent`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        currency: 'usd',
      }),
    });
    const { clientSecret } = await response.json();

    return clientSecret;
  };

  const pay = async () => {
    const clientSecret = await fetchPaymentIntentClientSecret();

    const { error, paymentIntent } = await confirmPlatformPayPayment(
      clientSecret,
      {
        googlePay: {
          testEnv: true,
          merchantName: 'My merchant name',
          merchantCountryCode: 'US',
          currencyCode: 'USD',
          billingAddressConfig: {
            format: PlatformPay.BillingAddressFormat.Full,
            isPhoneNumberRequired: true,
            isRequired: true,
          },
        },
      }
    );

    if (error) {
      Alert.alert(error.code, error.message);
      // Update UI to prompt user to retry payment (and possibly another payment method)
      return;
    }
    Alert.alert('Success', 'The payment was confirmed successfully.');
    console.log(JSON.stringify(paymentIntent, null, 2));
  };

  return (
    <View >
      <PlatformPayButton
        type={PlatformPay.ButtonType.Pay}
        onPress={pay}
        style={{
          width: '100%',
          height: 50,
        }}
      />
    </View>
  );
}
```

## Optional: PaymentMethod を作成する [クライアント側]

サーバーで支払いを確定する場合は、Google Pay を使用して、支払いを確定する代わりに `PaymentMethod` の収集のみを実行できます。このコールを行うには、`createPlatformPayPaymentMethod` メソッドを使用します。

```javascript
import {PlatformPayButton, usePlatformPay} from '@stripe/stripe-react-native';

function PaymentScreen() {
  const {
    isPlatformPaySupported,
    createPlatformPayPaymentMethod,
  } = usePlatformPay();

  React.useEffect(() => {
    ... // see above
  }, []);

  const createPaymentMethod = async () => {
    const { error, paymentMethod } = await createPlatformPayPaymentMethod({
      googlePay: {
        amount: 12,
        currencyCode: 'USD',
        testEnv: true,
        merchantName: 'Test',
        merchantCountryCode: 'US',
      },
    });

    if (error) {
      Alert.alert(error.code, error.message);
      return;
    } else if (paymentMethod) {
      Alert.alert(
        'Success',
        `The payment method was created successfully. paymentMethodId: ${paymentMethod.id}`
      );
    }
  };

  return (
    <View>
      <PlatformPayButton
        type={PlatformPay.ButtonType.GooglePayMark}
        onPress={createPaymentMethod}
        style={{
          width: '100%',
          height: 50,
        }}
      />
    </View>
  );
}
```

## Google Pay を本番環境へ移行

[Google の指示](https://developers.google.com/pay/api/android/guides/test-and-deploy/request-prod-access) に従ってアプリの本番環境でのアクセスをリクエストします。メッセージが表示されたら、連携タイプに **Gateway (ゲートウェイ)** を選択し、審査のためにアプリのスクリーンショットを提供します。

アプリが承認されたら、`testEnv: false` を使用し、署名済みのアプリのリリースビルドから Google Pay を起動して、本番環境で連携をテストします。この際に*本番環境* (Use this mode when you’re ready to launch your app. Card networks or payment providers process payments) [API キー](https://docs.stripe.com/keys.md)を使用することを忘れないでください。[capture_method=manual](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-capture_method) を指定した `PaymentIntent` を使用すると、支払いをキャプチャーせずに取引を処理できます。

### Google Pay をテストする

Google では、[テストクレジットカードスイート](https://developers.google.com/pay/api/android/guides/resources/test-card-suite) を使用してテスト決済を行うことができます。Stripe [テストカード](https://docs.stripe.com/testing.md) をテストスイートと併用できます。

Google Pay がサポートされている国では、シミュレーションされたデバイスではなく、物理的な Android デバイスを使用して Google Pay をテストする必要があります。Google ウォレットに保存した実際のクレジットカードを使用して、テスト用デバイスの Google アカウントにログインします。


## 不審請求の申請

利用者は自身の Google Pay アカウントを使用して支払いを承認する必要があり、これによって不正使用や未承認の支払いを減らすことができます。それでも、支払いの完了後に利用者が不審請求の申請を行う場合があります。不審請求の申請に異議を申し立てる反証資料は、直接提出することができます。不審請求の申請プロセスはカード支払いと同じです。[不審請求の申請に対応する](https://docs.stripe.com/disputes/responding.md)方法をご覧ください。

### Google Pay 支払いのライアビリティシフト

Google Pay は世界各地での [ライアビリティシフト](https://docs.stripe.com/payments/3d-secure/authentication-flow.md#disputed-payments) に対応しています。Stripe が提供するプロダクトのユーザーと Stripe.js を使用するユーザーは自動的に適用されます。Stripe が提供するプロダクト以外が Visa の取引の場合、Google Pay & ウォレットコンソールでライアビリティシフトを有効にする必要があります。これを行うには、_**Google Pay & ウォレットコンソール**_に移動し、左側のナビゲーションバーで _**Google Pay API**_を選択して、ライアビリティシフト保護の _**Visa デバイストークンの不正利用によるライアビリティ保護**_を有効にします。

Google Pay の取引には、3 つのユースケースがあります。

1. ユーザーがモバイルデバイスを使用して、Google Pay アプリにカードを追加する場合、このカードは DPAN (デバイスプライマリアカウント番号) として保存され、デフォルトでライアビリティシフトに対応します。
2. ユーザーが Chrome や Google サービス (YouTube、Google Play など) にカードを追加すると、そのカードは Funding Primary Account Number (FPAN) として保存されます。[3D セキュア](https://docs.stripe.com/payments/3d-secure.md)利用時には、Visa を含むすべての主要ネットワークのライアビリティシフトが全世界でサポートされます。[Stripe Radar ルール](https://docs.stripe.com/radar/rules.md#request-3d-secure)をカスタマイズして 3D セキュアの有効化をリクエストできます。
3. ユーザーが EC ストアサイトで支払い方法として Google Pay を選択したり、 Google Pay で支払うアプリを選択する場合、カードは登録済みのカードを表す EC ストアトークンとして保存されます。ライアビリティシフトも 3D セキュアも、現時点では EC ストアトークンでサポートされていません。

Sigma ユーザーの場合、`charges` テーブルには Google Pay の取引タイプを示す `card_token_type` フィールドが格納されます。FPAN 取引は `card_token_type` を `fpan` に設定します。DPAN および EC ストアトークンの取引は、`card_token_type` を `dpan_or_ecommerce_token` に設定します。

## 返金

成功した Google Pay の支払いは、一部返金または全額返金することができます。返金プロセスはカード支払いの場合と同じです。返金の開始または管理の手順については、[支払いの返金とキャンセル](https://docs.stripe.com/refunds.md)をご覧ください。
