Skip to content

Commit

Permalink
Add extra method for retrieving active subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tikhop committed May 11, 2022
1 parent 5b22e31 commit 51cc7ec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/Mercato/Mercato.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ extension Mercato
try await AppStore.showManageSubscriptions(in: scene)
}

public static func activeSubscriptions(onlyRenewable: Bool = true) async throws -> [String]
public static func activeSubscriptions(onlyRenewable: Bool = true) async throws -> [Transaction]
{
var productIds: Set<String> = []
var txs: [Transaction] = []

for await result in Transaction.currentEntitlements
{
Expand All @@ -148,15 +148,20 @@ extension Mercato
if transaction.productType == .autoRenewable ||
(!onlyRenewable && transaction.productType == .nonRenewable)
{
productIds.insert(transaction.productID)
txs.append(transaction)
}
} catch {
throw error
}
}

return Array(productIds)
return Array(txs)
}

public static func activeSubscriptionIds(onlyRenewable: Bool = true) async throws -> [String]
{
return try await activeSubscriptions(onlyRenewable: onlyRenewable).map { $0.productID}
}
}


Expand Down

0 comments on commit 51cc7ec

Please sign in to comment.