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

Update api to return information about the trial status

parent 78663b69
......@@ -268,6 +268,7 @@
DD56E3F6225F5D77002EDFB2 /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD56E3F5225F5D77002EDFB2 /* Product.swift */; };
DD58F4BB21AEB99C00D043F7 /* GlossToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BA21AEB99C00D043F7 /* GlossToken.swift */; };
DD58F4BD21AEF76100D043F7 /* String+Components.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BC21AEF76100D043F7 /* String+Components.swift */; };
DD6768E322FAB19D00B9FDD0 /* AppStoreInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6768E222FAB19D00B9FDD0 /* AppStoreInformation.swift */; };
DD6DC5B921B6A83400F9D538 /* UIViewLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6DC5B821B6A83400F9D538 /* UIViewLoading.swift */; };
DD6DC5BC21B6A8FC00F9D538 /* pia-spinner.json in Resources */ = {isa = PBXBuildFile; fileRef = DD6DC5BB21B6A8FC00F9D538 /* pia-spinner.json */; };
DD6FB0372224355600A84F05 /* UIDevice+WiFi.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */; };
......@@ -567,6 +568,7 @@
DD56E3F5225F5D77002EDFB2 /* Product.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Product.swift; sourceTree = "<group>"; };
DD58F4BA21AEB99C00D043F7 /* GlossToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlossToken.swift; sourceTree = "<group>"; };
DD58F4BC21AEF76100D043F7 /* String+Components.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Components.swift"; sourceTree = "<group>"; };
DD6768E222FAB19D00B9FDD0 /* AppStoreInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStoreInformation.swift; sourceTree = "<group>"; };
DD6DC5B821B6A83400F9D538 /* UIViewLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewLoading.swift; sourceTree = "<group>"; };
DD6DC5BB21B6A8FC00F9D538 /* pia-spinner.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "pia-spinner.json"; sourceTree = "<group>"; };
DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+WiFi.swift"; sourceTree = "<group>"; };
......@@ -829,6 +831,7 @@
0EC849C81F82329F002480CA /* WebServices.swift */,
DD76292721ECDFF80092DF50 /* Usage.swift */,
DD56E3F5225F5D77002EDFB2 /* Product.swift */,
DD6768E222FAB19D00B9FDD0 /* AppStoreInformation.swift */,
DDC0840F22EB077400DA2701 /* InvitesInformation.swift */,
DDC0840C22EB06F400DA2701 /* Invites.swift */,
);
......@@ -1450,10 +1453,8 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-PIALibrary-PIALibraryTests-iOS/Pods-PIALibrary-PIALibraryTests-iOS-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-PIALibrary-PIALibraryTests-iOS/Pods-PIALibrary-PIALibraryTests-iOS-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/DynamicBlurView/DynamicBlurView.framework",
"${BUILT_PRODUCTS_DIR}/Gloss/Gloss.framework",
......@@ -1467,8 +1468,6 @@
"${BUILT_PRODUCTS_DIR}/lottie-ios/Lottie.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DynamicBlurView.framework",
......@@ -1484,7 +1483,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PIALibrary-PIALibraryTests-iOS/Pods-PIALibrary-PIALibraryTests-iOS-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PIALibrary-PIALibraryTests-iOS/Pods-PIALibrary-PIALibraryTests-iOS-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9D0059CEB01BB1B3D7E8C974 /* [CP] Check Pods Manifest.lock */ = {
......@@ -1558,10 +1557,8 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-PIALibrary-PIALibraryHost-iOS/Pods-PIALibrary-PIALibraryHost-iOS-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-PIALibrary-PIALibraryHost-iOS/Pods-PIALibrary-PIALibraryHost-iOS-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/DynamicBlurView/DynamicBlurView.framework",
"${BUILT_PRODUCTS_DIR}/Gloss/Gloss.framework",
......@@ -1575,8 +1572,6 @@
"${BUILT_PRODUCTS_DIR}/lottie-ios/Lottie.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DynamicBlurView.framework",
......@@ -1592,7 +1587,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PIALibrary-PIALibraryHost-iOS/Pods-PIALibrary-PIALibraryHost-iOS-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PIALibrary-PIALibraryHost-iOS/Pods-PIALibrary-PIALibraryHost-iOS-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
......@@ -1828,6 +1823,7 @@
DD76292821ECDFF80092DF50 /* Usage.swift in Sources */,
0E2ADD3A1FE14F8600BB170C /* VPNProfile.swift in Sources */,
0E492C5C1FE5EA06007F23DF /* CMacros.m in Sources */,
DD6768E322FAB19D00B9FDD0 /* AppStoreInformation.swift in Sources */,
0EB8C0671F9CD38B005857E4 /* AutolayoutViewController.swift in Sources */,
0E3D13D31F9E270A00434A48 /* GlossAccountInfo.swift in Sources */,
0E245C9D1FECF0C20010DEF2 /* ClientAccess.swift in Sources */,
......
......@@ -182,11 +182,11 @@ public protocol AccountProvider: class {
func listRenewablePlans(_ callback: LibraryCallback<[Plan]>?)
/**
Lists plans available for purchase or renewal in the PIA database.
Lists plans available from the AppStore and information about the purchase.
- Parameter callback: Returns a list of available plans.
- Parameter callback: Returns a AppStoreInformation object containing the list of available products and information about the status of the trial.
*/
func updatePlanProductIdentifiers(_ callback: LibraryCallback<[Product]>?)
func subscriptionInformation(_ callback: LibraryCallback<AppStoreInformation>?)
/**
Renews expiring plan with current purchase history.
......
//
// AppStoreInformation.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 07/08/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import Foundation
public struct AppStoreInformation {
public let products: [Product]
public let isInIntroOfferPeriod: Bool
public let isTrialPeriod: Bool
}
......@@ -32,7 +32,7 @@ protocol WebServices: class {
// MARK: Store
func planProductIdentifiers(_ callback: LibraryCallback<[Product]>?)
func subscriptionInformation(with receipt: Data?, _ callback: LibraryCallback<AppStoreInformation>?)
// MARK: Ephemeral
......
......@@ -294,18 +294,20 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
#if os(iOS)
func updatePlanProductIdentifiers(_ callback: LibraryCallback<[Product]>?) {
func subscriptionInformation(_ callback: LibraryCallback<AppStoreInformation>?) {
log.debug("Fetching available product keys...")
webServices.planProductIdentifiers({ products, error in
let receipt = accessedStore.paymentReceipt
webServices.subscriptionInformation(with: receipt, { appStoreInformation, error in
if let _ = error {
callback?(nil, error)
return
}
if let products = products,
products.count > 0 {
callback?(products, nil)
if let appStoreInformation = appStoreInformation {
callback?(appStoreInformation, nil)
} else {
callback?(nil, ClientError.malformedResponseData)
}
......
......@@ -211,16 +211,20 @@ class PIAWebServices: WebServices, ConfigurationAccess {
}
// MARK: Store
func planProductIdentifiers(_ callback: LibraryCallback<[Product]>?) {
func subscriptionInformation(with receipt: Data?, _ callback: LibraryCallback<AppStoreInformation>?) {
let endpoint = ClientEndpoint.ios
let status = [200, 400]
let errors: [Int: ClientError] = [
400: .badReceipt
]
let parameters: JSON = [
var parameters: JSON = [
"type": "subscription"
]
if let receipt = receipt {
parameters["receipt"] = receipt
}
req(nil, .get, endpoint, useAuthToken: false, parameters, status, JSONRequestExecutor() { (json, status, error) in
if let knownError = self.knownError(endpoint, status, errors) {
......@@ -237,7 +241,12 @@ class PIAWebServices: WebServices, ConfigurationAccess {
callback?(nil, error)
return
}
callback?(products, nil)
let isIntroOffer = json["is_in_intro_offer_period"] as? Bool ?? false
let isTrialPeriod = json["is_trial_period"] as? Bool ?? false
let info = AppStoreInformation(products: products,
isInIntroOfferPeriod: isIntroOffer,
isTrialPeriod: isTrialPeriod)
callback?(info, nil)
} else {
callback?(nil, error)
return
......
......@@ -226,9 +226,9 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
}
/// :nodoc:
public func updatePlanProductIdentifiers(_ callback: LibraryCallback<[Product]>?) {
delegate.updatePlanProductIdentifiers(callback)
}
public func subscriptionInformation(_ callback: LibraryCallback<AppStoreInformation>?) {
delegate.subscriptionInformation(callback)
}
/// :nodoc:
public func signup(with request: SignupRequest, _ callback: ((UserAccount?, Error?) -> Void)?) {
......
......@@ -67,8 +67,14 @@ class MockWebServices: WebServices {
callback?(nil)
}
func planProductIdentifiers(_ callback: LibraryCallback<[Product]>?) {
callback?([Product(identifier: "com.product.monthly", plan: .monthly, price: "3.99", legacy: false)], nil)
func subscriptionInformation(with receipt: Data?, _ callback: LibraryCallback<AppStoreInformation>?) {
let appstoreInfo = AppStoreInformation(products: [Product(identifier: "com.product.monthly",
plan: .monthly,
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: false,
isTrialPeriod: false)
callback?(appstoreInfo, nil)
}
func invitesInformation(_ callback: LibraryCallback<InvitesInformation>?) {
......
......@@ -331,7 +331,7 @@ class EphemeralAccountProvider: AccountProvider, ProvidersAccess, InAppAccess {
fatalError("Not implemented")
}
func updatePlanProductIdentifiers(_ callback: LibraryCallback<[Product]>?) {
func subscriptionInformation(_ callback: LibraryCallback<AppStoreInformation>?) {
fatalError("Not implemented")
}
......
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