From caf6e451c28d5648a903c8d6e2c02122c704d041 Mon Sep 17 00:00:00 2001 From: Andrea Bizzotto Date: Sun, 12 Mar 2017 18:57:28 +0000 Subject: [PATCH] Filter out all receipts with "cancellation_date" != nil (#163) --- SwiftyStoreKit/InAppReceipt.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SwiftyStoreKit/InAppReceipt.swift b/SwiftyStoreKit/InAppReceipt.swift index bd191779..b95cbc6e 100644 --- a/SwiftyStoreKit/InAppReceipt.swift +++ b/SwiftyStoreKit/InAppReceipt.swift @@ -105,14 +105,15 @@ internal class InAppReceipt { // The values of the latest_receipt and latest_receipt_info keys are useful when checking whether an auto-renewable subscription is currently active. By providing any transaction receipt for the subscription and checking these values, you can get information about the currently-active subscription period. If the receipt being validated is for the latest renewal, the value for latest_receipt is the same as receipt-data (in the request) and the value for latest_receipt_info is the same as receipt. let (receipts, duration) = getReceiptsAndDuration(for: type, inReceipt: receipt) let receiptsInfo = filterReceiptsInfo(receipts: receipts, withProductId: productId) - if receiptsInfo.count == 0 { + let nonCancelledReceiptsInfo = receiptsInfo.filter { receipt in receipt["cancellation_date"] == nil } + if nonCancelledReceiptsInfo.count == 0 { return .notPurchased } let receiptDate = getReceiptRequestDate(inReceipt: receipt) ?? date // Return the expires dates sorted desc - let expiryDateValues = receiptsInfo + let expiryDateValues = nonCancelledReceiptsInfo .flatMap { (receipt) -> String? in let key: String = duration != nil ? "original_purchase_date_ms" : "expires_date_ms" return receipt[key] as? String