Created
January 13, 2013 01:45
-
-
Save lindon-fox/4521743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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