Skip to content

Commit

Permalink
Merge pull request #116 from czarny/master
Browse files Browse the repository at this point in the history
feat: Original app purchase date support
  • Loading branch information
tikhop authored Feb 1, 2024
2 parents c65a8b5 + cac248c commit 5680945
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
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

0 comments on commit 5680945

Please sign in to comment.