【发布时间】:2022-08-24 03:26:36
【问题描述】:
我正在尝试创建一个这样的应用程序来将我的票证保存在谷歌钱包https://codelabs.developers.google.com/add-to-wallet-android#0 中。我已完成所有步骤,但我无法得到结果。 Google pay button is not visible
实际上,我的手机上有一个 google pay,但它显示“不幸的是,此手机上没有 google pay”,并且应用程序中看不到 google pay 按钮。所以我手动启用了谷歌支付按钮。当我单击它时显示错误“发生意外错误。请稍后再试。[OR_BIBED_07]。如何解决此错误。
这是我的代码
*这使谷歌支付可见
private fun setGooglePayAvailable(available: Boolean) {
if (available) {
googlePayButton.visibility = View.VISIBLE
} else {
Toast.makeText(
this,
R.string.google_pay_status_unavailable,
Toast.LENGTH_LONG).show()
googlePayButton.visibility = View.VISIBLE
}
}
*onClick google pay 按钮
private fun requestPayment() {
// Disables the button to prevent multiple clicks.
googlePayButton.isClickable = false
// The price provided to the API should include taxes and shipping.
// This price is not displayed to the user.
val dummyPriceCents = 100L
val shippingCostCents = 900L
val task = model.getLoadPaymentDataTask(dummyPriceCents + shippingCostCents)
task.addOnCompleteListener { completedTask ->
if (completedTask.isSuccessful) {
completedTask.result.let(::handlePaymentSuccess)
} else {
when (val exception = completedTask.exception) {
is ResolvableApiException -> {
resolvePaymentForResult.launch(
IntentSenderRequest.Builder(exception.resolution).build()
)
}
is ApiException -> {
handleError(exception.statusCode, exception.message)
}
else -> {
handleError(
CommonStatusCodes.INTERNAL_ERROR, \"Unexpected non API\" +
\" exception when trying to deliver the task result to an activity!\"
)
}
}
}
// Re-enables the Google Pay payment button.
googlePayButton.isClickable = true
}
}
*我的谷歌钱包按钮
private fun setAddToGoogleWalletAvailable(available: Boolean) {
if (available) {
layout.passContainer.visibility = View.VISIBLE
} else {
Toast.makeText(
this,
R.string.google_wallet_status_unavailable,
Toast.LENGTH_LONG).show()
}
}
同样,当我启用谷歌钱包按钮时。当我单击它时,它甚至没有响应。它实际上应该将我的通行证保存在谷歌钱包中
*OnClick 钱包按钮
private fun requestSavePass() {
// Disables the button to prevent multiple clicks.
addToGoogleWalletButton.isClickable = false
model.savePassesJwt(model.genericObjectJwt, this, addToGoogleWalletRequestCode)
}
我发送的 Json 对象
private val issuerEmail = \"irfan*********@gmail.com\"
private val issuerId = \"338800000002212****\"
private val passClass = \"338800000002212****.e7504e23-****-4852-b8e4-9345684a2e06\"
private val passId = UUID.randomUUID().toString()
private val newObjectJson = \"\"\"
{
\"iss\": \"$issuerEmail\",
\"aud\": \"google\",
\"typ\": \"savetowallet\",
\"iat\": ${Date().time / 1000L},
\"origins\": [],
\"payload\": {
\"genericObjects\": [
{
\"id\": \"$issuerId.$passId\",
\"classId\": \"$passClass\",
\"genericType\": \"GENERIC_TYPE_UNSPECIFIED\",
\"hexBackgroundColor\": \"#4285f4\",
\"logo\": {
\"sourceUri\": {
\"uri\": \"https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg\"
}
},
\"cardTitle\": {
\"defaultValue\": {
\"language\": \"en\",
\"value\": \"Google I/O \'22 [DEMO ONLY]\"
}
},
\"subheader\": {
\"defaultValue\": {
\"language\": \"en\",
\"value\": \"Attendee\"
}
},
\"header\": {
\"defaultValue\": {
\"language\": \"en\",
\"value\": \"Alex McJacobs\"
}
},
\"barcode\": {
\"type\": \"QR_CODE\",
\"value\": \"$passId\"
},
\"heroImage\": {
\"sourceUri\": {
\"uri\": \"https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/google-io-hero-demo-only.jpg\"
}
},
\"textModulesData\": [
{
\"header\": \"POINTS\",
\"body\": \"${Random.nextInt(0, 9999)}\",
\"id\": \"points\"
},
{
\"header\": \"CONTACTS\",
\"body\": \"${Random.nextInt(1, 99)}\",
\"id\": \"contacts\"
}
]
}
]
}
}
\"\"\"
由于我在印度,它不适合我吗?
标签: android android-pay google-pay wallet wallet-connect