在Flutter中集成Google钱包添加按钮时遇到的问题。

huangapple go评论106阅读模式
英文:

Problems integrating an Add to Google Wallet button with Flutter

问题

我正在使用 flutter_google_wallet 插件来在我的应用中添加一个添加到 Google 钱包按钮。在这个过程中,我犯了一些错误,没有办法在没有联系 Google 开发者支持的情况下找出解决方法,Google Pay 和钱包控制台。

在处理过程中我遇到的一些错误消息包括:

  • "发生了一些问题,请重试"
  • "验证 RPC 失败"
  • "无法加载此通行证"

我在网上没有找到这些问题的解决方案,所以我将在这个 "问题" 的答案中记录它们。

英文:

I am using the flutter_google_wallet plugin to add an Add to Google Wallet button to my app. In the process I've made several mistakes that I wasn't able to figure out without contacting Google's developer support for Google Pay and Wallet console.

Some of the error message I dealt with during the process were:

  • "Something went wrong. Please try again"
  • "Validate RPC failed"
  • "Unable to load this pass"

I did not find solutions to these issues online, so I'll document them in an answer to this "question".

答案1

得分: 1

以下是您要翻译的文本:

我的第一次尝试使用插件导致出现错误,显示为:“出现问题,请重试”,在adb日志中我看到了一个错误,显示为“验证RPC失败”。支持表示我需要通过向他们发送我的发布者ID、应用程序包名称和SHA1指纹来将我的应用程序添加到他们的“允许列表”中。向Google发送这些信息后,过了几天他们才让我知道我可以继续。

flutter_google_wallet的文档显示,您需要将JSON字符串传递给其savePasses方法,但它并未显示该字符串的示例,因此您必须在Google文档中查找该格式。最初,我只是发送了“payload”值,没有将其包装在包含iss、aud、typ、iat和origins属性的元素中。

我犯的下一个错误是从Google Pay控制台复制我的发布者ID。不要将您的字母数字商户ID与发布者ID混淆。发布者ID应该只包含数字,例如:3388000000012345678。您将在Google Pay和Wallet控制台页面中央上部的“Google Wallet API发布者ID:”之后找到这个值。此值在您的JSON中有两个地方使用。第一个地方是作为您的对象的“id”值的前缀。第二个地方是作为对象的“classId”值的前缀。

我指定“iat”值的格式错误。它应该是数字的“unix_time”(自纪元以来的秒)值。

我遇到的另一个错误是我引用的图像之一已经移动了。如果您正在使用heroImage属性,请仔细检查并确保URI有效。

我意识到的最后一个错误是,我试图使用一个类Id为“Event Ticket”类型的“genericObjects”负载。确保使用“eventTicketObjects” JSON与“Event Ticket”类型的类以及“genericObjects”与“Generic”类型的类一起使用!

尽管最终我会在服务器上创建此JSON,但我目前正在模拟并在我的Flutter应用程序中使用以下代码创建它:

// Google为您的“服务帐户”创建的“电子邮件地址”,您可以在https://console.cloud.google.com/apis/credentials上找到
const issuerEmail = 'google-wallet-my-proj@company-proj.iam.gserviceaccount.com';

// 使用pay.google.com/business/console上找到的发布者ID进行更新
const issuerId = '3388000000012345678';

// 您在pay.google.com/business/console上创建的Google Wallet类的名称
const className = 'GeneralAdmission';
final passId = const Uuid().v4(); // 随机UUID

final iat = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final json = '''
{
"iss": "$issuerEmail",
"aud": "google",
"typ": "savetowallet",
"iat": "$iat",
"origins": [],
"payload": {
"genericObjects": [{
"id": "$issuerId.$passId",
"classId": "$issuerId.$className",
"genericType": "GENERIC_TYPE_UNSPECIFIED",
"cardTitle": {
"defaultValue": {
"language": "en",
"value": "Card title"
}
},
"header": {
"defaultValue": {
"language": "en",
"value": "header"
}
},
"subheader": {
"defaultValue": {
"language": "en",
"value": "subheader"
}
}
}]
}
}
''';
''';


请告诉我如果您需要任何其他翻译帮助。

<details>
<summary>英文:</summary>

My first attempt at using the plugin resulted in getting an error displayed that said:
&quot;Something went wrong. Please try again&quot; and in the adb log I saw an error which said &quot;Validate RPC failed&quot;. Support indicated that I needed to get my app added to their &quot;allow-list&quot; by sending them my Issuer ID, App package name, and SHA1 fingerprint. After sending Google this info, it was a couple days before they let me know that I could proceed.

The documentation for the flutter_google_wallet shows that you pass a json string to its savePasses method but it doesn&#39;t show an example of that string, so you have to dig around the google documentation for that format. Initially, I was just sending the &quot;payload&quot; value without wrapping that in an element that included the iss, aud, typ, iat, and origins properties.

The next error I made was in copying my issuerId from the Google Pay Console.  Don&#39;t confuse your alpha-numeric merchant ID for your issuerId.  The issuerId should be only digits such as: 3388000000012345678.  You&#39;ll find this at the center of the Google Pay &amp; Wallet console page near the center top after it says Google Wallet API
Issuer ID:.  This value gets used in two places in your json. The first is as a prefix to your object&#39;s &quot;id&quot; value. The second place is as a prefix to the object&#39;s &quot;classId&quot; value.

I was specifying the &quot;iat&quot; value in the wrong format. It should be a numeric &quot;unix_time&quot; (seconds since epoch) value.

Another error I ran into was that one of the images I referenced had been moved. If you are using a heroImage property, double check and make sure the URI is valid.

The final mistake I realized I had made was that I was trying to use a &quot;genericObjects&quot; payload with a classId that was an &quot;Event Ticket&quot; type.  Make sure to use &quot;eventTicketObjects&quot; json with &quot;Event Ticket&quot; type classes and &quot;genericObjects&quot; with &quot;Generic&quot; type classes!

Although eventually, I&#39;ll create this json on a server, I&#39;m currently mocking that out and creating it within my Flutter app using the code below:

        // &quot;email address&quot; that google created for your &quot;service account&quot; which you can 
        // find on https://console.cloud.google.com/apis/credentials
        const issuerEmail = &#39;google-wallet-my-proj@company-proj.iam.gserviceaccount.com&#39;;
    
        // update this with the issuerId found on pay.google.com/business/console
        const issuerId = &#39;3388000000012345678&#39;;
    
        // name of Google Wallet class you created on pay.google.com/business/console
        const className = &#39;GeneralAdmission&#39;;
        final passId = const Uuid().v4(); // random uuid
    
        final iat = DateTime.now().millisecondsSinceEpoch ~/ 1000;
        final json = &#39;&#39;&#39;
    {
    	&quot;iss&quot;: &quot;$issuerEmail&quot;,
    	&quot;aud&quot;: &quot;google&quot;,
    	&quot;typ&quot;: &quot;savetowallet&quot;,
    	&quot;iat&quot;: &quot;$iat&quot;,
    	&quot;origins&quot;: [],
    	&quot;payload&quot;: {
    		&quot;genericObjects&quot;: [{
    			&quot;id&quot;: &quot;$issuerId.$passId&quot;,
    			&quot;classId&quot;: &quot;$issuerId.$className&quot;,
    			&quot;genericType&quot;: &quot;GENERIC_TYPE_UNSPECIFIED&quot;,
    			&quot;cardTitle&quot;: {
    				&quot;defaultValue&quot;: {
    					&quot;language&quot;: &quot;en&quot;,
    					&quot;value&quot;: &quot;Card title&quot;
    				}
    			},
    			&quot;header&quot;: {
    				&quot;defaultValue&quot;: {
    					&quot;language&quot;: &quot;en&quot;,
    					&quot;value&quot;: &quot;header&quot;
    				}
    			},
    			&quot;subheader&quot;: {
    				&quot;defaultValue&quot;: {
    					&quot;language&quot;: &quot;en&quot;,
    					&quot;value&quot;: &quot;subheader&quot;
    				}
    			}
    		}]
    	}
    }
    &#39;&#39;&#39;;

</details>



huangapple
  • 本文由 发表于 2023年8月5日 06:37:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76839434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定