Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-App Purchase with Promo Code - and how to handle it

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?)

like image 817
Kowboj Avatar asked Oct 22 '18 11:10

Kowboj


People also ask

What happens when you use promo code?

Promotional codes are alphanumeric strings that online stores offer to encourage purchases on their website and are typically associated with an overarching promotional marketing strategy. The discount associated with a promo code can apply to individual products or an entire order.

Where do you enter a promo code?

To use a coupon, click on the offer, and a window will appear where you can copy the code. When you check out on the store's website, paste the code in the promo code field. Stores sometimes call this a promo code, but it is also known as a promotional code, coupon code or, discount code. How do I use a coupon code?


1 Answers

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.

like image 143
Kowboj Avatar answered Nov 03 '22 01:11

Kowboj