Commit fddd00bb authored by Jose Blaya's avatar Jose Blaya
Browse files

Added `trialsEnabled` to decide from the backend when to show the trials

parent a0713643
......@@ -15,5 +15,7 @@ public struct AppStoreInformation {
public let isInIntroOfferPeriod: Bool
public let isTrialPeriod: Bool
public let trialsEnabled: Bool
}
......@@ -237,21 +237,35 @@ class PIAWebServices: WebServices, ConfigurationAccess {
}
if let availableJSONProducts = json["available_products"] as? [JSON] {
guard let products = [Product].from(jsonArray: availableJSONProducts) else {
callback?(nil, error)
return
}
let isIntroOffer = json["is_in_intro_offer_period"] as? Bool ?? false
let isTrialPeriod = json["is_trial_period"] as? Bool ?? false
guard let receipt = json["receipt"] as? [String: Any] else {
callback?(nil, error)
return
}
let isIntroOffer = receipt["is_in_intro_offer_period"] as? Bool ?? false
let isTrialPeriod = receipt["is_trial_period"] as? Bool ?? false
let trialsEnabled = json["trials_enabled"] as? Bool ?? false
let info = AppStoreInformation(products: products,
isInIntroOfferPeriod: isIntroOffer,
isTrialPeriod: isTrialPeriod)
isTrialPeriod: isTrialPeriod,
trialsEnabled: trialsEnabled)
//If either of these fields are true for a given subscription, the user is not eligible for an introductory offer on that subscription product or any other products within the same subscription group.
if info.isInIntroOfferPeriod || info.isTrialPeriod {
Client.configuration.eligibleForTrial = false
} else {
Client.configuration.eligibleForTrial = true
}
//Backend can disable the trials
Client.configuration.eligibleForTrial = trialsEnabled
callback?(info, nil)
} else {
callback?(nil, error)
......
......@@ -109,7 +109,8 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: false,
isTrialPeriod: false)
isTrialPeriod: false,
trialsEnabled: true)
}
webServices.appstoreInformationNotEligible = {
return AppStoreInformation(products: [Product(identifier: "com.product.monthly",
......@@ -117,7 +118,8 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: true,
isTrialPeriod: false)
isTrialPeriod: false,
trialsEnabled: true)
}
}
......
......@@ -85,6 +85,8 @@ class MockWebServices: WebServices {
} else {
Client.configuration.eligibleForTrial = true
}
Client.configuration.eligibleForTrial = result()!.trialsEnabled
callback?(result(), nil)
......
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