Skip to content

Commit

Permalink
Merge pull request #428 from qonversion/feature/entitlementsUpdate
Browse files Browse the repository at this point in the history
Updated entitlements fields and added transactions array
  • Loading branch information
suriksarkisyan authored Dec 28, 2023
2 parents 1ed7854 + 1f34f51 commit 48f4439
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 11 deletions.
12 changes: 12 additions & 0 deletions Qonversion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
70A26ADF2A31BC44008CE4A7 /* QONExperiment.m in Sources */ = {isa = PBXBuildFile; fileRef = 70A26ADD2A31BC44008CE4A7 /* QONExperiment.m */; };
70ADE70F2951CC7200CB4D2E /* QONScreenPresentationConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 70ADE70D2951CC7200CB4D2E /* QONScreenPresentationConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
70ADE7102951CC7200CB4D2E /* QONScreenPresentationConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 70ADE70E2951CC7200CB4D2E /* QONScreenPresentationConfiguration.m */; };
70B917642B3314BD00BF0689 /* QONTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = 70B917622B3314BD00BF0689 /* QONTransaction.h */; settings = {ATTRIBUTES = (Public, ); }; };
70B917652B3314BD00BF0689 /* QONTransaction.m in Sources */ = {isa = PBXBuildFile; fileRef = 70B917632B3314BD00BF0689 /* QONTransaction.m */; };
70B917672B34284200BF0689 /* QONTransaction+Protected.h in Headers */ = {isa = PBXBuildFile; fileRef = 70B917662B34284200BF0689 /* QONTransaction+Protected.h */; };
70B9A9F1297AB8A700BD30FD /* QONAutomationsNavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 70B9A9EF297AB8A700BD30FD /* QONAutomationsNavigationController.h */; };
70B9A9F2297AB8A700BD30FD /* QONAutomationsNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 70B9A9F0297AB8A700BD30FD /* QONAutomationsNavigationController.m */; };
70D05A8E29C9FC1600EA5DDF /* QONRemoteConfigManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 70D05A8C29C9FC1600EA5DDF /* QONRemoteConfigManager.h */; };
Expand Down Expand Up @@ -372,6 +375,9 @@
70A26ADD2A31BC44008CE4A7 /* QONExperiment.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QONExperiment.m; sourceTree = "<group>"; };
70ADE70D2951CC7200CB4D2E /* QONScreenPresentationConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QONScreenPresentationConfiguration.h; sourceTree = "<group>"; };
70ADE70E2951CC7200CB4D2E /* QONScreenPresentationConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QONScreenPresentationConfiguration.m; sourceTree = "<group>"; };
70B917622B3314BD00BF0689 /* QONTransaction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QONTransaction.h; sourceTree = "<group>"; };
70B917632B3314BD00BF0689 /* QONTransaction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QONTransaction.m; sourceTree = "<group>"; };
70B917662B34284200BF0689 /* QONTransaction+Protected.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "QONTransaction+Protected.h"; sourceTree = "<group>"; };
70B9A9EF297AB8A700BD30FD /* QONAutomationsNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QONAutomationsNavigationController.h; sourceTree = "<group>"; };
70B9A9F0297AB8A700BD30FD /* QONAutomationsNavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QONAutomationsNavigationController.m; sourceTree = "<group>"; };
70D05A8C29C9FC1600EA5DDF /* QONRemoteConfigManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QONRemoteConfigManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -940,6 +946,8 @@
895731BC26DD03A2009507A6 /* QONIntroEligibility.h */,
895731BE26DD03A2009507A6 /* QONStoreKitSugare.h */,
895731BF26DD03A2009507A6 /* QONEntitlement.h */,
70B917622B3314BD00BF0689 /* QONTransaction.h */,
70B917632B3314BD00BF0689 /* QONTransaction.m */,
895731C026DD03A2009507A6 /* QONLaunchResult.h */,
895731C126DD03A2009507A6 /* QONExperimentGroup.m */,
895731C326DD03A2009507A6 /* QONAutomations.m */,
Expand Down Expand Up @@ -1322,6 +1330,7 @@
702DBDEB2A3216C900D590D0 /* QONExperiment+Protected.h */,
8957324226DD03A3009507A6 /* QONUser+Protected.h */,
701922752B10AB3300724926 /* QONSubscriptionPeriod+Protected.h */,
70B917662B34284200BF0689 /* QONTransaction+Protected.h */,
8957324326DD03A3009507A6 /* QONOfferings+Protected.h */,
8957324526DD03A3009507A6 /* QONOffering+Protected.h */,
8957324726DD03A3009507A6 /* QONIntroEligibility+Protected.h */,
Expand Down Expand Up @@ -1575,6 +1584,7 @@
8957328626DD03A3009507A6 /* QONAutomationsEvent.h in Headers */,
8957329826DD03A3009507A6 /* QONAutomationsEventType.h in Headers */,
6A21BF4C2AB201A7005BDA7C /* QONRateLimiter.h in Headers */,
70B917672B34284200BF0689 /* QONTransaction+Protected.h in Headers */,
895732B426DD03A3009507A6 /* QONAutomationsService.h in Headers */,
895732CA26DD03A3009507A6 /* QNUtils.h in Headers */,
8957328126DD03A3009507A6 /* QONEntitlement.h in Headers */,
Expand Down Expand Up @@ -1640,6 +1650,7 @@
8957330126DD03A3009507A6 /* QNUserInfoServiceInterface.h in Headers */,
895732C926DD03A3009507A6 /* QNInternalConstants.h in Headers */,
895732AF26DD03A3009507A6 /* QONAutomationsActionsHandler.h in Headers */,
70B917642B3314BD00BF0689 /* QONTransaction.h in Headers */,
8957328926DD03A3009507A6 /* QONProduct.h in Headers */,
702DBDEC2A3216C900D590D0 /* QONExperiment+Protected.h in Headers */,
8957328D26DD03A3009507A6 /* QONOfferings.h in Headers */,
Expand Down Expand Up @@ -1955,6 +1966,7 @@
8957327A26DD03A3009507A6 /* QNDevice+Advertising.m in Sources */,
895732C626DD03A3009507A6 /* QNAPIConstants.m in Sources */,
6A21BF552AB205AC005BDA7C /* QONRequest.m in Sources */,
70B917652B3314BD00BF0689 /* QONTransaction.m in Sources */,
70D05A8F29C9FC1600EA5DDF /* QONRemoteConfigManager.m in Sources */,
895732C426DD03A3009507A6 /* QNRequestBuilder.m in Sources */,
8957329726DD03A3009507A6 /* QONStoreKitSugare.m in Sources */,
Expand Down
50 changes: 50 additions & 0 deletions Sources/Qonversion/Public/QONEntitlement.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <Foundation/Foundation.h>
#import "QONTransaction.h"

typedef NS_ENUM(NSInteger, QONEntitlementSource) {
QONEntitlementSourceUnknown = -1, // Unable to detect the source
Expand All @@ -8,6 +9,13 @@ typedef NS_ENUM(NSInteger, QONEntitlementSource) {
QONEntitlementSourceManual = 4 // The entitlement was activated manually
} NS_SWIFT_NAME(Qonversion.EntitlementSource);

typedef NS_ENUM(NSInteger, QONEntitlementGrantType) {
QONEntitlementGrantTypePurchase = 0,
QONEntitlementGrantTypeFamilySharing = 1,
QONEntitlementGrantTypeOfferCode = 2,
QONEntitlementGrantTypeManual = 3
} NS_SWIFT_NAME(Qonversion.EntitlementGrantType);

typedef NS_ENUM(NSInteger, QONEntitlementRenewState){
/**
For in-app purchases.
Expand Down Expand Up @@ -78,4 +86,46 @@ NS_SWIFT_NAME(Qonversion.Entitlement)
*/
@property (nonatomic, copy, nullable) NSDate *expirationDate;

/**
Renews count for the entitlement. Renews count starts from the second paid subscription.
For example, we have 20 transactions. One is the trial, and one is the first paid transaction after the trial.
Renews count is equal to 18.
*/
@property (nonatomic, assign) NSUInteger renewsCount;

/**
Trial start date.
*/
@property (nonatomic, strong, nullable) NSDate *trialStartDate;

/**
First purchase date.
*/
@property (nonatomic, strong, nullable) NSDate *firstPurchaseDate;

/**
Last purchase date.
*/
@property (nonatomic, strong, nullable) NSDate *lastPurchaseDate;

/**
Last activated offer code.
*/
@property (nonatomic, copy, nullable) NSString *lastActivatedOfferCode;

/**
Grant type of the entitlement.
*/
@property (nonatomic, assign) QONEntitlementGrantType grantType;

/**
Auto-renew disable date.
*/
@property (nonatomic, strong, nullable) NSDate *autoRenewDisableDate;

/**
Array of the transactions that unlocked current entitlement.
*/
@property (nonatomic, copy, nonnull) NSArray<QONTransaction *> *transactions;

@end
58 changes: 52 additions & 6 deletions Sources/Qonversion/Public/QONEntitlement.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#import "QONEntitlement.h"
#import "QONTransaction.h"

@implementation QONEntitlement : NSObject

- (instancetype)initWithCoder:(NSCoder *)coder
{
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super init];
if (self) {
_entitlementID = [coder decodeObjectForKey:NSStringFromSelector(@selector(entitlementID))];
Expand All @@ -13,23 +13,38 @@ - (instancetype)initWithCoder:(NSCoder *)coder
_source = [coder decodeIntegerForKey:NSStringFromSelector(@selector(source))];
_startedDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(startedDate))];
_expirationDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(expirationDate))];
_renewsCount = [coder decodeIntegerForKey:NSStringFromSelector(@selector(renewsCount))];
_trialStartDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(trialStartDate))];
_firstPurchaseDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(firstPurchaseDate))];
_lastPurchaseDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(lastPurchaseDate))];
_lastActivatedOfferCode = [coder decodeObjectForKey:NSStringFromSelector(@selector(lastActivatedOfferCode))];
_grantType = [coder decodeIntegerForKey:NSStringFromSelector(@selector(grantType))];
_autoRenewDisableDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(autoRenewDisableDate))];
_transactions = [coder decodeObjectForKey:NSStringFromSelector(@selector(transactions))];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:_entitlementID forKey:NSStringFromSelector(@selector(entitlementID))];
[coder encodeObject:_productID forKey:NSStringFromSelector(@selector(productID))];
[coder encodeBool:_isActive forKey:NSStringFromSelector(@selector(isActive))];
[coder encodeInteger:_renewState forKey:NSStringFromSelector(@selector(renewState))];
[coder encodeInteger:_grantType forKey:NSStringFromSelector(@selector(grantType))];
[coder encodeInteger:_source forKey:NSStringFromSelector(@selector(source))];
[coder encodeObject:_startedDate forKey:NSStringFromSelector(@selector(startedDate))];
[coder encodeObject:_expirationDate forKey:NSStringFromSelector(@selector(expirationDate))];
[coder encodeInteger:_renewsCount forKey:NSStringFromSelector(@selector(renewsCount))];
[coder encodeObject:_lastActivatedOfferCode forKey:NSStringFromSelector(@selector(lastActivatedOfferCode))];
[coder encodeObject:_trialStartDate forKey:NSStringFromSelector(@selector(trialStartDate))];
[coder encodeObject:_firstPurchaseDate forKey:NSStringFromSelector(@selector(firstPurchaseDate))];
[coder encodeObject:_lastPurchaseDate forKey:NSStringFromSelector(@selector(lastPurchaseDate))];
[coder encodeObject:_autoRenewDisableDate forKey:NSStringFromSelector(@selector(autoRenewDisableDate))];
[coder encodeInteger:_grantType forKey:NSStringFromSelector(@selector(grantType))];
[coder encodeObject:_transactions forKey:NSStringFromSelector(@selector(transactions))];
}

- (NSString *)description
{
- (NSString *)description {
NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];

[description appendFormat:@"id=%@,\n", self.entitlementID];
Expand All @@ -39,11 +54,42 @@ - (NSString *)description
[description appendFormat:@"source=%@ (enum value = %li),\n", [self prettySource], (long) self.source];
[description appendFormat:@"startedDate=%@,\n", self.startedDate];
[description appendFormat:@"expirationDate=%@,\n", self.expirationDate];
[description appendFormat:@"renewsCount=%lu,\n", (unsigned long)self.renewsCount];
[description appendFormat:@"trialStartDate=%@,\n", self.trialStartDate];
[description appendFormat:@"firstPurchaseDate=%@,\n", self.firstPurchaseDate];
[description appendFormat:@"lastPurchaseDate=%@,\n", self.lastPurchaseDate];
[description appendFormat:@"lastActivatedOfferCode=%@,\n", self.lastActivatedOfferCode];
[description appendFormat:@"grantType=%@ (enum value = %li),\n", [self prettyGrantType], (long) self.grantType];
[description appendFormat:@"autoRenewDisableDate=%@,\n", self.autoRenewDisableDate];
[description appendFormat:@"transactions=%@,\n", self.transactions];
[description appendString:@">"];

return [description copy];
}

- (NSString *)prettyGrantType {
NSString *result = @"purchase";

switch (self.grantType) {
case QONEntitlementGrantTypePurchase:
result = @"purchase"; break;

case QONEntitlementGrantTypeFamilySharing:
result = @"family sharing"; break;

case QONEntitlementGrantTypeOfferCode:
result = @"offer code"; break;

case QONEntitlementGrantTypeManual:
result = @"manual"; break;

default:
break;
}

return result;
}

- (NSString *)prettyRenewState {
NSString *result = @"unknown";

Expand Down
83 changes: 83 additions & 0 deletions Sources/Qonversion/Public/QONTransaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// QONTransaction.h
// Qonversion
//
// Created by Suren Sarkisyan on 20.12.2023.
// Copyright © 2023 Qonversion Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, QONTransactionEnvironment) {
QONTransactionEnvironmentSandbox = 0,
QONTransactionEnvironmentProduction = 1
} NS_SWIFT_NAME(Qonversion.TransactionEnvironment);

typedef NS_ENUM(NSInteger, QONTransactionOwnershipType) {
QONTransactionOwnershipTypeOwner = 0,
QONTransactionOwnershipTypeFamilySharing = 1
} NS_SWIFT_NAME(Qonversion.TransactionOwnershipType);

typedef NS_ENUM(NSInteger, QONTransactionType) {
QONTransactionTypeUnknown = 0,
QONTransactionTypeSubscriptionStarted = 1,
QONTransactionTypeSubscriptionRenewed = 2,
QONTransactionTypeTrialStrated = 3,
QONTransactionTypeIntroStarted = 4,
QONTransactionTypeIntroRenewed = 5,
QONTransactionTypeNonConsumablePurchase = 6
} NS_SWIFT_NAME(Qonversion.TransactionType);

NS_SWIFT_NAME(Qonversion.Transaction)
@interface QONTransaction : NSObject <NSCoding>

/**
Original transaction identifier.
*/
@property (nonatomic, copy, nonnull) NSString *originalTransactionId;

/**
Transaction identifier.
*/
@property (nonatomic, copy, nonnull) NSString *transactionId;

/**
Offer code.
*/
@property (nonatomic, copy, nullable) NSString *offerCode;

/**
Transaction date.
*/
@property (nonatomic, strong, nonnull) NSDate *transactionDate;

/**
Expiration date for subscriptions.
*/
@property (nonatomic, strong, nullable) NSDate *expirationDate;

/**
The date when transaction was revoked. This field represents the time and date the App Store refunded a transaction or revoked it from family sharing.
*/
@property (nonatomic, strong, nullable) NSDate *transactionRevocationDate;

/**
Environment of the transaction.
*/
@property (nonatomic, assign) QONTransactionEnvironment environment;

/**
Type of ownership for the transaction. Owner/Family sharing.
*/
@property (nonatomic, assign) QONTransactionOwnershipType ownershipType;

/**
Type of the transaction.
*/
@property (nonatomic, assign) QONTransactionType type;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 48f4439

Please sign in to comment.