Skip to content

Commit

Permalink
Merge pull request #109 from robotmedia/feature/deferred-transactions
Browse files Browse the repository at this point in the history
Add support for deferred transactions
  • Loading branch information
hpique committed Sep 23, 2014
2 parents d0347f3 + 67e6194 commit 2eadf5d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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) <!--[![Build Status](https://travis-ci.org/robotmedia/RMStore.png)](https://travis-ci.org/robotmedia/RMStore)-->


A lightweight iOS library for In-App Purchases.
Expand Down
1 change: 1 addition & 0 deletions RMStore/RMStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions RMStore/RMStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -315,6 +316,7 @@ - (void)addStoreObserver:(id<RMStoreObserver>)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];
Expand All @@ -332,6 +334,7 @@ - (void)removeStoreObserver:(id<RMStoreObserver>)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];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion RMStoreTests/RMStoreTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2eadf5d

Please sign in to comment.