Commit 03cf0f45 authored by Jose Blaya's avatar Jose Blaya
Browse files

Check if environment is production and the user is using a sandbox receipt

parent 7cd787b4
......@@ -21,6 +21,8 @@
"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 are not available in Beta 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";
......
......@@ -290,6 +290,19 @@ extension Client {
return availableVPNProfiles.first { $0.vpnType == type }
}
/**
Returns true if the purchase feature is available
- Returns: A boolean indicating if purchases are available.
*/
public func arePurchasesAvailable() -> Bool {
if let url = Bundle.main.appStoreReceiptURL,
url.lastPathComponent == "sandboxReceipt",
Client.environment == .production {
return false
}
return true
}
#if os(iOS)
// MARK: InApp
......
......@@ -59,5 +59,8 @@ public enum ClientError: String, Error {
/// Invalid parameter
case invalidParameter
/// Invalid environment
case invalidEnvironment
#endif
}
......@@ -93,6 +93,11 @@ 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)
......@@ -159,6 +164,11 @@ class PIAWebServices: WebServices, ConfigurationAccess {
let errors: [Int: ClientError] = [
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) {
......
......@@ -21,6 +21,12 @@ 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 {
/// Purchases are not available in Beta 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.
......
......@@ -35,7 +35,10 @@ 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