In-App Purchase consumable can be purchased just once

I am making an app in SwiftUI using an In-app purchase. In this app, the user should be able to buy points as many times as he wants, so I have used consumable products (in the app store connect). But when I've tried to buy them once again I got the information "This In-App purchase has already been bought. It will be restored for free". I've already searched for a way how to do it but none of the ideas worked for me. Here is my StoreManager class:

import Foundation
import StoreKit
import SwiftUI

class StoreManager : NSObject, ObservableObject, SKProductsRequestDelegate {
    
    @EnvironmentObject var authViewModel: AuthViewModel
    
    @Published var transactionState: SKPaymentTransactionState?
    @Published var myProducts = [SKProduct]()
    var request: SKProductsRequest!
    
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        print("Did receive response")
        
        if !response.products.isEmpty {
            for fetchedProduct in response.products {
                    DispatchQueue.main.async {
                        self.myProducts.append(fetchedProduct)
                }
            }
            for invalidIdentifier in response.invalidProductIdentifiers {
                print("Invalid identifiers found: \(invalidIdentifier)")
            }
        }else{
            print("it's empty")
        }
    }
    
    func getProducts(productIDs: [String]) {
        let request = SKProductsRequest(productIdentifiers: Set(productIDs))
        request.delegate = self
        request.start()
    }
    
    func request(_ request: SKRequest, didFailWithError error: Error) {
        print("Request did fail: \(error)")
    }
    
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            switch transaction.transactionState {
            case .purchasing:
                transactionState = .purchasing
                break
            case .purchased:
                print("purchased")
                queue.finishTransaction(transaction)
                transactionState = .purchased
                break
            case .restored:
                print("restored")
                transactionState = .restored
                queue.finishTransaction(transaction)
                break
            case .failed, .deferred:
                    queue.finishTransaction(transaction)
                    transactionState = .failed
                break
                    default:
                    queue.finishTransaction(transaction)
                break
            }
        }
    }
    
    func purchaseProduct(product: SKProduct) {
        
        if SKPaymentQueue.canMakePayments() {
            let payment = SKPayment(product: product)
            SKPaymentQueue.default().add(payment)

        } else {
            print("User can't make payment.")
        }
    }
    
    func restoreProducts() {
        SKPaymentQueue.default().restoreCompletedTransactions()
    }
}

And I am simply using getProducts with onAppear, and purchase product on button's action. Please help me or if an answer to a similar question already exists send me a link to that thread.

Replies

Sounds like Nonconsumable's behaviour purchase once restore as many times. Just double-check your product setup in AppStore Connect for Type Consumable

  • Ok, thanks but I delete everything and set one test in-app purchase as consumable and still it gives me that message.

Add a Comment

Can you elaborate on how and where you are testing this? Is this in Sandbox or in StoreKit testing in Xcode simulator? You note setting up products in App Store Connect so I assume this is testing in sandbox or TestFlight, in which I'd double check the product_id being purchased. If this is in Xcode, then the products are all local and not part of App Store Connect.

Like the previous comment, your observed purchase experience is behavior of a non-consumable product type. Note that this behavior is not determined by your app but rather through our commerce engine server side or simulated in Xcode based on the product type being purchased.

  • Hello, @App Store Commerce Engineer, I am facing the same issue. ** I am elaborating my testing flow**-

    I have the products setup in app store connect as usual as per the product addition rules and policies.I am testing the product using real device and sanbox-id

    But when I want to purchase consumable products more than once, it shows me that "already bought, will be restored for free" like above.

    Can you please check and give me a solution?

  • Hello @App Store Commerce Engineer,

    I am facing the same issue. ** Note that**: I have my products setup properly in app store connect and I am testing using sandbox user in real devices. but when I try to purchase "consumable" prodcucts more than once, I get the message "already bought, will be restored for free" like above.

Add a Comment

Hello @App Store Commerce Engineer , I am facing the same issue. ** Note that**: I have my products setup properly in app store connect and I am testing using sandbox user in real devices. but when I try to purchase "consumable" products more than once, I get the message "already bought, will be restored for free" like above.