Google Pay のライブデモ
コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。
このページには、JavaScript や JSFiddle で編集できる Google Pay のライブデモが含まれています。
基本サンプル
以下は Google Pay ボタンの動作の基本的な例です。コードの作成方法の例については、隣接するコードを参照してください。
Google Pay ボタンのサイズを変更する方法は次のとおりです。buttonSizeMode
プロパティを fill
に設定して createButton
を呼び出し、#container div
でサイズを設定します。
お支払いの承認の例
以下は、お支払いを処理する前に承認する方法の例です。
お支払いを処理する前に承認する理由は、承認が失敗した場合に別のお支払い方法を選択できるようにするためです。
お支払い承認リクエストは次の手順で処理できます。
-
PaymentOptions
で onPaymentAuthorized()
コールバックを登録します。 -
PAYMENT_AUTHORIZATION
コールバック インテントを指定して loadPaymentData()
関数を呼び出します。 onPaymentAuthorized()
コールバック ハンドラを実装します。
JSFiddle で編集リンクをクリックして、ご自分で編集して試してみてください。
動的料金設定の更新の例
動的料金設定の更新では、配送先住所と配送オプションの変更に合わせて合計金額を動的に調整できます。
動的料金設定の更新を設定するには、次の手順を行います。
PaymentOptions
で onPaymentAuthorized
と onPaymentDataChanged
の両方のコールバックを登録します。 - コールバック インテントを指定して
loadPaymentData()
関数を呼び出します。詳しくは、対応するサンプルをご覧ください。 onPaymentAuthorized
と onPaymentDataChanged
を実装します。
JSFiddle で編集リンクをクリックして、ご自分で編集して試してみてください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-10-16 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2024-10-16 UTC。"],[[["\u003cp\u003eThis page provides live, editable Google Pay demos using JavaScript or JSFiddle.\u003c/p\u003e\n"],["\u003cp\u003eYou can explore examples demonstrating basic Google Pay button integration, button resizing, and payment authorization.\u003c/p\u003e\n"],["\u003cp\u003eThe demos also showcase how to dynamically update prices based on shipping changes using Dynamic Price Updates.\u003c/p\u003e\n"],["\u003cp\u003eThese demos are interactive and can be edited in JSFiddle for experimentation and learning.\u003c/p\u003e\n"]]],["The content showcases live Google Pay demos editable in JavaScript or JSFiddle. Key actions include creating and resizing the Google Pay button using `createButton` with `buttonSizeMode`. It demonstrates authorizing payments before processing by registering `onPaymentAuthorized()`, calling `loadPaymentData()`, and implementing the callback handler. Dynamic price updates are enabled by registering `onPaymentAuthorized` and `onPaymentDataChanged`, and implementing both functions after calling `loadPaymentData`. Note that authorize payments and Dynamic price updates do not support liability shift.\n"],null,["This page contains live Google Pay demos that you can edit in JavaScript or JSFiddle.\n| **Note**: The demos on this page will only show a button if your browser supports Google Pay.\n\nBasic example\n\nThe following demonstrates a basic example of the Google Pay button in action. Refer to the\nadjacent code for an example on how it's constructed. \n\nButton resize example\n\nThe following demonstrates how you can resize the Google Pay button. Call\n`createButton` with the `buttonSizeMode` property set to `fill`,\nand then set a size on the `#container div`. \n\nAuthorize Payments example\n\nThe following is an example of how you can *authorize a payment* before processing it. \n\nThe reason you might want to authorize a payment before processing it is to give the user an\nopportunity to choose a different payment method if the authorization fails.\n\nYou can handle the payment authorization request by following these instructions:\n\n1. Register an [`onPaymentAuthorized()`](/pay/api/web/reference/client#onPaymentAuthorized) callback in [`PaymentOptions`](/pay/api/web/reference/request-objects#PaymentOptions).\n2. Call the [`loadPaymentData()`](/pay/api/web/reference/client#loadPaymentData) function with the `PAYMENT_AUTHORIZATION` callback intent.\n3. Implement the [`onPaymentAuthorized()`](/pay/api/web/reference/client#onPaymentAuthorized) callback handler.\n\nClick the [Edit in JSFiddle](https://jsfiddle.net/34wxopb2/)\nlink to edit and try it out for yourself.\n\nDynamic Price Update example \n\nDynamic Price Updates allows you to dynamically adjust the total price to reflect changes in shipping address and shipping option changes.\n\nUse the following steps to set up Dynamic Price Updates:\n\n1. Register both of the [`onPaymentAuthorized`](/pay/api/web/reference/client#onPaymentAuthorized) and [`onPaymentDataChanged`](/pay/api/web/reference/client#onPaymentDataChanged) callbacks in [`PaymentOptions`](/pay/api/web/reference/request-objects#PaymentOptions).\n2. Call the [`loadPaymentData()`](/pay/api/web/reference/client#loadPaymentData) function with callback intents. For details, see the corresponding [example](/pay/api/web/guides/tutorial#load).\n3. Implement [`onPaymentAuthorized`](/pay/api/web/reference/client#onPaymentAuthorized) and [`onPaymentDataChanged`](/pay/api/web/reference/client#onPaymentDataChanged).\n\nClick the [Edit in JSFiddle](https://jsfiddle.net/ynt8p152/) link to edit and try it out for yourself."]]