Skip to content

Commit

Permalink
feat: StoreKit2 - add environment property into TransactionSk2 (#2281)
Browse files Browse the repository at this point in the history
* feat: StoreKit2 - add environment property into TransactionSk2

* fix: TransactionSk2.environment type and add availability comment for one

* fix: consider tvOS availability as well
  • Loading branch information
zarv1k committed Mar 13, 2023
1 parent e6713f4 commit af47b72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ios/IapSerializationUtils.swift
Expand Up @@ -138,12 +138,24 @@ func serialize(_ ot: Product.SubscriptionOffer.OfferType?) -> String? {
}
@available(iOS 15.0, tvOS 15.0, *)
func serialize(_ t: Transaction) -> [String: Any?] {
var environment: String?

if #available(iOS 16.0, tvOS 16.0, *) {
environment = t.environment.rawValue
} else {
let env = t.environmentStringRepresentation
if ["Production", "Sandbox", "Xcode"].contains(env) {
environment = env
}
}

return ["appAccountToken": t.appAccountToken?.uuidString,
"appBundleID": t.appBundleID,
"debugDescription": serializeDebug(t.debugDescription),
"deviceVerification": t.deviceVerification,
"deviceVerificationNonce": t.deviceVerificationNonce.uuidString,
"expirationDate": t.expirationDate?.millisecondsSince1970,
"environment": environment,
"id": t.id,
"isUpgraded": t.isUpgraded,
"jsonRepresentation": serializeDebug(t.jsonRepresentation),
Expand Down
1 change: 1 addition & 0 deletions src/types/appleSk2.ts
Expand Up @@ -96,6 +96,7 @@ export type TransactionSk2 = {
deviceVerification: string;
deviceVerificationNonce: string;
expirationDate: number;
environment?: 'Production' | 'Sandbox' | 'Xcode'; // Could be undefined in some cases on iOS 15, but it's stable since iOS 16
id: number;
isUpgraded: boolean;
jsonRepresentation: string;
Expand Down

0 comments on commit af47b72

Please sign in to comment.