英文:
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:
"Something went wrong. Please try again" and in the adb log I saw an error which said "Validate RPC failed". Support indicated that I needed to get my app added to their "allow-list" 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'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 "payload" 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't confuse your alpha-numeric merchant ID for your issuerId. The issuerId should be only digits such as: 3388000000012345678. You'll find this at the center of the Google Pay & 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's "id" value. The second place is as a prefix to the object's "classId" value.
I was specifying the "iat" value in the wrong format. It should be a numeric "unix_time" (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 "genericObjects" payload with a classId that was an "Event Ticket" type. Make sure to use "eventTicketObjects" json with "Event Ticket" type classes and "genericObjects" with "Generic" type classes!
Although eventually, I'll create this json on a server, I'm currently mocking that out and creating it within my Flutter app using the code below:
// "email address" that google created for your "service account" which you can
// find on https://console.cloud.google.com/apis/credentials
const issuerEmail = 'google-wallet-my-proj@company-proj.iam.gserviceaccount.com';
// update this with the issuerId found on pay.google.com/business/console
const issuerId = '3388000000012345678';
// name of Google Wallet class you created on pay.google.com/business/console
const className = 'GeneralAdmission';
final passId = const Uuid().v4(); // random 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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论