Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the penny cost from SKTransaction iOS

Hi I'm trying to do some server integration with my IAPs in my iOS app. The params for what I'm sending to the server require: transaction_ID, product_ID, and pennyCost.

The first two were easy enough to figure out but I can't find the cost. I do have some NSData for the receipt but I can't figure out how to get that into any form I can use. This is my code so far.

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
 NSLog(@"completeTransaction...");

 purchaseComplete = 2;

 NSString *transaction_key = transaction.transactionIdentifier;
 NSString *productID = transaction.payment.productIdentifier;
 NSNumber *pennyCost = transaction.payment.product.pennyCost;

 NSData *rec = [self receiptForPaymentTransaction:transaction];


}

The transaction.payment.product.pennyCost line is invalid.

Any help would be awesome thanks!

like image 416
Sean Calkins Avatar asked May 18 '16 22:05

Sean Calkins


1 Answers

SKPayment doesn't have a price, oddly enough. The price is defined on the SKProduct after retrieving the product using an SKProductRequest.

What you need to do is keep a reference to the SKProduct instances returned from the SKProductRequest. Once you submit a payment to the SKPaymentQueue and you get back your response, use the productId of the SKPayment to find the matching SKProduct.

Now it's possible that you will receive a payment transaction later, after your app has been restarted. In that case, you will have to make a new SKProductRequest to get the SKProduct so you can get the price.

The bad part about all of this is that the price you get for the product could different from what the user is actually charged since you might update the product's pricing in between the time you received the payment transaction and the time you request the product info.

like image 148
rmaddy Avatar answered Oct 23 '22 22:10

rmaddy