-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RevenueCat/rich_purchaser_info
Rich Purchaser Info updates
- Loading branch information
Showing
3 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Created by RevenueCat. | ||
// Copyright © 2019 RevenueCat. All rights reserved. | ||
// | ||
|
||
#import <Purchases/Purchases.h> | ||
|
||
@interface RCEntitlementInfo (HybridAdditions) | ||
|
||
- (NSDictionary *)dictionary; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// Created by RevenueCat. | ||
// Copyright © 2019 RevenueCat. All rights reserved. | ||
// | ||
|
||
#import "RCEntitlement+HybridAdditions.h" | ||
#import "SKProduct+HybridAdditions.h" | ||
|
||
static NSDateFormatter *formatter; | ||
static dispatch_once_t onceToken; | ||
|
||
static NSString * stringFromDate(NSDate *date) | ||
{ | ||
dispatch_once(&onceToken, ^{ | ||
// Here we're not using NSISO8601DateFormatter as we need to support iOS < 10 | ||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | ||
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; | ||
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'"; | ||
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; | ||
formatter = dateFormatter; | ||
}); | ||
|
||
return [formatter stringFromDate:date]; | ||
} | ||
|
||
@implementation RCEntitlementInfo (HybridAdditions) | ||
|
||
- (NSDictionary *)dictionary | ||
{ | ||
NSMutableDictionary *jsonDict = [NSMutableDictionary new]; | ||
jsonDict[@"identifier"] = self.identifier; | ||
jsonDict[@"isActive"] = @(self.isActive); | ||
jsonDict[@"willRenew"] = @(self.willRenew); | ||
|
||
switch (self.periodType) { | ||
case RCIntro: | ||
jsonDict[@"periodType"] = @"INTRO"; | ||
break; | ||
case RCNormal: | ||
jsonDict[@"periodType"] = @"NORMAL"; | ||
break; | ||
case RCTrial: | ||
jsonDict[@"periodType"] = @"TRIAL"; | ||
break; | ||
} | ||
|
||
jsonDict[@"latestPurchaseDate"] = stringFromDate(self.latestPurchaseDate); | ||
jsonDict[@"originalPurchaseDate"] = stringFromDate(self.originalPurchaseDate); | ||
jsonDict[@"expirationDate"] = stringFromDate(self.originalPurchaseDate) ?: [NSNull null]; | ||
|
||
switch (self.store) { | ||
case RCAppStore: | ||
jsonDict[@"store"] = @"APP_STORE"; | ||
break; | ||
case RCMacAppStore: | ||
jsonDict[@"store"] = @"MAC_APP_STORE"; | ||
break; | ||
case RCPlayStore: | ||
jsonDict[@"store"] = @"PLAY_STORE"; | ||
break; | ||
case RCStripe: | ||
jsonDict[@"store"] = @"STRIPE"; | ||
break; | ||
case RCPromotional: | ||
jsonDict[@"store"] = @"PROMOTIONAL"; | ||
break; | ||
case RCUnknownStore: | ||
jsonDict[@"store"] = @"UNKNOWN_STORE"; | ||
break; | ||
} | ||
|
||
jsonDict[@"productIdentifier"] = self.productIdentifier; | ||
jsonDict[@"isSandbox"] = @(self.isSandbox); | ||
jsonDict[@"unsubscribeDetectedAt"] = stringFromDate(self.unsubscribeDetectedAt) ?: [NSNull null]; | ||
jsonDict[@"billingIssueDetectedAt"] = stringFromDate(self.billingIssueDetectedAt) ?: [NSNull null]; | ||
|
||
return [NSDictionary dictionaryWithDictionary:jsonDict]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters