Skip to content

Commit 5d96d90

Browse files
committed
Add descriptions for IAP Store errors
1 parent 7d0aaa4 commit 5d96d90

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ private struct PurchaseError: LocalizedError {
119119
let error: Error
120120

121121
var errorDescription: String? {
122-
error.localizedDescription
122+
if let error = error as? LocalizedError {
123+
return error.errorDescription
124+
} else {
125+
return error.localizedDescription
126+
}
123127
}
124128
}
125129

Yosemite/Yosemite/Stores/InAppPurchaseStore.swift

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private extension InAppPurchaseStore {
280280
}
281281

282282
public extension InAppPurchaseStore {
283-
enum Errors: String, Error {
283+
enum Errors: Error, LocalizedError {
284284
/// The user canceled the IAP flow
285285
case userCancelled
286286

@@ -320,6 +320,51 @@ public extension InAppPurchaseStore {
320320
/// In-app purchases are not supported for this user
321321
///
322322
case inAppPurchasesNotSupported
323+
324+
public var errorDescription: String? {
325+
switch self {
326+
case .userCancelled:
327+
return NSLocalizedString(
328+
"Purchase cancelled by user",
329+
comment: "Error message used when the user cancelled an In-app purchase flow")
330+
case .pending:
331+
return NSLocalizedString(
332+
"Purchase pending",
333+
comment: "Error message used when the purchase is pending some user action")
334+
case .unknownResult:
335+
return NSLocalizedString(
336+
"Unexpected purchase result",
337+
comment: "Error message used when a purchase returned something unexpected that we don't know how to handle")
338+
case .unverifiedTransaction:
339+
return NSLocalizedString(
340+
"The purchase transaction couldn't be verified",
341+
comment: "Error message used when a purchase was successful but its transaction was unverified")
342+
case .transactionMissingAppAccountToken:
343+
return NSLocalizedString(
344+
"Purchase transaction missing account information",
345+
comment: "Error message used when the purchase transaction doesn't have the right metadata to associate to a specific site")
346+
case .appAccountTokenMissingSiteIdentifier:
347+
return NSLocalizedString(
348+
"Purchase transaction can't be associated to a site",
349+
comment: "Error message used when the purchase transaction doesn't have the right metadata to associate to a specific site")
350+
case .transactionProductUnknown:
351+
return NSLocalizedString(
352+
"Purchase transaction received for an unknown product",
353+
comment: "Error message used when we received a transaction for an unknown product")
354+
case .storefrontUnknown:
355+
return NSLocalizedString(
356+
"Couldn't determine App Stoure country",
357+
comment: "Error message used when we can't determine the user's App Store country")
358+
case .missingAppReceipt:
359+
return NSLocalizedString(
360+
"Couldn't retrieve app receipt",
361+
comment: "Error message used when we can't read the app receipt")
362+
case .inAppPurchasesNotSupported:
363+
return NSLocalizedString(
364+
"In-app purchases are not supported for this user yet",
365+
comment: "Error message used when In-app purchases are not supported for this user/site")
366+
}
367+
}
323368
}
324369

325370
enum Constants {

0 commit comments

Comments
 (0)