         return purchasedProductIds.contains(productId)
     }
     
-    public func restoreCompletedTransactions(completion: RestoreTransactionsCompletionBlock) {
+    public func restoreCompletedTransactions(completion: @escaping RestoreTransactionsCompletionBlock) {
         restoreTransactionsCompletionBlock = completion
-        SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
-    }
-    
-    public func loadProductsWithIds(productIds: Array<String>, completion:LoadProductsCompletionBlock) {
+        SKPaymentQueue.default().restoreCompletedTransactions()
+    }
+    
+    public func loadProducts(productIds: Array<String>, completion:@escaping LoadProductsCompletionBlock) {
         var loadedProducts = Array<SKProduct>()
         var remainingIds = Array<String>()
         

        request.start()
    }
    
    public func purchaseProductWithId(productId: String, completion: PurchaseProductCompletionBlock) {
        if !canMakePayments() {
            let error = NSError(domain: "inapppurchase", code: 0, userInfo: [NSLocalizedDescriptionKey: "In App Purchasing is unavailable"])
            completion(error)
        } else {
            loadProductsWithIds([productId]) { (products, error) -> Void in
                if error != nil {
                    completion(error)
                } else {
                    if let product = products?.first {
                        self.purchaseProduct(product, completion: completion)
                    }
                }
            }
        }
    }
    
    public func purchaseProduct(product: SKProduct, completion: PurchaseProductCompletionBlock) {
        purchaseProductRequests.append(PurchaseProductRequestInfo(productId: product.productIdentifier, completion: completion))
        let payment = SKPayment(product: product)
        SKPaymentQueue.defaultQueue().addPayment(payment)
    }
    
    private func callLoadProductsCompletionForRequest(request: SKProductsRequest, responseProducts:Array<SKProduct>?, error: NSError?) {
        dispatch_async(dispatch_get_main_queue()) {
            for i in 0..<self.loadProductsRequests.count {
                let requestInfo = self.loadProductsRequests[i]
                if requestInfo.request == request {
                    self.loadProductsRequests.removeAtIndex(i)
                    requestInfo.completion(responseProducts, error)
                    return
                }


extension IAPManager { // Store file managment
    
    func purchasedItemsURL() -> URL {
        let documentsDirectory = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!
        return URL(string: documentsDirectory)!.appendingPathComponent("purchased.plist")
    }
    
    func purchasedItemsFilePath() -> String {
        return purchasedItemsURL().path
    }
    
    func restorePurchasedItems()  {
        if let items = NSKeyedUnarchiver.unarchiveObject(withFile: purchasedItemsFilePath()) as? Array<String> {
            purchasedProductIds.append(contentsOf: items)
        }
    }
    
    func savePurchasedItems() {
        let data = NSKeyedArchiver.archivedData(withRootObject: purchasedProductIds)
        do {
            try data.write(to: purchasedItemsURL(), options: [.atomicWrite, .completeFileProtection])
        } catch {
            print("Failed to save purchased items: \(error)")
        }
    }
}
