Files
purchases-ios/Sources/Purchasing/NonSubscriptionTransaction.swift
T
Cesar de la VegaandAndy Boedo 658782b68d Adds subscriptions to CustomerInfo (#4508)
* adds SubscriptionInfo

* fix nullabilities

* purchaseDate is not nullable

* add isActive

* add store

* add the product identifier

* add willRenew

* private extension

* made storeTransactionId nil

* fix tests and docs

* fix tests

* fix more tests

* fix compilation

* fix test

* API tests and other fixes

* Update Sources/Purchasing/NonSubscriptionTransaction.swift

Co-authored-by: Andy Boedo <andresboedo@gmail.com>

* use ProductIdentifier and subscriptionsByProductIdentifier

* fix lint

* disable file_length

---------

Co-authored-by: Andy Boedo <andresboedo@gmail.com>
2024-12-04 12:00:27 +01:00

71 lines
2.3 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.
///
/// This can be one of these types of product:
/// - Consumables
/// - Non-consumables
/// - Non-renewing subscriptions
@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 created by RevenueCat.
@objc public let transactionIdentifier: String
/// The unique identifier for the transaction created by the Store.
@objc public let storeTransactionIdentifier: String
/**
* The ``Store`` where this transaction was performed.
*/
@objc public let store: Store
init?(with transaction: CustomerInfoResponse.Transaction, productID: String) {
guard let transactionIdentifier = transaction.transactionIdentifier,
let storeTransactionIdentifier = transaction.storeTransactionIdentifier else {
Logger.error("Couldn't initialize NonSubscriptionTransaction. " +
"Reason: missing data: \(transaction).")
return nil
}
self.transactionIdentifier = transactionIdentifier
self.storeTransactionIdentifier = storeTransactionIdentifier
self.purchaseDate = transaction.purchaseDate
self.productIdentifier = productID
self.store = transaction.store
}
public override var description: String {
return """
<\(String(describing: NonSubscriptionTransaction.self)):
productIdentifier=\(self.productIdentifier)
purchaseDate=\(self.purchaseDate)
transactionIdentifier=\(self.transactionIdentifier)
storeTransactionIdentifier=\(self.storeTransactionIdentifier)
>
"""
}
}
extension NonSubscriptionTransaction: Sendable {}