Skip to content

Instantly share code, notes, and snippets.

@augustine-tran
Created July 10, 2014 07:17
Show Gist options
  • Save augustine-tran/10bd03176de58d0b43f0 to your computer and use it in GitHub Desktop.
Save augustine-tran/10bd03176de58d0b43f0 to your computer and use it in GitHub Desktop.
- (IBAction)buyMoreButtonClicked:(id)sender
{
[GGProgressHUD showActivity];
NSString *productId = IAP_PRODUCT_CREDIT;
SKProduct *product = [[TNStoreHelper requestedProducts] valueForKey:productId];
if (product) {
[self purchaseProduct:product];
return;
}
[[TNStoreHelper sharedInstance] requestProducts:[NSSet setWithObject:productId] withCompletionHandler:^(BOOL success, NSArray *products) {
if (success && [products count] > 0) {
// we got the product here, now we just need to purchase it
[self purchaseProduct:[products objectAtIndex:0]];
} else {
[GGProgressHUD hideActivity];
}
}];
}
- (void)purchaseProduct:(SKProduct *)product
{
[GGProgressHUD showActivity];
[[TNStoreHelper sharedInstance] buyProduct:product withCompletionHandler:^(BOOL buySuccess, SKPaymentTransaction *transaction, BOOL isRestore) {
if (buySuccess) {
// Purchase successed, we need to call webservice to verify and add credit for user
[GGWebService creditTopup:[NSNumber numberWithInt:score] didCompleted:^(NSHTTPURLResponse *response, id data, NSError *error) {
[GGProgressHUD hideActivity];
}];
} else {
[GGProgressHUD hideActivity];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment