From 96abb65fc47868b7f73e01c80dce4495d94b21dd Mon Sep 17 00:00:00 2001 From: Pavel Tikhonenko Date: Mon, 17 May 2021 21:00:34 +0300 Subject: [PATCH] Check whether user is eligible for introductory offer (https://github.com/tikhop/TPInAppReceipt/issues/85) --- Sources/Extras.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sources/Extras.swift b/Sources/Extras.swift index 3b3879c..386897e 100644 --- a/Sources/Extras.swift +++ b/Sources/Extras.swift @@ -84,4 +84,27 @@ fileprivate class RefreshSession : NSObject, SKRequestDelegate } } +extension InAppReceipt +{ + /// Check whether user is eligible for introductory offer + /// + /// - Returns `false` if user isn't eligible for introductory offer, otherwise `true` + func isEligibleForIntroductoryOffer(for productIdentifiers: [String]) -> Bool + { + let purchases = purchases.filter { $0.subscriptionTrialPeriod || $0.subscriptionIntroductoryPricePeriod } + .filter { productIdentifiers.contains($0.productIdentifier) } + + return purchases.isEmpty + } + + /// Check whether user is eligible for introductory offer + /// + /// - Returns `false` if user isn't eligible for introductory offer, otherwise `true` + func isEligibleForIntroductoryOffer(for productIdentifier: String) -> Bool + { + let purchases = purchases.filter { ($0.subscriptionTrialPeriod || $0.subscriptionIntroductoryPricePeriod) && $0.productIdentifier == productIdentifier } + + return purchases.isEmpty + } +} #endif