Consumable in app purchases already purchased
I have added a consumable in-app purchase app. I can buy it, but then when I try to buy it, it says I already bought it so that it boots up again. The type is definitely consumed. Where am I going wrong? Thanks to
func purchasePoints(sender:AnyObject) {
//Purchase
buyConsumable()
}
func buyConsumable(){
print("About to fetch the products");
// We check that we are allow to make the purchase.
if (SKPaymentQueue.canMakePayments())
{
var productID:NSSet = NSSet(object: "com.companyname.appname.coins");
var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
productsRequest.delegate = self;
productsRequest.start();
print("Fething Products");
}else{
print("can not make purchases");
}
}
func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
print("got the request from Apple")
var count : Int = response.products.count
if (count>0) {
var validProducts = response.products
var validProduct: SKProduct = response.products[0] as SKProduct
if (validProduct.productIdentifier == "com.companyname.appname.coins") {
print(validProduct.localizedTitle)
print(validProduct.localizedDescription)
print(validProduct.price)
buyProduct(validProduct);
} else {
print(validProduct.productIdentifier)
}
} else {
print("nothing")
}
}
func buyProduct(product: SKProduct){
print("Sending the Payment Request to Apple");
var payment = SKPayment(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment);
}
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [SKPaymentTransaction]) {
print("Received Payment Transaction Response from Apple");
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
print("Product Purchased");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
case .Failed:
print("Purchased Failed");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
// case .Restored:
//[self restoreTransaction:transaction];
default:
break;
}
}
}
}
+3
source to share
1 answer
You saw this message in the console log:
print("Received Payment Transaction Response from Apple");
and
print("Product Purchased");
or
print("Purchased Failed");
?
If not, it looks like you haven't added
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
somewhere before adding the payment to the queue. Try adding this to your buyConsumable method .
Try this with an existing transaction, but make sure it is consumed.
+2
source to share