Question

Modifying Purchases.sharedInstance.finishTransactions when necessary: Is it Safe?

  • 9 September 2023
  • 6 replies
  • 156 views

Badge +3

I'm implementing subscriptions in my app using RevenueCat; however, I had already implemented consumable products, validating them on my server.

When I added RevenueCat to the project, I noticed that when a consumable product was purchased, it was automatically consumed, and when the user visited the purchase verification screen (to consume it and gain the content), an error occurred on my server because the purchase had already been consumed by RevenueCat.

I discovered that I can use Purchases.sharedInstance.finishTransactions = false to handle consumable logic as before. However, by doing this, I'll need to manage subscription logic on my server as well, and that's not what I want.

After running some tests, I think I found a way to handle this. Let me explain what I did:

  • When I initialize RevenueCat, I call Purchases.sharedInstance.finishTransactions = false.
  • When I open my subscription PayWall, I call Purchases.sharedInstance.finishTransactions = true. This ensures that when purchasing a subscription, everything runs smoothly with RevenueCat.
  • When the user opens any activity that lists consumable products like coins, credits, etc., I call Purchases.sharedInstance.finishTransactions = false again. This allows me to handle the consumable purchase on my server as I always did before adding RevenueCat to the project.

I'd like to know if this approach is secure and if it's appropriate to change the value of finishTransactions when necessary. It worked correctly in my tests, but I would appreciate validation from someone on the RevenueCat team.

Thank you!


6 replies

Badge

did this end up working @six ?

Badge +3

@christopher-0bb635 Yes, it works well, but I'm still unsure if this could cause any issues later on. I'm still waiting for a response from the team regarding my last post here.

Badge +3

Can someone from the RevenueCat team help me, please? I just need to know if it's safe to change the value of Purchases.sharedInstance.finishTransactions at any time.

Userlevel 4
Badge +6

Hey @six!

I’m not sure that this is the best approach - Apple recommends that if you have anything left to do with a transaction or need to do any work to deliver the product, then it’s not ready to be finished. In this case, the logic with your user on the purchase verification screen. In your workflow, I’d be concerned about step 3, trying to mark `finishTransaction` as false after the consumable has already been acknowledged and consumed in step 2. There wasn’t any issue with this in your testing?

You can see Apples recommendations about finishing transactions here: https://developer.apple.com/documentation/storekit/in-app_purchase/original_api_for_in-app_purchase/finishing_a_transaction

My recommendation here would be to either mark `finishTransactions = false` from the start for consumable products and acknowledge and finish the purchase yourself, or to use alternative logic for granting access to your users. 

Badge +3

Hello @kaitlin  

I apologize; I believe I didn't detail my workflow enough... Below is what I'm actually doing:

Subscriptions
In fact, I set `finishTransactions` to `true` when the user opens my paywall screen containing subscriptions. So, if they successfully subscribe, everything will proceed smoothly using RevenueCat, and I won't need to handle subscription confirmation on my server. I set it to `true` only on the paywall screen so that if the user completes a subscription successfully, everything goes well with RevenueCat.

Consumable products
If the user opens the screen where I list consumable products, I set `finishTransactions` to `false`. This way, if the user buys a package of coins or something that needs to be consumed in my server, to save the quantity obtained in their account, I can confirm everything on my server, which wouldn't be possible with `finishTransactions` set to `true` because the purchase would be automatically consumed by RevenueCat, and my server couldn't reward the user since checking the Google API would indicate that the purchase has already been consumed.

In summary, I set `finishTransactions` to `true` when the user opens the paywall screen containing subscriptions and set `finishTransactions` to `false` when the user opens the screen where they can purchase consumable product packages.

In my tests, this worked well and is exactly what I needed to continue handling consumable products on my server and deal with subscriptions exclusively through RevenueCat. However, I'm not sure if this is the ideal approach, which is why I made this post.

Thanks

Badge +3

Hello @kaitlin, how are you? I apologize for posting again right after my previous post, but it's been a month, and I would like to know if what I described above could cause me any issues. It worked perfectly in my tests, but I just need to know if it's a good practice.

Reply