Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Dealing with promo codes and trials

Discussion in 'Unity IAP' started by novaVision, Dec 8, 2022.

  1. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    I see some notes about promo codes redeemtion in unity IAP package changelogs, but checking manual and documentation I didn't find any API to use it.

    So, what I need is to use predefined promo code to give an access to subscription.
    How to implement it?

    Also, not clear how to deal with free trials
     
  2. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    268
    Promo codes and trials are setup in your stores directly (Google Play Store, Apple Store).
    Here's a few useful links:
    Google Play Store - Promo codes
    Google Play Store - Setting up subscriptions with trials
    Apple Store - Set up an introductory offer for an auto-renewable subscription
    Apple Store - Set up offer codes

    For promo codes, those are redeemed in the store (we don't support in-app redemption at the moment) and are treated as out of app purchases when it occurs, the store will send a notification to the Unity IAP which will be processed in the processPurchase.

    For subscriptions with trials, these will be an option in the store's purchase UI instead of paying with money (if eligible). Those will also be processed in the processPurchase, but you can identify them with
    SubscriptionManager.getSubscriptionInfo().isFreeTrial()
     
    ArthurMWM likes this.
  3. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    I can't understand the flow. So let's say user get his code and activated it in App Store app on iOS (should be something similar on Android). What's next? User downloads the app and...? How to identify, does user has that subscription or not? Should I call "Restore purchase" or it will be managed automatically after first Unity IAP initialization?
    Also, is there a way to identify, is that subscription purchased or gained by a promo code?


    Is there any workaround? What if create some native code bridge (kind of plugin) to open that native redeemtion sheet? May it work?
     
    Last edited: Dec 9, 2022
  4. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    268
    When a promo code is redeemed, Apple will notify the application that it was redeemed. The flow is the same as a purchase, it will go through the ProcessPurchase.
    On your end, there's nothing more to do to support promo codes!

    Subscriptions gained by a promo code are treated the same as a purchase. As far as I know, there's nothing to identify how it was obtained.


    For Google, we do support in-app redemption. This is an option when selecting the payment method, nothing to do on your end.

    For Apple, we have PresentCodeRedemptionSheet() in IAppleExtensions to open the native redemption sheet. However, there's been reports that this isn't fully working. If it doesn't work, a workaround would be to restore transactions.
     
  5. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    Wow, why you don't mention such points in documentation. I didn't find it before you said. I tested it - I see that native popup, and interesting thing here:
    1. if I reddem the Custom Code it says the offer is expired, but it's not (1 year more till expire)
    2. if I redeem one-time code the popup is being updated but with some wrong data, only app icon is actual. No callbacks received
      IMG_4422.PNG
    I checked tons of threads and discusssion about issue redeeming the code on iOS and there are many different opinions, still didn't find any "actual" one. In general, many developers replies that testing Promo Code in iOS require the app to be published, while others says that RedemptionSheet called within the app allows to use it even without publishing. This doesn't work on my end.

    So, the biggest problem for now - how to test these Promo Codes in development builds? Sounds pretty weird, why it's not that easy to do before you prepare the app completely and tested properly (before publishing)
     
  6. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    268
  7. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    I finally could test it in our release version. We didn't use "PresentCodeRedemptionSheet" this release (will add it next time) and I assume the flow you described relates to PresentCodeRedemptionSheet usage.

    However I could test it using AppStore > Account > Redeem Goft Card or Code option using one time code.
    Code been accepted. I launched the app, but I didn't get any callbacks from IAP about the transaction or purchase to identify the code was redeemed. The only way was to click "Restore Purchases" button and only after that app could identify the applied code.
    Should it be like that? Is there any option to avoid the step to click "Restore Purchase"? I would make it as smooth as possible and let the user proceed just after he launched the app
     
    Ontario likes this.
  8. Ontario

    Ontario

    Joined:
    Jun 14, 2013
    Posts:
    4
    Is PresentCodeRedemptionSheet() fully working now? It presents properly on iPad, but doesn't redeem recognized codes.
     
  9. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    I have implemented and tested it. I can tell you 1 thing for sure - it works same way as all the features works in Unity.
    • redemtion sheet opens, but if you close it and open again, then input promo code you will get the error message that the code is not valid. The only solution - restart the app. This means user may use your code from the first try, and may not understand that he need to restart the app
    • after you input the code it will show you that all done with a button to continue. The tap to that button doesn't do anything... You need to close the popup
    At least purchase complete callback received in the background. Closing the popup my app proceeds same way as user would buy any of the provided subscriptions.

    Shame to you Unity. You added that popup, but you even didn't test it and didn't try to find a way, how developers may use it. At least add the method to close that native popup. In that case I can close the popup with pointless "continue" buttons at least.

    P.S. I didn't test the one time code yet.
     
    Ontario likes this.
  10. prasetion

    prasetion

    Joined:
    Apr 3, 2014
    Posts:
    28
    did you try input promo code using PresentCodeRedemptionSheet using testfligth? or you have already pass review and release the app?
     
  11. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    No, it will never work in TestFlight. At least Unity and it's old InAppPurchasing package doesn't provide that option.
    The only way to ensure it works - try it in release build. And even doing that you will meet the bugs I described.
     
  12. lasheenl

    lasheenl

    Joined:
    Jul 22, 2016
    Posts:
    1
    Hi novaVision

    I see how frustrating this is, I am looking to implement offer codes in my app myself.

    I didn't quite understand this point you made "redemption sheet opens, but if you close it and open again, then input promo code you will get the error message that the code is not valid. The only solution - restart the app. This means user may use your code from the first try, and may not understand that he need to restart the app"

    Why does the user need to restart the app in order for it to recognise the code. I was thinking of adding a continue button/pop up on the UI. When the user click redeem on my UI I will make visible the continue pop up before the app store pop up is triggered. This way after completion of the ios redeem code UI I can run a restore purchases on that continue button, if there is a valid subscription then go to the next page otherwise let the user know the redeem offer was ineffective. Do you see any problems with this?

    Hopefully I explained this well. Its a work around to a problem that should have been tested by unity but hopefully this would do the job.
     
  13. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    If I remember it properly the problem was that native popup were not closed after redemtion. Just because it made as everything in Unity. In the fact, you can still receive the IAP purchase callback and if you develop some kind of native plugin to close that popup - that's the way to go. However, I didn't find any ready to use solution and didn't wish to spend time to write that plugin. Promo codes in our case used just for a free access for a specific users group (teachers) so it's not a big for them to restart the app once after.