Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Original app purchase date support #116

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sources/InAppReceipt+ASN1Decodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extension InAppReceiptPayload: ASN1Decodable
var bundleIdentifierData = Data()
var appVersion = ""
var originalAppVersion = ""
var originalPurchaseDate: Date?
var purchases = [InAppPurchase]()
var opaqueValue = Data()
var receiptHash = Data()
Expand Down Expand Up @@ -140,6 +141,9 @@ extension InAppReceiptPayload: ASN1Decodable
purchases.append(try valueContainer.decode(InAppPurchase.self))
case InAppReceiptField.originalAppVersion:
originalAppVersion = try valueContainer.decode(String.self)
case InAppReceiptField.originalAppPurchaseDate:
let originalPurchaseDateString = try valueContainer.decode(String.self, template: .universal(ASN1Identifier.Tag.ia5String))
originalPurchaseDate = originalPurchaseDateString.rfc3339date()
case InAppReceiptField.expirationDate:
let expirationDateString = try valueContainer.decode(String.self, template: .universal(ASN1Identifier.Tag.ia5String))
expirationDate = expirationDateString.rfc3339date()
Expand All @@ -161,6 +165,7 @@ extension InAppReceiptPayload: ASN1Decodable
self.init(bundleIdentifier: bundleIdentifier,
appVersion: appVersion,
originalAppVersion: originalAppVersion,
originalPurchaseDate: originalPurchaseDate,
purchases: purchases,
expirationDate: expirationDate,
bundleIdentifierData: bundleIdentifierData,
Expand Down
10 changes: 8 additions & 2 deletions Sources/InAppReceipt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct InAppReceiptField
static let ageRating: Int32 = 10 // SHA-1 Hash
static let receiptCreationDate: Int32 = 12
static let inAppPurchaseReceipt: Int32 = 17 // The receipt for an in-app purchase.
//TODO: case originalPurchaseDate = 18
static let originalAppPurchaseDate: Int32 = 18
static let originalAppVersion: Int32 = 19
static let expirationDate: Int32 = 21

Expand Down Expand Up @@ -101,7 +101,13 @@ public extension InAppReceipt
{
return payload.originalAppVersion
}


/// The date of the app that was originally purchased.
var originalPurchaseDate: Date?
{
return payload.originalPurchaseDate
}

/// In-app purchase's receipts
var purchases: [InAppPurchase]
{
Expand Down
8 changes: 6 additions & 2 deletions Sources/InAppReceiptPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ struct InAppReceiptPayload

/// The version of the app that was originally purchased.
let originalAppVersion: String


/// The date when the app orginaly purchased.
let originalPurchaseDate: Date?

/// The date that the app receipt expires
let expirationDate: Date?

Expand All @@ -49,11 +52,12 @@ struct InAppReceiptPayload

/// Initialize a `InAppReceipt` passing all values
///
init(bundleIdentifier: String, appVersion: String, originalAppVersion: String, purchases: [InAppPurchase], expirationDate: Date?, bundleIdentifierData: Data, opaqueValue: Data, receiptHash: Data, creationDate: Date, ageRating: String, environment: String, rawData: Data)
init(bundleIdentifier: String, appVersion: String, originalAppVersion: String, originalPurchaseDate: Date?, purchases: [InAppPurchase], expirationDate: Date?, bundleIdentifierData: Data, opaqueValue: Data, receiptHash: Data, creationDate: Date, ageRating: String, environment: String, rawData: Data)
{
self.bundleIdentifier = bundleIdentifier
self.appVersion = appVersion
self.originalAppVersion = originalAppVersion
self.originalPurchaseDate = originalPurchaseDate
self.purchases = purchases
self.expirationDate = expirationDate
self.bundleIdentifierData = bundleIdentifierData
Expand Down
8 changes: 7 additions & 1 deletion Sources/Objc/InAppReceipt+Objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ import TPInAppReceipt
{
return wrappedReceipt.originalAppVersion
}


/// The date of the app that was originally purchased.
var originalPurchaseDate: Date?
{
return wrappedReceipt.originalPurchaseDate
}

/// In-app purchase's receipts
var purchases: [InAppPurchase_Objc]
{
Expand Down
Loading