ios, android: word purchase errors for a purchase, not a code

This commit is contained in:
spaced4ndy committed 2026-10-01 14:12:05 +04:00
1 parent 94675cda8c
commit 8448bc28b5
8 files changed
+23 -11

No files matched your search

@@ -607,6 +607,7 @@ object ChatController {
suspend fun apiCreateBadgeInvoice(rh: Long?, userId: Long): String {
val r = sendCmd(rh, CC.ApiCreateBadgeInvoice(userId))
if (r is API.Result && r.res is CR.BadgeInvoice) return r.res.invoiceId
if (r is API.Error) throw BadgeStoreError.InvoiceRefused(r.err)
throw Exception("apiCreateBadgeInvoice: unexpected ${r.responseType}")
}
@@ -617,13 +618,15 @@ object ChatController {
}
// localized where the user can act on it; otherwise the error itself, so a screenshot says what happened
fun redeemErrorText(err: ChatError?): String {
fun redeemErrorText(err: ChatError?, purchase: Boolean): String {
if (err is ChatError.ChatErrorChat && err.errorType is ChatErrorType.CEBadgeRedeemError) {
when (val e = err.errorType.badgeRedeemError) {
is BadgeRedeemError.InvalidCode -> return generalGetString(MR.strings.badges_error_invalid_code)
is BadgeRedeemError.InvalidReceipt -> {}
is BadgeRedeemError.ServiceNotConfigured -> return generalGetString(MR.strings.badges_error_service_not_configured)
is BadgeRedeemError.BadgeActive -> return generalGetString(MR.strings.badges_error_already_active)
is BadgeRedeemError.ServiceNotConfigured ->
return generalGetString(if (purchase) MR.strings.badges_error_service_not_configured_purchase else MR.strings.badges_error_service_not_configured)
is BadgeRedeemError.BadgeActive ->
return generalGetString(if (purchase) MR.strings.badges_error_already_active_purchase else MR.strings.badges_error_already_active)
is BadgeRedeemError.ServiceError -> badgeServiceErrorText(e.serviceError)?.let { return it }
is BadgeRedeemError.InvalidResponse -> return String.format(generalGetString(MR.strings.badges_error_bad_service_response), e.message)
is BadgeRedeemError.UnknownKeyIndex, is BadgeRedeemError.CredentialNotVerified -> return generalGetString(MR.strings.badges_error_credential_not_verified)
@@ -100,7 +100,8 @@ private fun purchase(level: BadgeLevel, period: BadgePeriod, purchasing: Mutable
purchasing.value = false
AlertManager.shared.showAlertMsg(
title = generalGetString(MR.strings.badges_purchase_error),
text = e.toString()
text = if (e is BadgeStoreError.InvoiceRefused) chatModel.controller.redeemErrorText(e.err, purchase = true)
else "${generalGetString(MR.strings.error_prefix)}: ${e.message ?: e}"
)
}
}
@@ -85,7 +85,7 @@ suspend fun redeemBadgeCode(rhId: Long?, user: User, code: String): BadgeRedeemO
}
is BadgeRedeemResult.Failed -> {
Log.e(TAG, "apiRedeemBadgeCode: ${result.err?.string}")
BadgeRedeemOutcome.Refused(chatModel.controller.redeemErrorText(result.err))
BadgeRedeemOutcome.Refused(chatModel.controller.redeemErrorText(result.err, purchase = false))
}
}
@@ -3211,7 +3211,9 @@
<string name="badges_error_title">Cannot redeem code</string>
<string name="badges_error_invalid_code">This code is not valid.</string>
<string name="badges_error_service_not_configured">This app version cannot redeem badge codes.</string>
<string name="badges_error_service_not_configured_purchase">This app version cannot buy badges.</string>
<string name="badges_error_already_active">This profile already has a badge. Redeem the code on another profile, or once this badge ends.</string>
<string name="badges_error_already_active_purchase">This profile already has a badge. The purchase will be added when this badge ends.</string>
<string name="badges_error_code_invalid">This code was not recognized.</string>
<string name="badges_error_code_used">This code has already been used.</string>
<string name="badges_error_code_expired">This code has expired.</string>