In-App Purchases in iOS 6 Tutorial: Consumables and Receipt Validation
17 posts
• Page 1 of 2 • 1, 2
In-App Purchases in iOS 6 Tutorial: Consumables and Receipt Validation
This is the official thread to discuss the following blog post: In-App Purchases in iOS 6 Tutorial: Consumables and Receipt Validation
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
I always appreciate a great tutorial, but I must ask why you use those graphics of the characters (e.g. Random rage face) -
??
Just curious, but I despise these images for some reason. IMHO, they take aways from the tutorial...
??Just curious, but I despise these images for some reason. IMHO, they take aways from the tutorial...
- PhillyNJ
- n00b
- Posts: 4
- Joined: Sat Jan 14, 2012 12:32 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Heh, they are love them or hate them I guess. Personally I like them because I think they help make the tutorial a bit more amusing/lighthearted - otherwise tutorials can get pretty dry and technical. Maybe I'll run a poll sometimes to see what people think :]
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Hi Ray,
As always, Excellent Tutorial!
I have a little question: When I use the code in this tutorial for receipt validation, ¿Do I have to check the "Uses Encryption" box in iTunes Connect?
Thanks,
Jarocep
As always, Excellent Tutorial!
I have a little question: When I use the code in this tutorial for receipt validation, ¿Do I have to check the "Uses Encryption" box in iTunes Connect?
Thanks,
Jarocep
- jarocep
- Baby Hacker
- Posts: 8
- Joined: Sun Sep 11, 2011 10:42 pm
- Has thanked: 0 time
- Been thanked: 1 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
great tutorial,
i have a question,
i have non-consumable product,how do i send request using skpayment for MultipleProduct Id's in IOS.In my project I have 5 products. So I need to buy 3 products to send payment request for those particular productID's, do I need to loop it like below.
for (int i;i<[productsID's count];i++)
{
skmutablepayment *payment =[skmutablepayment paymentwithproductidentifier:
[product objetatindex:i]];
}
I need the payment only for specific products which I have selected. How do I pass those selected id's to skpayment?
your help is greatly appreciated.
i have a question,
i have non-consumable product,how do i send request using skpayment for MultipleProduct Id's in IOS.In my project I have 5 products. So I need to buy 3 products to send payment request for those particular productID's, do I need to loop it like below.
for (int i;i<[productsID's count];i++)
{
skmutablepayment *payment =[skmutablepayment paymentwithproductidentifier:
[product objetatindex:i]];
}
I need the payment only for specific products which I have selected. How do I pass those selected id's to skpayment?
your help is greatly appreciated.
- Abhay
- n00b
- Posts: 1
- Joined: Wed Dec 26, 2012 7:35 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Hi, thank you so much for the tutorial, everything works great, but instead of a table view I would like to create a simple IBAction button.
I tried several ways but I couldn't make it work. Just a simple button to start the process.
I'm trying like this:
Or this:
But doesn't work. Any ideas? I would reallly appreciate an answer, it can't be so difficult. This is the ONLY thing missing on a 3 months project.
I tried several ways but I couldn't make it work. Just a simple button to start the process.
I'm trying like this:
- Code: Select all
- (IBAction)button10Coins:(SKProduct *)product {
SKPayment * payment = [SKPayment paymentWithProduct:@"com.companyname.10coins"];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
Or this:
- Code: Select all
-(IBAction)buyProductButton:(id)sender {
SKProduct *product = _products;
NSLog(@"Buying %@...", product.productIdentifier);
[[RageIAPHelper sharedInstance] buyProduct:product]; }
But doesn't work. Any ideas? I would reallly appreciate an answer, it can't be so difficult. This is the ONLY thing missing on a 3 months project.
- tomDev
- n00b
- Posts: 3
- Joined: Sat Jan 05, 2013 3:33 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Hey,
I was just wondering what if I wanted to do a simple button to purchase an item within my view controller. I have some code:
- (IBAction)purchase {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.500k"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
status.text = @"Please wait...";
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
SKProduct *validProduct = nil;
int count = [response.products count];
if (count >0) {
validProduct = [response.products objectAtIndex:0];
} else if (!validProduct) {
NSLog(@"No products avaiable");
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
status.text = @"Processing...";
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self purchaseCOMPLETE];
status.text = @"Purchase complete";
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
status.text = @"";
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog (@"An error encountered");
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
status.text = @"Purchase error";
break;
}
}
}
-(void)purchaseCOMPLETE {
self.currentMoneyStore = self.currentMoneyStore + 500000;
moneyLabelStore.text = [NSString stringWithFormat: @"$ %lld", self.currentMoneyStore];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"Parental-controls are disbaled");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.500k"]];
productsRequest.delegate = self;
[productsRequest start];
} else {
NSLog(@"Parental-controls are enabled");
}
}
Everything works great but I get the warning (paymentWithProductIdentifier) is deprecated in iOS 5 every time. Would this code still work for my app in I submit a binary? Is there a better way to code this? Please help.
I was just wondering what if I wanted to do a simple button to purchase an item within my view controller. I have some code:
- (IBAction)purchase {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.500k"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
status.text = @"Please wait...";
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
SKProduct *validProduct = nil;
int count = [response.products count];
if (count >0) {
validProduct = [response.products objectAtIndex:0];
} else if (!validProduct) {
NSLog(@"No products avaiable");
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
status.text = @"Processing...";
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self purchaseCOMPLETE];
status.text = @"Purchase complete";
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
status.text = @"";
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog (@"An error encountered");
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
status.text = @"Purchase error";
break;
}
}
}
-(void)purchaseCOMPLETE {
self.currentMoneyStore = self.currentMoneyStore + 500000;
moneyLabelStore.text = [NSString stringWithFormat: @"$ %lld", self.currentMoneyStore];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"Parental-controls are disbaled");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.500k"]];
productsRequest.delegate = self;
[productsRequest start];
} else {
NSLog(@"Parental-controls are enabled");
}
}
Everything works great but I get the warning (paymentWithProductIdentifier) is deprecated in iOS 5 every time. Would this code still work for my app in I submit a binary? Is there a better way to code this? Please help.
- DroolGames
- n00b
- Posts: 2
- Joined: Fri Jan 11, 2013 6:12 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Hey everyone,
I figured out if someone wanted a single button to make a purchase than they would simply apply this code:
-(IBAction)purchase25k:(id)sender {
SKProductsRequest *request= [[SKProductsRequest alloc]
initWithProductIdentifiers: [NSSet setWithObject: @"com.25k"]];
request.delegate = self;
[request start];
//Added a UIlabel to display status of purchase
status.text = @"Processing..Please wait..";
}
-(IBAction)purchase75k:(id)sender {
SKProductsRequest *request= [[SKProductsRequest alloc]
initWithProductIdentifiers: [NSSet setWithObject: @"com.75k"]];
request.delegate = self;
[request start];
//Added a UIlabel to display status of purchase
status.text = @"Processing..Please wait..";
}
[size=150]Than after you enter your transaction methods as explained in the tutorial IF you have more than one button you can add[/size]
- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {
if ([productIdentifier isEqualToString:@"com.25k"]) {
self.currentMoneyStore = self.currentMoneyStore + 25000;
moneyLabelStore.text = [NSString stringWithFormat: @"$ %lld", self.currentMoneyStore];
status.text = @"Purchase complete";
} else if ([productIdentifier isEqualToString:@"com.75k"]) {
self.currentMoneyStore = self.currentMoneyStore + 75000;
moneyLabelStore.text = [NSString stringWithFormat: @"$ %lld", self.currentMoneyStore];
status.text = @"Purchase complete";
}
email me for any confusion or help
droolgames@gmail.com
I figured out if someone wanted a single button to make a purchase than they would simply apply this code:
-(IBAction)purchase25k:(id)sender {
SKProductsRequest *request= [[SKProductsRequest alloc]
initWithProductIdentifiers: [NSSet setWithObject: @"com.25k"]];
request.delegate = self;
[request start];
//Added a UIlabel to display status of purchase
status.text = @"Processing..Please wait..";
}
-(IBAction)purchase75k:(id)sender {
SKProductsRequest *request= [[SKProductsRequest alloc]
initWithProductIdentifiers: [NSSet setWithObject: @"com.75k"]];
request.delegate = self;
[request start];
//Added a UIlabel to display status of purchase
status.text = @"Processing..Please wait..";
}
[size=150]Than after you enter your transaction methods as explained in the tutorial IF you have more than one button you can add[/size]
- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {
if ([productIdentifier isEqualToString:@"com.25k"]) {
self.currentMoneyStore = self.currentMoneyStore + 25000;
moneyLabelStore.text = [NSString stringWithFormat: @"$ %lld", self.currentMoneyStore];
status.text = @"Purchase complete";
} else if ([productIdentifier isEqualToString:@"com.75k"]) {
self.currentMoneyStore = self.currentMoneyStore + 75000;
moneyLabelStore.text = [NSString stringWithFormat: @"$ %lld", self.currentMoneyStore];
status.text = @"Purchase complete";
}
email me for any confusion or help
droolgames@gmail.com
- DroolGames
- n00b
- Posts: 2
- Joined: Fri Jan 11, 2013 6:12 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Hi,
I was wondering about server-side receipt validation and man-in-the-middle attacks. I asked the question on StackOverflow and it might be easier to check it out rather than rehashing it in this forum.
http://stackoverflow.com/questions/14243909/apple-in-app-purchase-receipt-verification
Thanks for the tutorial. Best of luck
Al
I was wondering about server-side receipt validation and man-in-the-middle attacks. I asked the question on StackOverflow and it might be easier to check it out rather than rehashing it in this forum.
http://stackoverflow.com/questions/14243909/apple-in-app-purchase-receipt-verification
Thanks for the tutorial. Best of luck
Al
- ajmccall
- n00b
- Posts: 1
- Joined: Mon Jan 14, 2013 12:52 pm
- Has thanked: 0 time
- Been thanked: 0 time
Re: In-App Purchases in iOS 6 Tutorial: Consumables and Rece
Hi,
thank you for the great tutorials.
Just a small remark.
In the previous tutorial the restoreTransaction method uses "originalTransaction" (transaction.originalTransaction.payment.productIdentifier).
Like so:
In this new tutorial, "validateReceiptForTransaction" always works with: "transaction.payment.productIdentifier".
"originalTransaction" is not used.
Is this on purpose?
Also, if validate receipt does not succeed, it appears that the following code will get called twice:
Once in "validateReceiptForTransaction" and once in for example "completeTransaction".
Any harm done by this?
Thanks again.
All the best
Ralph
thank you for the great tutorials.
Just a small remark.
In the previous tutorial the restoreTransaction method uses "originalTransaction" (transaction.originalTransaction.payment.productIdentifier).
Like so:
- Code: Select all
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
[self provideContentForProductIdentifier:transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
[self provideContentForProductIdentifier:transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
In this new tutorial, "validateReceiptForTransaction" always works with: "transaction.payment.productIdentifier".
"originalTransaction" is not used.
Is this on purpose?
Also, if validate receipt does not succeed, it appears that the following code will get called twice:
- Code: Select all
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
Once in "validateReceiptForTransaction" and once in for example "completeTransaction".
Any harm done by this?
Thanks again.
All the best
Ralph
- Ralph
- n00b
- Posts: 1
- Joined: Mon Feb 04, 2013 11:04 am
- Has thanked: 0 time
- Been thanked: 0 time
17 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 3 guests