Commit 9125476a authored by Jose Blaya's avatar Jose Blaya
Browse files

Remove sandbox transactions in production

parent ca66c72a
......@@ -21,8 +21,6 @@
"failure.vc_title" = "Sign-up failed";
"failure.title" = "Account creation failed";
"failure.message" = "We're unable to create an account at this time. Please try again later. Reopening the app will re-attempt to create an account.";
"failure.environment.title" = "Invalid environment";
"failure.environment.message" = "Your have a sandbox receipt. Purchases with sandbox receipts are not available in Beta or Production builds.";
"failure.redeem.invalid.title" = "Invalid card PIN";
"failure.redeem.invalid.message" = "Looks like you entered an invalid card PIN. Please try again.";
"failure.redeem.claimed.title" = "Card claimed already";
......
......@@ -347,11 +347,6 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
// callback?(uncredited, nil)
// return
// }
if !Client.configuration.arePurchasesAvailable() {
callback?(nil, ClientError.invalidEnvironment)
return
}
self.accessedStore.purchaseProduct(product) { (transaction, error) in
guard let transaction = transaction else {
callback?(nil, error)
......@@ -363,12 +358,6 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
func restorePurchases(_ callback: SuccessLibraryCallback?) {
if !Client.configuration.arePurchasesAvailable() {
callback?(ClientError.invalidEnvironment)
return
}
accessedStore.refreshPaymentReceipt(callback)
}
......@@ -389,12 +378,19 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
return
}
guard let credentials = credentials else {
// If bad Receipt and purchases are not available, remove and clean the transaction from the queue
if error as? ClientError == .badReceipt,
let transaction = request.transaction,
!Client.configuration.arePurchasesAvailable() {
self.accessedStore.finishTransaction(transaction, success: false)
}
callback?(nil, error)
return
}
if let transaction = request.transaction {
self.accessedStore.finishTransaction(transaction, success: true)
}
self.accessedDatabase.plain.lastSignupEmail = nil
self.accessedDatabase.secure.setPublicUsername(credentials.username)
self.accessedDatabase.secure.setPassword(credentials.password, for: credentials.username)
......@@ -525,17 +521,19 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
callback?(nil, ClientError.noReceipt)
return
}
if !Client.configuration.arePurchasesAvailable() {
callback?(nil, ClientError.invalidEnvironment)
return
}
webServices.processPayment(credentials: user.credentials, request: payment) { (error) in
if let _ = error {
if let error = error {
// If bad Receipt and purchases are not available, remove and clean the transaction from the queue
if error as? ClientError == .badReceipt,
let transaction = request.transaction,
!Client.configuration.arePurchasesAvailable() {
self.accessedStore.finishTransaction(transaction, success: false)
}
callback?(nil, error)
return
}
if let transaction = request.transaction {
self.accessedStore.finishTransaction(transaction, success: true)
}
......
......@@ -297,7 +297,7 @@ extension Client {
public func arePurchasesAvailable() -> Bool {
if let url = Bundle.main.appStoreReceiptURL,
url.lastPathComponent == "sandboxReceipt",
!isDevelopment {
Client.environment == .production {
return false
}
return true
......
......@@ -60,7 +60,5 @@ public enum ClientError: String, Error {
/// Invalid parameter
case invalidParameter
/// Invalid environment
case invalidEnvironment
#endif
}
......@@ -93,11 +93,6 @@ class PIAWebServices: WebServices, ConfigurationAccess {
400: .badReceipt
]
if !Client.configuration.arePurchasesAvailable() {
callback?(nil, ClientError.invalidEnvironment)
return
}
req(nil, .post, endpoint, parameters, status, JSONRequestExecutor() { (json, status, error) in
if let knownError = self.knownError(endpoint, status, errors) {
callback?(nil, knownError)
......@@ -165,11 +160,6 @@ class PIAWebServices: WebServices, ConfigurationAccess {
400: .badReceipt
]
if !Client.configuration.arePurchasesAvailable() {
callback?(ClientError.invalidEnvironment)
return
}
req(credentials, .post, endpoint, parameters, status, JSONRequestExecutor() { (json, status, error) in
if let knownError = self.knownError(endpoint, status, errors) {
callback?(knownError)
......
......@@ -21,12 +21,6 @@ internal enum L10n {
internal static let title = L10n.tr("Signup", "failure.title")
/// Sign-up failed
internal static let vcTitle = L10n.tr("Signup", "failure.vc_title")
internal enum Environment {
/// Your have a sandbox receipt. Purchases with sandbox receipts are not available in Beta or Production builds.
internal static let message = L10n.tr("Signup", "failure.environment.message")
/// Invalid environment
internal static let title = L10n.tr("Signup", "failure.environment.title")
}
internal enum Redeem {
internal enum Claimed {
/// Looks like this card has already been claimed by another account. You can try entering a different PIN.
......
......@@ -161,9 +161,6 @@ public class ConfirmVPNPlanViewController: AutolayoutViewController, BrandableNa
if let error = error {
var message = error.localizedDescription
log.error("Purchase failed (error: \(error))")
if error as? ClientError == ClientError.invalidEnvironment {
message = L10n.Signup.Failure.Environment.message
}
Macros.displayImageNote(withImage: Asset.iconWarning.image,
message: message)
} else {
......
......@@ -136,9 +136,6 @@ public class RestoreSignupViewController: AutolayoutViewController, BrandableNav
private func reportRestoreFailure(_ optionalError: Error?) {
var message = optionalError?.localizedDescription ?? L10n.Welcome.Iap.Error.title
if let error = optionalError {
if error as? ClientError == ClientError.invalidEnvironment {
message = L10n.Signup.Failure.Environment.message
}
log.error("Failed to restore payment receipt (error: \(error))")
} else {
log.error("Failed to restore payment receipt")
......
......@@ -35,10 +35,6 @@ public class SignupFailureViewController: AutolayoutViewController, BrandableNav
labelTitle.text = L10n.Signup.Failure.Redeem.Invalid.title
labelMessage.text = L10n.Signup.Failure.Redeem.Invalid.message
break
case .invalidEnvironment:
labelTitle.text = L10n.Signup.Failure.Environment.title
labelMessage.text = L10n.Signup.Failure.Environment.message
break
case .redeemClaimed:
title = L10n.Welcome.Redeem.title
imvPicture.image = Asset.imageRedeemClaimed.image
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment