# IAP - slow card responses and where to put iap.finish()

**URL:** <https://forum.defold.com/t/iap-slow-card-responses-and-where-to-put-iap-finish/78802>\
**Category:** Questions\
**Created:** [November 7, 2024, 11:24am UTC](https://forum.defold.com/t/iap-slow-card-responses-and-where-to-put-iap-finish/78802 "2024-11-07T11:24:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![urh](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/u/c0e974/32.png) [@urh](https://forum.defold.com/u/urh)\
**Post date:** [November 7, 2024, 11:24am UTC](https://forum.defold.com/t/iap-slow-card-responses-and-where-to-put-iap-finish/78802/1 "2024-11-07T11:24:44Z")

</div>

Setup: mobile game for android.

After reading [extension-iap tutorial](https://defold.com/extension-iap/), [api reference](https://defold.com/extension-iap/iap_api/#iap.finish:transaction), [google’s tutorial on billing](https://developer.android.com/google/play/billing/integrate), looking at [extension-iap demo project](https://github.com/defold/extension-iap/blob/master/main/main.gui_script) and checking out different topic on this forum, I still have some questions about implementing IAP using _extension-iap_.

1. **Where to put `iap-finish(transaction)` and `iap.acknowledge(transaction)`?** API reference states _“The transaction.state field must equal iap.TRANS\_STATE\_PURCHASED.”_. So if ` transaction.state` is something else, I do not have to finish or acknowledge the transaction? And what is the difference between those two?
2. Do I need to do anything special when the transaction.state is NOT PURCHASED, but something else?
3. **Dealing with slow card responses.** How to correctly deal with slow card responses? When testing slow test card, I sometimes get the same error as described [in this post.](https://forum.defold.com/t/issue-when-purchase-testing-android-iap-product-using-slow-test-card-method/71474), but since a succesful transaction will still finish with `TRANS_STATE_PURCHASING`, I can live with that. My game will give the user the bought product only when `iap.TRANS_STATE_PURCHASING`message is fetched with iap-listener.  
But what happens if the user exits the game **before** that happens? Will calling `iap.list()` or setting `iap.set_listener(iap_listener)` check for unverified purchases? If not, is there a way to do that?  
Or will such transaction never be verified (and be refunded by google play after three days)..

---

<div class="post-metadata">

**Author:** ![Chung\_Xa](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/chung_xa/32/34470_2.png) [@Chung\_Xa](https://forum.defold.com/u/Chung_Xa)\
**Post date:** [November 7, 2024, 2:44pm UTC](https://forum.defold.com/t/iap-slow-card-responses-and-where-to-put-iap-finish/78802/2 "2024-11-07T14:44:23Z")

</div>

From my experience, you should use `iap.finish()` when you got `iap.TRANS_STATE_PURCHASED` message in your iap listener and verified it with your server. But if you want to use `iap.finish()` you should disable auto-completion (this feature automatically finish transactions right when it’s purchased) at the IAP section of game.project file.

> [@urh](#):
>
> Do I need to do anything special when the transaction.state is NOT PURCHASED, but something else?

I think it depends but generally you can skip it

> [@urh](#):
>
> But what happens if the user exits the game **before** that happens?

You shouldn’t worry about it because the payment will be refunded to that user card after a few days because your app hasn’t call `iap.finish()`, thus, when user close the app, the listener also released, nothing handled

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [November 7, 2024, 9:04pm UTC](https://forum.defold.com/t/iap-slow-card-responses-and-where-to-put-iap-finish/78802/3 "2024-11-07T21:04:52Z")

</div>

> [@urh](#):
>
> Where to put `iap-finish(transaction)` and `iap.acknowledge(transaction)`?

Check out the “Life of a purchase” document for Google Play Billing.

> **[Life of a purchase - Integrate the Google Play Billing Library into your app  | ...](https://developer.android.com/google/play/billing/integrate#life)**
>
> This document describes how to integrate the Google Play Billing Library into your app to start selling products. | This guide details the process of integrating the Google Play Billing Library into an Android app, covering initialization, product...

The lifecycle is:

1. Show the user what they can buy.
2. Launch the purchase flow for the user to accept the purchase.
3. Verify the purchase on your server.
4. Give content to the user.
5. Acknowledge delivery of the content. For consumable products, consume the purchase so that the user can buy the item again.

As you can see from this flow you are meant to call iap.acknowledge() once you have given the content to the user. And then, if the product is consumable, you also consume the product, which you do by calling iap.finish().

> [@urh](#):
>
> - Do I need to do anything special when the transaction.state is NOT PURCHASED, but something else?

Each of them has a specific meaning:

- TRANS\_STATE\_FAILED - show an error to the user
- TRANS\_STATE\_PURCHASED - deliver the item to the user (before optional server side verification etc)
- TRANS\_STATE\_PURCHASING - show the user that the purchase is in progress
- TRANS\_STATE\_RESTORED - you get this on iOS when restoring purchased products
- TRANS\_STATE\_UNVERIFIED - the purchase is in an unspecified state

> [@urh](#):
>
> But what happens if the user exits the game **before** that happens? Will calling `iap.list()` or setting `iap.set_listener(iap_listener)` check for unverified purchases? If not, is there a way to do that

Ongoing purchases which have not failed or finished will be received again when you set the IAP listener function. This will be true until the purchase has failed or the purchase has completed and you have called iap.finish() etc
