Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated entitlements fields and added transactions array #428

Merged
merged 7 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 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);
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved

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

@property (nonatomic, assign) NSUInteger renewsCount;

@property (nonatomic, strong, nullable) NSDate *trialStartDate;

@property (nonatomic, strong, nullable) NSDate *firstPurchaseDate;

@property (nonatomic, strong, nullable) NSDate *lastPurchaseDate;

@property (nonatomic, copy, nullable) NSString *lastActivatedOfferCode;

@property (nonatomic, assign) QONEntitlementGrantType grantType;

@property (nonatomic, strong, nullable) NSDate *autoRenewDisableDate;

@property (nonatomic, copy, nonnull) NSArray<QONTransaction *> *transactions;

@end
59 changes: 52 additions & 7 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,37 @@ - (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(renewState))];
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
[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 +53,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=%li,\n", 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;
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
}

return result;
}

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

Expand Down
47 changes: 47 additions & 0 deletions Sources/Qonversion/Public/QONTransaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// 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) {
QONTransactionTypeSubscriptionStarted = 0,
QONTransactionTypeSubscriptionRenewed = 1,
QONTransactionTypeTrialStrated = 2,
QONTransactionTypeIntroStarted = 3,
QONTransactionTypeIntroRenewed = 4,
QONTransactionTypeNonConsumablePurchase = 5
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
} NS_SWIFT_NAME(Qonversion.TransactionType);

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

@property (nonatomic, copy, nonnull) NSString *originalTransactionId;
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
@property (nonatomic, copy, nonnull) NSString *transactionId;
@property (nonatomic, copy, nullable) NSString *offerCode;
@property (nonatomic, strong, nonnull) NSDate *transactionDate;
@property (nonatomic, strong, nullable) NSDate *expirationDate;
@property (nonatomic, strong, nullable) NSDate *transactionRevocationDate;
@property (nonatomic, assign) QONTransactionEnvironment environment;
@property (nonatomic, assign) QONTransactionOwnershipType ownershipType;
@property (nonatomic, assign) QONTransactionType type;

@end

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

#import "QONTransaction.h"

@implementation QONTransaction

- (instancetype)initWithOriginalTransactionId:(NSString *)originalTransactionId
transactionId:(NSString *)transactionId
offerCode:(NSString *)offerCode
transactionDate:(NSDate *)transactionDate
expirationDate:(NSDate *)expirationDate
transactionRevocationDate:(NSDate *)transactionRevocationDate
environment:(QONTransactionEnvironment)environment
ownershipType:(QONTransactionOwnershipType)ownershipType
type:(QONTransactionType)type {
self = [super init];

if (self) {
_originalTransactionId = originalTransactionId;
_transactionId = transactionId;
_offerCode = offerCode;
_transactionDate = transactionDate;
_expirationDate = expirationDate;
_transactionRevocationDate = transactionRevocationDate;
_environment = environment;
_ownershipType = ownershipType;
_type = type;
}

return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super init];
if (self) {
_originalTransactionId = [coder decodeObjectForKey:NSStringFromSelector(@selector(originalTransactionId))];
_transactionId = [coder decodeObjectForKey:NSStringFromSelector(@selector(transactionId))];
_offerCode = [coder decodeObjectForKey:NSStringFromSelector(@selector(offerCode))];
_transactionDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(transactionDate))];
_expirationDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(expirationDate))];
_transactionRevocationDate = [coder decodeObjectForKey:NSStringFromSelector(@selector(transactionRevocationDate))];
_environment = [coder decodeIntegerForKey:NSStringFromSelector(@selector(environment))];
_ownershipType = [coder decodeIntegerForKey:NSStringFromSelector(@selector(ownershipType))];
_type = [coder decodeIntegerForKey:NSStringFromSelector(@selector(type))];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:_originalTransactionId forKey:NSStringFromSelector(@selector(originalTransactionId))];
[coder encodeObject:_transactionId forKey:NSStringFromSelector(@selector(transactionId))];
[coder encodeObject:_offerCode forKey:NSStringFromSelector(@selector(offerCode))];
[coder encodeObject:_transactionDate forKey:NSStringFromSelector(@selector(transactionDate))];
[coder encodeObject:_expirationDate forKey:NSStringFromSelector(@selector(expirationDate))];
[coder encodeObject:_transactionRevocationDate forKey:NSStringFromSelector(@selector(transactionRevocationDate))];
[coder encodeInteger:_environment forKey:NSStringFromSelector(@selector(environment))];
[coder encodeInteger:_ownershipType forKey:NSStringFromSelector(@selector(ownershipType))];
[coder encodeInteger:_type forKey:NSStringFromSelector(@selector(type))];
}

- (NSString *)description {
NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];
[description appendFormat:@"originalTransactionId=%@,\n", self.originalTransactionId];
[description appendFormat:@"transactionId=%@,\n", self.transactionId];
[description appendFormat:@"offerCode=%@,\n", self.offerCode];
[description appendFormat:@"transactionDate=%@,\n", self.transactionDate];
[description appendFormat:@"expirationDate=%@,\n", self.expirationDate];
[description appendFormat:@"transactionRevocationDate=%@,\n", self.transactionRevocationDate];
[description appendFormat:@"environment=%@ (enum value = %li),\n", [self prettyEnvironment], (long) self.environment];
[description appendFormat:@"ownershipType=%@ (enum value = %li),\n", [self prettyOwnershipType], (long) self.ownershipType];
[description appendFormat:@"type=%@ (enum value = %li),\n", [self prettyType], (long) self.type];

[description appendString:@">"];

return [description copy];
}

- (NSString *)prettyEnvironment {
NSString *result = @"production";

switch (self.environment) {
case QONTransactionEnvironmentSandbox:
result = @"sandbox"; break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = @"sandbox"; break;
result = @"sandbox";
break;


case QONTransactionEnvironmentProduction:
result = @"production"; break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = @"production"; break;
result = @"production";
break;

default:
break;
}

return result;
}

- (NSString *)prettyOwnershipType {
NSString *result = @"owner";

switch (self.ownershipType) {
case QONTransactionOwnershipTypeOwner:
result = @"owner"; break;

case QONTransactionOwnershipTypeFamilySharing:
result = @"family sharing"; break;
default:
break;
}

return result;
}

- (NSString *)prettyType {
NSString *result = @"subscription renewed";

switch (self.type) {
case QONTransactionTypeSubscriptionStarted:
result = @"subscription started"; break;

case QONTransactionTypeSubscriptionRenewed:
result = @"subscription renewed"; break;

case QONTransactionTypeTrialStrated:
result = @"trial started"; break;

case QONTransactionTypeIntroStarted:
result = @"intro started"; break;

case QONTransactionTypeIntroRenewed:
result = @"intro renewed"; break;

case QONTransactionTypeNonConsumablePurchase:
result = @"non-consumable purchase"; break;
default:
break;
}

return result;
}

@end
Loading
Loading