                 return (expirationDate, $0)
             }
         } else {
-            return receiptItems.compactMap {
-                if let expirationDate = $0.subscriptionExpirationDate {
-                    return (expirationDate, $0)
+            #if swift(>=4.1)
+                return receiptItems.compactMap {
+                    if let expirationDate = $0.subscriptionExpirationDate {
+                        return (expirationDate, $0)
+                    }
+                    return nil
                 }
-                return nil
-            }
+            #else
+                return receiptItems.compactMap {
+                    if let expirationDate = $0.subscriptionExpirationDate {
+                        return (expirationDate, $0)
+                    }
+                    return nil
+                }
+            #endif
         }
     }
 


        let receiptDate = getReceiptRequestDate(inReceipt: receipt) ?? date

        let receiptItems = nonCancelledReceiptsInfo.compactMap { ReceiptItem(receiptInfo: $0) }

        if nonCancelledReceiptsInfo.count > receiptItems.count {
            print("receipt has \(nonCancelledReceiptsInfo.count) items, but only \(receiptItems.count) were parsed")

        let filteredReceiptsInfo = filterReceiptsInfo(receipts: receipts, withProductIds: [productId])
        let nonCancelledReceiptsInfo = filteredReceiptsInfo.filter { receipt in receipt["cancellation_date"] == nil }

        #if swift(>=4.1)
            let receiptItems = nonCancelledReceiptsInfo.compactMap { ReceiptItem(receiptInfo: $0) }
        #else
            let receiptItems = nonCancelledReceiptsInfo.flatMap { ReceiptItem(receiptInfo: $0) }
        #endif
        
        // Verify that at least one receipt has the right product id
        if let firstItem = receiptItems.first {
            return .purchased(item: firstItem)
