Skip to content

Instantly share code, notes, and snippets.

@lindon-fox
Created January 13, 2013 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindon-fox/4521743 to your computer and use it in GitHub Desktop.
Save lindon-fox/4521743 to your computer and use it in GitHub Desktop.
#pragma mark -
#pragma mark Subscription restore request methods
- (void)submitRestoredTransaction:(SKPaymentTransaction *)transaction {
UASubscriptionProduct *product = [[UASubscriptionManager shared].inventory productForKey:transaction.payment.productIdentifier];
NSString *key = product.subscriptionKey;
NSString *product_id = transaction.payment.productIdentifier;
NSString *receipt = [[[NSString alloc] initWithData:transaction.transactionReceipt
encoding:NSUTF8StringEncoding] autorelease];
if (!product.isForSale) {
UALOG(@"Ignoring transaction for deleted product %@", product_id);
[unrestoredTransactions removeObject:transaction];
[self safelyFinishTransaction:transaction];
return;
}
NSString *urlString = [NSString stringWithFormat:@"%@%@%@/subscriptions/%@/purchase",
[[UAirship shared] server],
@"/api/user/",
[UAUser defaultUser].username,
key];
UA_ASIHTTPRequest *request = [UAUtils userRequestWithURL:[NSURL URLWithString:urlString]
method:@"POST"
delegate:self
finish:@selector(autorenewableRestoredWithRequest:)
fail:@selector(autorenewableRestoreRequestDidFail:)];
request.userInfo = [NSDictionary dictionaryWithObject:transaction forKey:@"transaction"];
UA_SBJsonWriter *writer = [[UA_SBJsonWriter alloc] init];
writer.humanReadable = NO;
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
product_id,
@"product_id",
receipt,
@"transaction_receipt",
nil];
NSString *body = [writer stringWithObject:data];
[data release];
[writer release];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request appendPostData:[body dataUsingEncoding:NSUTF8StringEncoding]];
[networkQueue addOperation:request];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment