diff --git a/.travis.yml b/.travis.yml index f85c0b49..1e3ac21d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ before_script: - brew upgrade xctool || true script: - xctool -project RMStore.xcodeproj -scheme 'RMStoreExcludeKeychainTests' -configuration Release -sdk iphonesimulator build-tests + - xctool -project RMStore.xcodeproj -scheme 'RMStoreExcludeKeychainTests' -configuration Release run-tests + - xctool -project RMStore.xcodeproj -scheme 'RMStoreExcludeKeychainTests' -configuration Release run-tests -test-sdk iphonesimulator7.1 - xctool -project RMStore.xcodeproj -scheme 'RMStoreExcludeKeychainTests' -configuration Release run-tests -test-sdk iphonesimulator7.0 - xctool -project RMStore.xcodeproj -scheme 'RMStoreDemo' -configuration Release -sdk iphonesimulator branches: diff --git a/README.md b/README.md index 3bd50e03..1f635829 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ #RMStore -[![Version](https://cocoapod-badges.herokuapp.com/v/RMStore/badge.png)](http://cocoadocs.org/docsets/RMStore) [![Platform](https://cocoapod-badges.herokuapp.com/p/RMStore/badge.png)](http://cocoadocs.org/docsets/RMStore) [![Build Status](https://travis-ci.org/robotmedia/RMStore.png)](https://travis-ci.org/robotmedia/RMStore) +[![Version](https://cocoapod-badges.herokuapp.com/v/RMStore/badge.png)](http://cocoadocs.org/docsets/RMStore) [![Platform](https://cocoapod-badges.herokuapp.com/p/RMStore/badge.png)](http://cocoadocs.org/docsets/RMStore) A lightweight iOS library for In-App Purchases. diff --git a/RMStore/RMStore.h b/RMStore/RMStore.h index 191f22a4..ff887c50 100755 --- a/RMStore/RMStore.h +++ b/RMStore/RMStore.h @@ -252,6 +252,7 @@ extern NSInteger const RMStoreErrorCodeUnableToCompleteVerification; */ - (void)storeDownloadUpdated:(NSNotification*)notification __attribute__((availability(ios,introduced=6.0))); +- (void)storePaymentTransactionDeferred:(NSNotification*)notification __attribute__((availability(ios,introduced=8.0))); - (void)storePaymentTransactionFailed:(NSNotification*)notification; - (void)storePaymentTransactionFinished:(NSNotification*)notification; - (void)storeProductsRequestFailed:(NSNotification*)notification; diff --git a/RMStore/RMStore.m b/RMStore/RMStore.m index db2d776b..60175a8d 100755 --- a/RMStore/RMStore.m +++ b/RMStore/RMStore.m @@ -30,6 +30,7 @@ NSString* const RMSKDownloadFinished = @"RMSKDownloadFinished"; NSString* const RMSKDownloadPaused = @"RMSKDownloadPaused"; NSString* const RMSKDownloadUpdated = @"RMSKDownloadUpdated"; +NSString* const RMSKPaymentTransactionDeferred = @"RMSKPaymentTransactionDeferred"; NSString* const RMSKPaymentTransactionFailed = @"RMSKPaymentTransactionFailed"; NSString* const RMSKPaymentTransactionFinished = @"RMSKPaymentTransactionFinished"; NSString* const RMSKProductsRequestFailed = @"RMSKProductsRequestFailed"; @@ -315,6 +316,7 @@ - (void)addStoreObserver:(id)observer [self addStoreObserver:observer selector:@selector(storeDownloadUpdated:) notificationName:RMSKDownloadUpdated]; [self addStoreObserver:observer selector:@selector(storeProductsRequestFailed:) notificationName:RMSKProductsRequestFailed]; [self addStoreObserver:observer selector:@selector(storeProductsRequestFinished:) notificationName:RMSKProductsRequestFinished]; + [self addStoreObserver:observer selector:@selector(storePaymentTransactionDeferred:) notificationName:RMSKPaymentTransactionDeferred]; [self addStoreObserver:observer selector:@selector(storePaymentTransactionFailed:) notificationName:RMSKPaymentTransactionFailed]; [self addStoreObserver:observer selector:@selector(storePaymentTransactionFinished:) notificationName:RMSKPaymentTransactionFinished]; [self addStoreObserver:observer selector:@selector(storeRefreshReceiptFailed:) notificationName:RMSKRefreshReceiptFailed]; @@ -332,6 +334,7 @@ - (void)removeStoreObserver:(id)observer [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKDownloadUpdated object:self]; [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKProductsRequestFailed object:self]; [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKProductsRequestFinished object:self]; + [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKPaymentTransactionDeferred object:self]; [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKPaymentTransactionFailed object:self]; [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKPaymentTransactionFinished object:self]; [[NSNotificationCenter defaultCenter] removeObserver:observer name:RMSKRefreshReceiptFailed object:self]; @@ -366,6 +369,10 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran break; case SKPaymentTransactionStateRestored: [self didRestoreTransaction:transaction queue:queue]; + break; + case SKPaymentTransactionStateDeferred: + [self didDeferTransaction:transaction]; + break; default: break; } @@ -571,6 +578,11 @@ - (void)didRestoreTransaction:(SKPaymentTransaction *)transaction queue:(SKPayme } } +- (void)didDeferTransaction:(SKPaymentTransaction *)transaction +{ + [self postNotificationWithName:RMSKPaymentTransactionDeferred transaction:transaction userInfoExtras:nil]; +} + - (void)didVerifyTransaction:(SKPaymentTransaction *)transaction queue:(SKPaymentQueue*)queue { if (self.contentDownloader != nil) diff --git a/RMStoreTests/RMStoreTests.m b/RMStoreTests/RMStoreTests.m index 69e8753b..96b78364 100644 --- a/RMStoreTests/RMStoreTests.m +++ b/RMStoreTests/RMStoreTests.m @@ -29,8 +29,11 @@ extern NSString* const RMSKRefreshReceiptFailed; extern NSString* const RMSKRefreshReceiptFinished; +extern NSString* const RMSKPaymentTransactionDeferred; extern NSString* const RMSKRestoreTransactionsFailed; extern NSString* const RMSKRestoreTransactionsFinished; +extern NSString* const RMStoreNotificationProductIdentifier; +extern NSString* const RMStoreNotificationTransaction; extern NSString* const RMStoreNotificationStoreError; @@ -960,6 +963,22 @@ - (void)testPaymentQueueUpdatedTransactions_Failed__Blocks [_store paymentQueue:queue updatedTransactions:@[originalTransaction]]; } +- (void)testPaymentQueueUpdatedTransactions_Deferred +{ SKIP_IF_VERSION(NSFoundationVersionNumber_iOS_7_1) + id queue = [OCMockObject mockForClass:[SKPaymentQueue class]]; + id transaction = [self mockPaymentTransactionWithState:SKPaymentTransactionStateDeferred]; + id observerMock = [self observerMockForNotification:RMSKPaymentTransactionDeferred checkUserInfoWithBlock:^BOOL(NSDictionary *userInfo) { + XCTAssertEqualObjects(userInfo[RMStoreNotificationProductIdentifier], [[transaction payment] productIdentifier], @""); + XCTAssertEqualObjects(userInfo[RMStoreNotificationTransaction], transaction, @""); + return YES; + }]; + + [_store paymentQueue:queue updatedTransactions:@[transaction]]; + + [observerMock verify]; + [[NSNotificationCenter defaultCenter] removeObserver:observerMock]; +} + - (void)testPaymentQueueRestoreCompletedTransactionsFinished { id observerMock = [self observerMockForNotification:RMSKRestoreTransactionsFinished]; @@ -1240,7 +1259,7 @@ - (id)mockPaymentTransactionWithState:(SKPaymentTransactionState)state downloads [[[transaction stub] andReturn:@"transaction"] transactionIdentifier]; [[[transaction stub] andReturn:[NSData data]] transactionReceipt]; id payment = [OCMockObject mockForClass:[SKPayment class]]; - [[[payment stub] andReturn:@"test"] productIdentifier]; + [[[payment stub] andReturn:self.name] productIdentifier]; [[[transaction stub] andReturn:payment] payment]; [[[transaction stub] andReturn:downloads] downloads]; for (id download in downloads)