Skip to content
Browse files

The restored purchase doesn't list the receipt data itself, but the a…

…ct of restoring generates a new transaction that lists the original-transaction-id, which is more useful than returning nothing at all.
  • Loading branch information...
1 parent ce53551 commit 19e420edbb76362d1b9994b464c54420ce335123 @colinfrei colinfrei committed Sep 19, 2011
Showing with 19 additions and 19 deletions.
  1. +19 −19 iPhone/InAppPurchaseManager/InAppPurchaseManager.m
View
38 iPhone/InAppPurchaseManager/InAppPurchaseManager.m
@@ -15,23 +15,23 @@ -(void) setup:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
-- (void) requestProductData:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) requestProductData:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
if([arguments count] < 3) {
- return;
+ return;
}
NSLog(@"Getting product data");
NSSet *productIdentifiers = [NSSet setWithObject:[arguments objectAtIndex:0]];
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
-
+
ProductsRequestDelegate* delegate = [[[ProductsRequestDelegate alloc] init] retain];
delegate.command = self;
delegate.successCallback = [arguments objectAtIndex:1];
delegate.failCallback = [arguments objectAtIndex:2];
-
+
productsRequest.delegate = delegate;
[productsRequest start];
-
+
}
/**
@@ -57,42 +57,42 @@ - (void) requestProductsData:(NSMutableArray*)arguments withDict:(NSMutableDicti
[productsRequest start];
}
-- (void) makePurchase:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) makePurchase:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSLog(@"About to do IAP");
if([arguments count] < 1) {
- return;
+ return;
}
-
+
SKMutablePayment *payment = [SKMutablePayment paymentWithProductIdentifier:[arguments objectAtIndex:0]];
-
+
if([arguments count] > 1) {
id quantity = [arguments objectAtIndex:1];
if ([quantity respondsToSelector:@selector(integerValue)]) {
- payment.quantity = [quantity integerValue];
+ payment.quantity = [quantity integerValue];
}
}
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
-- (void) restoreCompletedTransactions:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) restoreCompletedTransactions:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
// SKPaymentTransactionObserver methods
-// called when the transaction status is updated
+// called when the transaction status is updated
//
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
NSString *state, *error, *transactionIdentifier, *transactionReceipt, *productId;
NSInteger errorCode;
-
+
for (SKPaymentTransaction *transaction in transactions)
{
error = state = transactionIdentifier = transactionReceipt = productId = @"";
errorCode = 0;
-
+
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchasing:
@@ -104,22 +104,22 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran
transactionReceipt = [[transaction transactionReceipt] base64EncodedString];
productId = transaction.payment.productIdentifier;
break;
-
+
case SKPaymentTransactionStateFailed:
state = @"PaymentTransactionStateFailed";
error = transaction.error.localizedDescription;
errorCode = transaction.error.code;
NSLog(@"error %d %@", errorCode, error);
break;
-
+
case SKPaymentTransactionStateRestored:
state = @"PaymentTransactionStateRestored";
transactionIdentifier = transaction.originalTransaction.transactionIdentifier;
- transactionReceipt = [[[transaction originalTransaction] transactionReceipt] base64EncodedString];
+ transactionReceipt = [[transaction transactionReceipt] base64EncodedString];
productId = transaction.originalTransaction.payment.productIdentifier;
break;
-
+
default:
NSLog(@"Invalid state");
continue;
@@ -136,7 +136,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran
@end
-@implementation ProductsRequestDelegate
+@implementation ProductsRequestDelegate
@synthesize successCallback, failCallback, command;

0 comments on commit 19e420e

Please sign in to comment.
Something went wrong with that request. Please try again.