Files
purchases-ios/Sources/Purchasing/NonSubscriptionTransaction.swift
T
NachoSoto 8d88328d92 CustomerInfo: Sendable conformance (#1824)
The type is now immutable, so the compiler ensures it's thread-safe.

For [CSDK-379].
Extracted from #1795 to make it easier to review this in isolation.

[CSDK-379]: https://revenuecats.atlassian.net/browse/CSDK-379?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-08-22 16:00:59 -07:00

51 lines
1.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// NonPurchaseTransaction.swift
//
// Created by Nacho Soto on 6/23/22.
import Foundation
/// Information that represents a non-subscription purchase made by a user.
@objc(RCNonSubscriptionTransaction)
public final class NonSubscriptionTransaction: NSObject {
/// The product identifier.
@objc public let productIdentifier: String
/// The date that App Store charged the user’s account.
@objc public let purchaseDate: Date
/// The unique identifier for the transaction.
@objc public let transactionIdentifier: String
init?(with transaction: CustomerInfoResponse.Transaction, productID: String) {
guard let transactionIdentifier = transaction.transactionIdentifier,
let purchaseDate = transaction.purchaseDate else {
Logger.error("Couldn't initialize NonSubscriptionTransaction. " +
"Reason: missing data: \(transaction).")
return nil
}
self.transactionIdentifier = transactionIdentifier
self.purchaseDate = purchaseDate
self.productIdentifier = productID
}
}
#if swift(>=5.7)
extension NonSubscriptionTransaction: Sendable {}
#else
// `@unchecked` because:
// - `Date` is not `Sendable` until Swift 5.7
extension NonSubscriptionTransaction: @unchecked Sendable {}
#endif