Skip to content

Commit

Permalink
Add some of the community PR's. Note that due to numerous merge confl…
Browse files Browse the repository at this point in the history
…icts, etc., I'm adding these

manually, so the actual commits are not part of the git history, unfortunately. However this list
indicates the original PR number and the author.
- Add robotmedia#138 by @protikhonov.
- Add robotmedia#150 by @seantb.
- Add robotmedia#175 by @metasmile
  • Loading branch information
balthisar committed Dec 24, 2019
1 parent 9d89b44 commit 89ab7ea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
6 changes: 5 additions & 1 deletion RMStore/Optional/RMStoreUserDefaultsPersistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
*/
- (void)removeTransactions;

/** Remove transactions from user defaults via specific ProductIdentifier.
*/
- (void)removeTransactionsForProductIdentifier:(NSString *)productIdentifier;

/** Consume the given product if available. Intended for consumable products.
@param productIdentifier Identifier of the product to be consumed.
@return YES if the product was consumed, NO otherwise.
Expand Down Expand Up @@ -78,4 +82,4 @@
*/
- (RMStoreTransaction*)transactionWithData:(NSData*)data;

@end
@end
10 changes: 10 additions & 0 deletions RMStore/Optional/RMStoreUserDefaultsPersistence.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ - (void)removeTransactions
[defaults synchronize];
}

- (void)removeTransactionsForProductIdentifier:(NSString *)productIdentifier
{
NSUserDefaults *defaults = [self userDefaults];
NSDictionary *purchases = [defaults objectForKey:RMStoreTransactionsUserDefaultsKey] ? : @{};
NSMutableDictionary *updatedPurchases = [NSMutableDictionary dictionaryWithDictionary:purchases];
[updatedPurchases removeObjectForKey:productIdentifier];
[defaults setObject:updatedPurchases forKey:RMStoreTransactionsUserDefaultsKey];
[defaults synchronize];
}

- (BOOL)consumeProductOfIdentifier:(NSString*)productIdentifier
{
NSUserDefaults *defaults = [self userDefaults];
Expand Down
30 changes: 18 additions & 12 deletions RMStore/RMStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ - (NSArray*)rm_transactions {

@interface RMProductsRequestDelegate : NSObject<SKProductsRequestDelegate>

@property (nonatomic, strong) RMSKProductsRequestSuccessBlock successBlock;
@property (nonatomic, strong) RMSKProductsRequestFailureBlock failureBlock;
@property (nonatomic, copy) RMSKProductsRequestSuccessBlock successBlock;
@property (nonatomic, copy) RMSKProductsRequestFailureBlock failureBlock;
@property (nonatomic, weak) RMStore *store;

@end

@interface RMAddPaymentParameters : NSObject

@property (nonatomic, strong) RMSKPaymentTransactionSuccessBlock deferBlock;
@property (nonatomic, strong) RMSKPaymentTransactionSuccessBlock successBlock;
@property (nonatomic, strong) RMSKPaymentTransactionFailureBlock failureBlock;
@property (nonatomic, copy) RMSKPaymentTransactionSuccessBlock deferBlock;
@property (nonatomic, copy) RMSKPaymentTransactionSuccessBlock successBlock;
@property (nonatomic, copy) RMSKPaymentTransactionFailureBlock failureBlock;

@end

Expand All @@ -160,7 +160,7 @@ @implementation RMStore

NSMutableArray *_storedStorePayments;

NSInteger _pendingRestoredTransactionsCount;
NSMutableSet *_pendingRestoredTransactionIds;
BOOL _restoredCompletedTransactionsFinished;

SKReceiptRefreshRequest *_refreshReceiptRequest;
Expand All @@ -180,6 +180,7 @@ - (instancetype) init
_productsRequestDelegates = [NSMutableSet set];
_productsRequests = [NSMutableSet set];
_restoredTransactions = [NSMutableArray array];
_pendingRestoredTransactionIds = [NSMutableSet set];
_storedStorePayments = [NSMutableArray array];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
Expand Down Expand Up @@ -320,7 +321,7 @@ - (void)restoreTransactionsOnSuccess:(void (^)(NSArray *transactions))successBlo
failure:(void (^)(NSError *error))failureBlock
{
_restoredCompletedTransactionsFinished = NO;
_pendingRestoredTransactionsCount = 0;
[_pendingRestoredTransactionIds removeAllObjects];
_restoredTransactions = [NSMutableArray array];
_restoreTransactionsSuccessBlock = successBlock;
_restoreTransactionsFailureBlock = failureBlock;
Expand All @@ -333,7 +334,7 @@ - (void)restoreTransactionsOfUser:(NSString*)userIdentifier
{
NSAssert([[SKPaymentQueue defaultQueue] respondsToSelector:@selector(restoreCompletedTransactionsWithApplicationUsername:)], @"restoreCompletedTransactionsWithApplicationUsername: not supported in this iOS version. Use restoreTransactionsOnSuccess:failure: instead.");
_restoredCompletedTransactionsFinished = NO;
_pendingRestoredTransactionsCount = 0;
[_pendingRestoredTransactionIds removeAllObjects];
_restoreTransactionsSuccessBlock = successBlock;
_restoreTransactionsFailureBlock = failureBlock;
[[SKPaymentQueue defaultQueue] restoreCompletedTransactionsWithApplicationUsername:userIdentifier];
Expand Down Expand Up @@ -735,9 +736,13 @@ - (void)didFailTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQ

- (void)didRestoreTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue
{
RMStoreLog(@"transaction restored with product %@", transaction.originalTransaction.payment.productIdentifier);
NSString *productIdentifier = transaction.originalTransaction.payment.productIdentifier;
RMStoreLog(@"transaction restored with product %@", productIdentifier);

if(productIdentifier) {
[_pendingRestoredTransactionIds addObject:productIdentifier];
}

_pendingRestoredTransactionsCount++;
if (self.receiptVerifier != nil)
{
[self.receiptVerifier verifyTransaction:transaction success:^{
Expand Down Expand Up @@ -830,9 +835,10 @@ - (void)notifyRestoreTransactionFinishedIfApplicableAfterTransaction:(SKPaymentT
if (transaction != nil)
{
[_restoredTransactions addObject:transaction];
_pendingRestoredTransactionsCount--;
[_pendingRestoredTransactionIds removeObject:transaction.payment.productIdentifier];

}
if (_restoredCompletedTransactionsFinished && _pendingRestoredTransactionsCount == 0)
if (_restoredCompletedTransactionsFinished && _pendingRestoredTransactionIds.count == 0)
{ // Wait until all restored transations have been verified
NSArray *restoredTransactions = [_restoredTransactions copy];
if (_restoreTransactionsSuccessBlock != nil)
Expand Down
4 changes: 2 additions & 2 deletions RMStoreTests/RMProducstRequestDelegateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

@interface RMProductsRequestDelegate : NSObject<SKProductsRequestDelegate>

@property (nonatomic, strong) RMSKProductsRequestSuccessBlock successBlock;
@property (nonatomic, strong) RMSKProductsRequestFailureBlock failureBlock;
@property (nonatomic, copy) RMSKProductsRequestSuccessBlock successBlock;
@property (nonatomic, copy) RMSKProductsRequestFailureBlock failureBlock;
@property (nonatomic, weak) RMStore *store;

@end
Expand Down

0 comments on commit 89ab7ea

Please sign in to comment.