Permalink
Browse files

Removes `_receiptVerificationClient`. On the start of verifying recei…

…pt, instantiate (if needed) the required singleton client (sandbox or production). I find this implementation most thread safe when it comes to switching.
  • Loading branch information...
1 parent 01ac031 commit f682a458aa0628866a4dccd1965e3e7e52336379 @lxcid committed Dec 1, 2012
Showing with 18 additions and 6 deletions.
  1. +18 −6 CargoBay/CargoBay.m
View
24 CargoBay/CargoBay.m
@@ -467,8 +467,6 @@ - (id)initWithSuccess:(void (^)(NSArray *products, NSArray *invalidIdentifiers))
@implementation CargoBay {
@private
- AFHTTPClient *_receiptVerificationClient;
-
CargoBayPaymentQueueTransactionsBlock _paymentQueueTransactionsUpdated;
CargoBayPaymentQueueTransactionsBlock _paymentQueueTransactionsRemoved;
CargoBayPaymentQueueRestoreSuccessBlock _paymentQueueRestoreSuccessBlock;
@@ -521,8 +519,6 @@ - (id)init {
if (!self) {
return nil;
}
-
- _receiptVerificationClient = [self productionReceiptVerificationClient];
return self;
}
@@ -664,14 +660,30 @@ - (void)verifyTransaction:(SKPaymentTransaction *)transaction
}
}];
- [_receiptVerificationClient enqueueHTTPRequestOperation:operation];
+ [client enqueueHTTPRequestOperation:operation];
}
- (void)verifyTransaction:(SKPaymentTransaction *)transaction
password:(NSString *)password
success:(void (^)(NSDictionary *receipt))success
failure:(void (^)(NSError *error))failure {
- AFHTTPClient *client = _receiptVerificationClient;
+ NSError *error = nil;
+
+ if (!((transaction) && (transaction.transactionReceipt) && (transaction.transactionReceipt.length > 0))) {
+ error = [NSError errorWithDomain:SKErrorDomain code:-1 userInfo:nil];
+ failure(error);
+ return;
+ }
+
+ NSDictionary *receiptDictionary = [NSPropertyListSerialization propertyListWithData:transaction.transactionReceipt options:NSPropertyListImmutable format:nil error:&error];
+ if (!receiptDictionary) {
+ failure(error);
+ return;
+ }
+
+ NSString *environment = [receiptDictionary objectForKey:@"environment"];
+ AFHTTPClient *client = [environment isEqual:@"Sandbox"] ? [self sandboxReceiptVerificationClient] : [self productionReceiptVerificationClient];
+
[self verifyTransaction:transaction client:client password:password success:success failure:failure];
}

0 comments on commit f682a45

Please sign in to comment.