Commit 3f899190 authored by Jose Blaya's avatar Jose Blaya
Browse files

Refactor

parent 015c5115
......@@ -12,10 +12,6 @@ public struct AppStoreInformation {
public let products: [Product]
public let isInIntroOfferPeriod: Bool
public let isTrialPeriod: Bool
public let trialsEnabled: Bool
public let eligibleForTrial: Bool
}
......@@ -226,7 +226,7 @@ class PIAWebServices: WebServices, ConfigurationAccess {
parameters["receipt"] = receipt.base64EncodedString()
}
req(nil, .get, endpoint, useAuthToken: false, parameters, status, JSONRequestExecutor() { (json, status, error) in
req(nil, .post, endpoint, useAuthToken: false, parameters, status, JSONRequestExecutor() { (json, status, error) in
if let knownError = self.knownError(endpoint, status, errors) {
callback?(nil, knownError)
return
......@@ -243,25 +243,12 @@ class PIAWebServices: WebServices, ConfigurationAccess {
return
}
let trialsEnabled = json["trial_enabled"] as? Bool ?? false
let receipt = json["receipt"] as? [String: Any] ?? [:]
let isIntroOffer = receipt["is_in_intro_offer_period"] as? Bool ?? false
let isTrialPeriod = receipt["is_trial_period"] as? Bool ?? false
let eligibleForTrial = receipt["eligible_for_trial"] as? Bool ?? false
let info = AppStoreInformation(products: products,
isInIntroOfferPeriod: isIntroOffer,
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 and override the previous value
Client.configuration.eligibleForTrial = info.trialsEnabled
eligibleForTrial: eligibleForTrial)
Client.configuration.eligibleForTrial = info.eligibleForTrial
callback?(info, nil)
} else {
......
......@@ -108,27 +108,21 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
plan: .monthly,
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: false,
isTrialPeriod: false,
trialsEnabled: true)
eligibleForTrial: true)
}
webServices.appstoreInformationEligibleButDisabledFromBackend = {
return AppStoreInformation(products: [Product(identifier: "com.product.monthly",
plan: .monthly,
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: false,
isTrialPeriod: false,
trialsEnabled: false)
eligibleForTrial: false)
}
webServices.appstoreInformationNotEligible = {
return AppStoreInformation(products: [Product(identifier: "com.product.monthly",
plan: .monthly,
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: true,
isTrialPeriod: false,
trialsEnabled: true)
eligibleForTrial: false)
}
}
......
......@@ -86,13 +86,7 @@ class MockWebServices: WebServices {
}
}
if result()!.isInIntroOfferPeriod || result()!.isTrialPeriod {
Client.configuration.eligibleForTrial = false
} else {
Client.configuration.eligibleForTrial = true
}
Client.configuration.eligibleForTrial = result()!.trialsEnabled
Client.configuration.eligibleForTrial = result()!.eligibleForTrial
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