7

I've seen a few topics on stackoverflow on promo codes handling: Detecting promo code, Handling promo code, Consumable promo codes and none of them have the right answer. There are some swift guides on how to create and redeem promo codes for in-app purchases, but nobody talks about what's happening later.

Redeeming an (in-app purchase) promo code on the AppStore:

  • lets you open the app on successful redeeming
  • notifies the transactionObserver declared preferably in the AppDelegate

Some people say it's all you have to do (and then when the user chooses payment there's suddenly no 9,99$ information, but something like 'Use promo code', which StoreKit handles behind the scenes). I'm afraid that doesn't work like that.

Should I handle it somehow in the AppDelegate - if there's a transaction coming right after the app launches (meaning that someone used promo code)? Should I present an alert telling the user he used the promo code, and unlock the functionality or add some 'gems' to his account (if it's consumables)?

EDIT: There are also these two apple developer forum topics: Few people have the same problem - no answer, Apple staff responded about where to place transactionObserver

EDIT2: Or perhaps promo codes cannot be applied to consumable products, which are used once and cannot be restored (using in-app promo codes is based on restoring I've read somewhere?)

Kowboj
  • 351
  • 2
  • 14

1 Answers1

1

For those who got stuck like me.

Indeed you need to declare a class (e.g. PurchaseHelper) importing StoreKit with SKProductsRequestDelegate and SKPaymentTransactionObserver extensions inside AppDelegate.

Then if the user redeems a promo code inside App Store - and he opens your app - 'updatedTransactions' func gets called and it's the only time you can do something with the purchased product.

What I did was - save an info/transactionId to UserDefaults, so in the main screen user gets an alert like "You redeemed a promo code. Choose your favorite spot and click Purchase to get it for free".

Of course a better solution is to do enable the product right away in the AppDelegate. If your promo code gives the user 100$ (consumable) then you can just add it (but there's still question if he is logged in).

If you know any better solutions, please tell me.

Kowboj
  • 351
  • 2
  • 14
  • I am trying this but the promo code never arrives in update transaction. Update Transaction is called upon launch of the app, but it doesn't contain the in-app purchase. Any ideas? https://stackoverflow.com/questions/57772095/redeemed-promo-codes-not-included-in-updatetransaction – paul_f Sep 03 '19 at 22:22
  • 3
    would be amazing if you could post full examples of your code. Everything yin the AppDelegate to make this happen and also the full 'updateTransactions' func. That would help a lot! Thanks :) – Stotch Jul 07 '20 at 16:02