Skip to content

Commit

Permalink
Add "is_upgraded" properties for ReceiptItem
Browse files Browse the repository at this point in the history
  • Loading branch information
ManyLattice committed Nov 24, 2021
1 parent b1c10c1 commit a86821e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Sources/SwiftyStoreKit/InAppReceipt.swift
Expand Up @@ -69,6 +69,7 @@ extension ReceiptItem {
} else {
self.isInIntroOfferPeriod = false
}
self.isUpgraded = receiptInfo["is_upgraded"] as? Bool ?? false
}

private static func parseDate(from receiptInfo: ReceiptInfo, key: String) -> Date? {
Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift
Expand Up @@ -219,7 +219,10 @@ public struct ReceiptItem: Purchased, Codable {
/// Indicates whether or not the subscription item is currently within an intro offer period.
public var isInIntroOfferPeriod: Bool

public init(productId: String, quantity: Int, transactionId: String, originalTransactionId: String, purchaseDate: Date, originalPurchaseDate: Date, webOrderLineItemId: String?, subscriptionExpirationDate: Date?, cancellationDate: Date?, isTrialPeriod: Bool, isInIntroOfferPeriod: Bool) {
/// An indicator that a subscription has been canceled due to an upgrade. This field is only present for upgrade transactions.
public var isUpgraded: Bool

public init(productId: String, quantity: Int, transactionId: String, originalTransactionId: String, purchaseDate: Date, originalPurchaseDate: Date, webOrderLineItemId: String?, subscriptionExpirationDate: Date?, cancellationDate: Date?, isTrialPeriod: Bool, isInIntroOfferPeriod: Bool, isUpgraded: Bool) {
self.productId = productId
self.quantity = quantity
self.transactionId = transactionId
Expand All @@ -231,6 +234,7 @@ public struct ReceiptItem: Purchased, Codable {
self.cancellationDate = cancellationDate
self.isTrialPeriod = isTrialPeriod
self.isInIntroOfferPeriod = isInIntroOfferPeriod
self.isUpgraded = isUpgraded
}
}

Expand Down
5 changes: 3 additions & 2 deletions Tests/SwiftyStoreKitTests/InAppReceiptTests.swift
Expand Up @@ -34,8 +34,8 @@ private extension TimeInterval {

extension ReceiptItem: Equatable {

init(productId: String, purchaseDate: Date, subscriptionExpirationDate: Date? = nil, cancellationDate: Date? = nil, isTrialPeriod: Bool = false, isInIntroOfferPeriod: Bool = false) {
self.init(productId: productId, quantity: 1, transactionId: UUID().uuidString, originalTransactionId: UUID().uuidString, purchaseDate: purchaseDate, originalPurchaseDate: purchaseDate, webOrderLineItemId: UUID().uuidString, subscriptionExpirationDate: subscriptionExpirationDate, cancellationDate: cancellationDate, isTrialPeriod: isTrialPeriod, isInIntroOfferPeriod: isInIntroOfferPeriod)
init(productId: String, purchaseDate: Date, subscriptionExpirationDate: Date? = nil, cancellationDate: Date? = nil, isTrialPeriod: Bool = false, isInIntroOfferPeriod: Bool = false, isUpgraded: Bool = false) {
self.init(productId: productId, quantity: 1, transactionId: UUID().uuidString, originalTransactionId: UUID().uuidString, purchaseDate: purchaseDate, originalPurchaseDate: purchaseDate, webOrderLineItemId: UUID().uuidString, subscriptionExpirationDate: subscriptionExpirationDate, cancellationDate: cancellationDate, isTrialPeriod: isTrialPeriod, isInIntroOfferPeriod: isInIntroOfferPeriod, isUpgraded: isUpgraded)
self.productId = productId
self.quantity = 1
self.purchaseDate = purchaseDate
Expand All @@ -47,6 +47,7 @@ extension ReceiptItem: Equatable {
self.webOrderLineItemId = UUID().uuidString
self.isTrialPeriod = isTrialPeriod
self.isInIntroOfferPeriod = isInIntroOfferPeriod
self.isUpgraded = isUpgraded
}

var receiptInfo: NSDictionary {
Expand Down

0 comments on commit a86821e

Please sign in to comment.