Skip to content

5. Consume a Purchased Product

Saeed Moradi edited this page Feb 23, 2022 · 2 revisions

You can consume a product just by calling consumeProduct function in Payment class:

payment.consumeProduct(purchaseToken = "THE ACTUAL PURCHASE TOKEN") {
    consumeSucceed {
        ...
    }
    consumeFailed { throwable ->
        ...
    }
}

purchaseToken -> You get this token in purchaseSucceed callback when user purchases a product. Also you can simple query purchased products by that particular user, using getPurchasedProducts in Payment class, which also gives you purchaseToken to consume. You can read more about querying purchased products from here.

Note that

consumeProduct runs on a background thread and notifies you about the consumption state in the main thread, this means that you don't have to handle threading by your self.

Reactive way of this

payment.consumeProduct(purchaseToken = "THE ACTUAL PURCHASE TOKEN")
    .subscribe({
        // Successfully consumed the product
        ...
    }, { throwable ->
        // Failed to consume the product
        ...
    })