更新至最新版
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Pay API 已於 2018 年 7 月推出新的 PaymentDataRequest
和 IsReadyToPayRequest
物件結構。本指南解說如何將適用於 Google Pay API 第 1 版格式的物件,更新為適用第 2 版格式。
付款方式
在 Google Pay API 第 2 版中,每個要求物件都會指定 API 版本。
在 Google Pay API 第 1 版中,卡片是唯一支援的付款方式。不過在 Google Pay API 第 2 版中,CARD
付款方式只是多種付款方式中的其中一種。先前指定 allowedPaymentMethods
值為 CARD
的網站現在必須將 allowedAuthMethods
值設為 PAN_ONLY
。先前指定 allowedPaymentMethods
值為 TOKENIZED_CARD
的網站現在必須將 allowedAuthMethods
值設為 CRYPTOGRAM_3DS
。
除了指定允許的發卡機構之外,您現在必須一併指定這些發卡機構支援的卡片驗證方式。
apiVersion 1
{
allowedPaymentMethods: [
'CARD',
'TOKENIZED_CARD'
],
cardRequirements: {
allowedCardNetworks: [
'AMEX',
'DISCOVER',
'JCB',
'MASTERCARD',
'VISA'
]
}
}
apiVersion 2
{
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: [{
type: 'CARD',
parameters: {
allowedAuthMethods: [
'PAN_ONLY',
'CRYPTOGRAM_3DS'
],
allowedCardNetworks: [
'AMEX',
'DISCOVER',
'JCB',
'MASTERCARD',
'VISA'
]
}
}]
}
允許的發卡機構及其驗證方法均包含在 CARD
付款方式的 IsReadyToPayRequest
中。
卡片付款資料代碼化
Google Pay API 會傳回加密的卡片資料,這項資料會由您指定的閘道參照,或是在您的伺服器中解密。Google Pay API 第 2 版將付款方式權杖化作業移至 CARD
付款方式內部。
apiVersion 1
{
paymentMethodTokenizationParameters: {
tokenizationType: 'PAYMENT_GATEWAY',
parameters: {
'gateway': 'example',
'gatewayMerchantId': 'exampleMerchantId'
}
}
}
apiVersion 2
{
allowedPaymentMethods: [{
type: 'CARD',
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
'gateway': 'example',
'gatewayMerchantId': 'exampleMerchantId'
}
}
}]
}
Google 商家 ID
Google 商家 ID 在 Google Pay API 第 1 版中是頂層屬性,現在則位於 MerchantInfo
物件中,並提供選用的商家名稱。
apiVersion 1
{
merchantId: '12345678901234567890'
}
apiVersion 2
{
merchantInfo: {
merchantId: '12345678901234567890'
}
}
帳單地址
選用的帳單地址和帳單電話號碼現在與 CARD
付款方式相關聯。如有網站要求帳單地址,任何與預期回應有關的設定都位在 BillingAddressParameters
物件中。
apiVersion 1
{
cardRequirements: {
billingAddressRequired: true,
billingAddressFormat: 'FULL'
},
phoneNumberRequired: true
}
apiVersion 2
{
allowedPaymentMethods: [{
type: 'CARD',
parameters: {
billingAddressRequired: true,
billingAddressParameters: {
format: 'FULL',
phoneNumberRequired: true
}
}
}]
}
運送地址
選用的運送地址規定仍位於 PaymentDataRequest
物件的頂層,shippingAddressRequirements
屬性已重新命名為 shippingAddressParameters
。
早期,如果要求電話號碼,Google Pay API 可能會將電話號碼做為運送地址的一部分傳回。現在,任何版本的 Google Pay API 皆不支援運送電話號碼。
因此您必須更新任何需要運送電話號碼的回應處理常式。
apiVersion 1
{
shippingAddressRequired: true,
shippingAddressRequirements: {
allowedCountryCodes: [
'US',
'CA'
]
}
}
apiVersion 2
{
shippingAddressRequired: true,
shippingAddressParameters: {
allowedCountryCodes: [
'US',
'CA'
]
}
}
PaymentData 回應
針對 PaymentDataRequest
中 apiVersion
屬性值設為 2
的網站,PaymentData
物件回應已變更為將卡片納入可能的付款資料回應。PaymentDataRequest
物件中包含的 apiVersion
和 apiVersionMinor
屬性會出現在 PaymentData
回應中,以指出預期的格式。
apiVersion 1
{
// no version specified
}
apiVersion 2
{
apiVersion: 2,
apiVersionMinor: 0
}
所選付款方式及其代碼化內容的相關資訊皆位於 paymentMethodData
屬性中。以下兩種屬性已從卡片付款方式的 cardInfo
物件中移除:cardClass
和 cardImageUri
。
apiVersion 1
{
cardInfo: {
cardDescription: 'Visa •••• 1234',
cardNetwork: 'VISA',
cardDetails: 1234
},
paymentMethodToken: {
tokenizationType: 'PAYMENT_GATEWAY',
token: 'examplePaymentMethodToken'
}
}
apiVersion 2
{
paymentMethodData: {
type: 'CARD',
description: 'Visa •••• 1234',
info: {
cardNetwork: 'VISA',
cardDetails: '1234'
},
tokenizationData: {
type: 'PAYMENT_GATEWAY',
token: 'examplePaymentMethodToken'
}
}
}
加密訊息回應
如果網站指定的付款方式權杖化類型是 DIRECT
,並接受 API 第 1 版的 TOKENIZED_CARD
付款方式,您就必須更新網站處理已解密 encryptedMessage
屬性的方式。您必須執行這項操作,網站才能繼續將透過 3-D Secure 密文和選用電子商務指標 (ECI) 驗證的 Android 裝置權杖轉送至您的閘道或處理方。卡片是 CARD
的 paymentMethod
,且含有 paymentMethodDetails.authMethod
中所選卡片驗證方法的額外資訊。
apiVersion 1
{
"paymentMethod": "TOKENIZED_CARD",
"paymentMethodDetails": {
"authMethod": "3DS",
"dpan": "1111222233334444",
"expirationMonth": 10,
"expirationYear": 2020,
"3dsCryptogram": "AAAAAA...",
"3dsEciIndicator": "eci indicator"
}
}
apiVersion 2
{
"paymentMethod": "CARD",
"paymentMethodDetails": {
"authMethod": "CRYPTOGRAM_3DS",
"pan": "1111222233334444",
"expirationMonth": 10,
"expirationYear": 2020,
"cryptogram": "AAAAAA...",
"eciIndicator": "eci indicator"
}
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-10-16 (世界標準時間)。
[null,null,["上次更新時間:2024-10-16 (世界標準時間)。"],[[["\u003cp\u003eGoogle Pay API \u003ccode\u003ePaymentDataRequest\u003c/code\u003e and \u003ccode\u003eIsReadyToPayRequest\u003c/code\u003e objects have been updated with new structures in version 2, requiring updates to existing integrations.\u003c/p\u003e\n"],["\u003cp\u003eVersion 2 introduces explicit API versioning and expands payment methods beyond just cards, requiring adjustments to \u003ccode\u003eallowedPaymentMethods\u003c/code\u003e and \u003ccode\u003eallowedAuthMethods\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003ePayment method tokenization, Google merchant ID, billing address configuration, and shipping address parameters have been relocated within the new object structure.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePaymentData\u003c/code\u003e response format has been revised to include API version information and nest card details within \u003ccode\u003epaymentMethodData\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eHandling of encrypted message responses for tokenized cards requires updates to accommodate the new \u003ccode\u003epaymentMethod\u003c/code\u003e and \u003ccode\u003epaymentMethodDetails\u003c/code\u003e structure.\u003c/p\u003e\n"]]],["The Google Pay API updated its object structures to version 2. Key changes include specifying the API version in each request and expanding payment methods beyond just `CARD`. Version 2 requires setting `allowedAuthMethods` to `PAN_ONLY` or `CRYPTOGRAM_3DS` instead of `allowedPaymentMethods`. Tokenization moved inside the `CARD` payment method, and the merchant ID is now within the `MerchantInfo` object. Billing and shipping address requirements are reorganized. Finally, `PaymentData` responses now specify the API version.\n"],null,["# Update to latest version\n\nThe Google Pay API introduced new object structures for\n[`PaymentDataRequest`](/pay/api/web/reference/request-objects#PaymentDataRequest) and\n[`IsReadyToPayRequest`](/pay/api/web/reference/request-objects#IsReadyToPayRequest) objects in July 2018. This guide explains how to update\nobjects formatted for Google Pay API version 1 to objects formatted for version 2.\n\nPayment methods\n---------------\n\nAn API version is specified with each request object in version 2 of the Google Pay API.\n\nVersion 1 of the Google Pay API supported cards as the only form of payment. The\n`CARD` [payment method](/pay/api/web/reference/request-objects#PaymentMethod)\nis one of multiple possible payment method options in version 2 of the Google Pay API. Sites that\npreviously specified an `allowedPaymentMethods` value of `CARD` must now set\nan `allowedAuthMethods` value of `PAN_ONLY`. Sites that previously specified\nan `allowedPaymentMethods` value of `TOKENIZED_CARD` must now set an\n`allowedAuthMethods` value of `CRYPTOGRAM_3DS`.\n\nAllowed card networks are specified alongside supported authentication methods for cards on\nthose networks. \n\n### apiVersion 1\n\n```javascript\n{\n allowedPaymentMethods: [\n 'CARD',\n 'TOKENIZED_CARD'\n ],\n cardRequirements: {\n allowedCardNetworks: [\n 'AMEX',\n 'DISCOVER',\n 'JCB',\n 'MASTERCARD',\n 'VISA'\n ]\n }\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n apiVersion: 2,\n apiVersionMinor: 0,\n allowedPaymentMethods: [{\n type: 'CARD',\n parameters: {\n allowedAuthMethods: [\n 'PAN_ONLY',\n 'CRYPTOGRAM_3DS'\n ],\n allowedCardNetworks: [\n 'AMEX',\n 'DISCOVER',\n 'JCB',\n 'MASTERCARD',\n 'VISA'\n ]\n }\n }]\n}\n```\n\nAllowed card networks and their authentication methods are included in an\n[`IsReadyToPayRequest`](/pay/api/web/reference/request-objects#IsReadyToPayRequest) for a `CARD`\n[payment method](/pay/api/web/reference/request-objects#PaymentMethod \"Object reference: payment method\").\n\nCard payment data tokenization\n------------------------------\n\nThe Google Pay API returns encrypted card data that's referenced by your specified gateway or\ndecrypted on your servers. Version 2 of the Google Pay API moves\n[payment method tokenization](/pay/api/web/reference/request-objects#PaymentMethodTokenizationSpecification \"Object reference: PaymentMethodTokenizationSpecification\")\ninside the `CARD` payment method. \n\n### apiVersion 1\n\n```javascript\n{\n paymentMethodTokenizationParameters: {\n tokenizationType: 'PAYMENT_GATEWAY',\n parameters: {\n 'gateway': '\u003cvar translate=\"no\"\u003eexample\u003c/var\u003e',\n 'gatewayMerchantId': '\u003cvar translate=\"no\"\u003eexampleMerchantId\u003c/var\u003e'\n }\n }\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n allowedPaymentMethods: [{\n type: 'CARD',\n tokenizationSpecification: {\n type: 'PAYMENT_GATEWAY',\n parameters: {\n 'gateway': '\u003cvar translate=\"no\"\u003eexample\u003c/var\u003e',\n 'gatewayMerchantId': '\u003cvar translate=\"no\"\u003eexampleMerchantId\u003c/var\u003e'\n }\n }\n }]\n}\n```\n\nGoogle merchant ID\n------------------\n\nA Google merchant ID was a top-level property in version 1 of the Google Pay API. Now, the\nGoogle merchant ID is placed inside a\n[`MerchantInfo`](/pay/api/web/reference/request-objects#MerchantInfo) object\nwith an optional merchant name. \n\n### apiVersion 1\n\n```javascript\n{\n merchantId: '12345678901234567890'\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n merchantInfo: {\n merchantId: '12345678901234567890'\n }\n}\n```\n\nBilling address\n---------------\n\nAn optional billing address and a billing phone number are associated with a `CARD` payment method.\nIf a site requests a billing address, any configuration related to the expected response is placed inside a\n[`BillingAddressParameters`](/pay/api/web/reference/request-objects#BillingAddressParameters) object. \n\n### apiVersion 1\n\n```javascript\n{\n cardRequirements: {\n billingAddressRequired: true,\n billingAddressFormat: 'FULL'\n },\n phoneNumberRequired: true\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n allowedPaymentMethods: [{\n type: 'CARD',\n parameters: {\n billingAddressRequired: true,\n billingAddressParameters: {\n format: 'FULL',\n phoneNumberRequired: true\n }\n }\n }]\n}\n```\n\nShipping address\n----------------\n\nAn optional shipping address requirement remains at the top level of the\n[`PaymentDataRequest`](/pay/api/web/reference/request-objects#PaymentDataRequest) object.\nThe `shippingAddressRequirements` property has been renamed\n[`shippingAddressParameters`](/pay/api/web/reference/request-objects#ShippingAddressParameters).\n\nEarlier Google Pay API responses might have returned a phone number as part of the shipping address\nwhen a phone number was requested. A shipping phone number is no longer supported by the Google Pay API in any version.\nAny response handlers that expect a shipping phone number must be updated. \n\n### apiVersion 1\n\n```javascript\n{\n shippingAddressRequired: true,\n shippingAddressRequirements: {\n allowedCountryCodes: [\n 'US',\n 'CA'\n ]\n }\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n shippingAddressRequired: true,\n shippingAddressParameters: {\n allowedCountryCodes: [\n 'US',\n 'CA'\n ]\n }\n}\n```\n\nPaymentData response\n--------------------\n\nThe [`PaymentData`](/pay/api/web/reference/response-objects#PaymentData) object response\nfor sites that set an `apiVersion` property value of `2` in\n[`PaymentDataRequest`](/pay/api/web/reference/request-objects#PaymentDataRequest)\nhas changed to reference cards as one of multiple possible payment data responses.\nThe `apiVersion` and `apiVersionMinor` properties included in the\n[`PaymentDataRequest`](/pay/api/web/reference/request-objects#PaymentDataRequest) object\nappear in the\n[`PaymentData`](/pay/api/web/reference/response-objects#PaymentData) response to indicate\nthe expected format. \n\n### apiVersion 1\n\n```javascript\n{\n // no version specified\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n apiVersion: 2,\n apiVersionMinor: 0\n}\n```\n\nInformation about a selected payment method and its tokenization is placed inside the\n[`paymentMethodData`](/pay/api/web/reference/response-objects#PaymentMethodData) property.\nTwo properties have been removed from the card payment method's `cardInfo` object:\n`cardClass` and `cardImageUri`. \n\n### apiVersion 1\n\n```javascript\n{\n cardInfo: {\n cardDescription: 'Visa •••• 1234',\n cardNetwork: 'VISA',\n cardDetails: 1234\n },\n paymentMethodToken: {\n tokenizationType: 'PAYMENT_GATEWAY',\n token: 'examplePaymentMethodToken'\n }\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n paymentMethodData: {\n type: 'CARD',\n description: 'Visa •••• 1234',\n info: {\n cardNetwork: 'VISA',\n cardDetails: '1234'\n },\n tokenizationData: {\n type: 'PAYMENT_GATEWAY',\n token: 'examplePaymentMethodToken'\n }\n }\n}\n```\n\nEncrypted message response\n--------------------------\n\nSites that specify a `DIRECT` payment method tokenization type and accept an\nAPI version 1 payment method of `TOKENIZED_CARD` must update how they handle the\ndecrypted `encryptedMessage` property. The site must do this to continue to forward\nAndroid device tokens authenticated with a 3-D Secure cryptogram and optional electronic commerce\nindicator (ECI) to your gateway or processor. Cards are a `paymentMethod` of\n`CARD`, with additional information about the selected card's authentication method in\n`paymentMethodDetails.authMethod`. \n\n### apiVersion 1\n\n```javascript\n{\n \"paymentMethod\": \"TOKENIZED_CARD\",\n \"paymentMethodDetails\": {\n \"authMethod\": \"3DS\",\n \"dpan\": \"1111222233334444\",\n \"expirationMonth\": 10,\n \"expirationYear\": 2020,\n \"3dsCryptogram\": \"AAAAAA...\",\n \"3dsEciIndicator\": \"eci indicator\"\n }\n}\n```\n\n### apiVersion 2\n\n```javascript\n{\n \"paymentMethod\": \"CARD\",\n \"paymentMethodDetails\": {\n \"authMethod\": \"CRYPTOGRAM_3DS\",\n \"pan\": \"1111222233334444\",\n \"expirationMonth\": 10,\n \"expirationYear\": 2020,\n \"cryptogram\": \"AAAAAA...\",\n \"eciIndicator\": \"eci indicator\"\n }\n}\n```"]]