|
@@ -135,8 +135,22 @@
|
|
|
|
|
|
@implementation IAPReceiptTool
|
|
|
|
|
|
++ (BOOL)isFreeTrailingWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId {
|
|
|
+ IAPReceiptInfoModel *lastestM = [self fetchProductLastestReceiptsWithModel:model withProductId:productId];
|
|
|
+ if (lastestM == nil) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (lastestM.is_trial_period == false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ long long expiresDate = [lastestM.expires_date_ms longLongValue]/1000;
|
|
|
+ long long currentDate = [[NSDate date] timeIntervalSince1970];
|
|
|
+ BOOL isActive = (expiresDate > currentDate) ? YES : NO;
|
|
|
+ return isActive;
|
|
|
+}
|
|
|
+
|
|
|
+ (BOOL)isNewUserWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
|
|
|
- if ([self hasTrialWithModel:model withGroupIdentifier:groupIdentifier]) {
|
|
|
+ if ([self hasFreeTrialWithModel:model withGroupIdentifier:groupIdentifier]) {
|
|
|
return false;
|
|
|
}
|
|
|
if ([self hasIntroOfferWithModel:model withGroupIdentifier:groupIdentifier]) {
|
|
@@ -145,7 +159,7 @@
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-+ (BOOL)hasTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
|
|
|
++ (BOOL)hasFreeTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
|
|
|
for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model withGroupIdentifier:groupIdentifier]) {
|
|
|
if (m.is_trial_period) {
|
|
|
return true;
|
|
@@ -174,10 +188,23 @@
|
|
|
return [results copy];
|
|
|
}
|
|
|
|
|
|
-+ (NSArray<IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductCode:(NSString *)productCode {
|
|
|
++ (IAPReceiptInfoModel *)fetchProductLastestReceiptsWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId {
|
|
|
+ IAPReceiptInfoModel *flagM= nil;
|
|
|
+ long long lastestExpiresDate = 0;
|
|
|
+ for (IAPReceiptInfoModel *m in [self fetchProductReceiptsWithModel:model withProductId:productId]) {
|
|
|
+ long long theExpiresDate = [m.expires_date_ms longLongValue]/1000;
|
|
|
+ if (theExpiresDate > lastestExpiresDate) {
|
|
|
+ lastestExpiresDate = theExpiresDate;
|
|
|
+ flagM = m;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flagM;
|
|
|
+}
|
|
|
+
|
|
|
++ (NSArray<IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductId:(nonnull NSString *)productId {
|
|
|
NSMutableArray *results = [NSMutableArray arrayWithCapacity:4];
|
|
|
for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model]) {
|
|
|
- if ([m.product_id isEqualToString:productCode] == false) {
|
|
|
+ if ([m.product_id isEqualToString:productId] == false) {
|
|
|
continue;
|
|
|
}
|
|
|
[results addObject:m];
|