3

I have an app that uses non-renewable in-app purchase products. Today I am thinking of releasing some 100 in-app Promo Codes for my initial users.

The in-app purchases work as expected in the app, but I'm unable to figure out what kind of check I need to do on app if the user has redeemed promo-code on App Store already.

ie., How do I check whether a user has redeemed a in-app purchase promo-code when they return to my app?

Edit: I also need the receipt to set an expiry date for the purchased product based on its purchase date. How do I get this receipt?

Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
  • You can't tell; Promo code redemption is treated just like any other purchase. Getting the receipt is covered in the in-app purchase programming guide – Paulw11 Jan 30 '17 at 08:35
  • @Paulw11 That's what I gather from their docs, but it doesn't trigger any of my `SKPaymentTransactionObserver`'s methods once they come back to my app. Docs: https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/ProvidingPromoCodes.html – Nagendra Rao Jan 30 '17 at 08:37
  • Do you add the observer in `didFinishLaunchingWithOptions` or somewhere similar, so that the observer is always in memory? – Paulw11 Jan 30 '17 at 08:49
  • No, only my payment screen has the listener. I will try to move it to AppDelegate. Also, one can redeem promo-code even before installing the app. Not sure having a listener is the right approach for this. I am guessing I need to just try to check if a receipt is present or not. I am also not sure how to get the `SKPaymentTransaction` object. AFAIK receipt won't have all the transaction details which I require to enable my services on the app. – Nagendra Rao Jan 30 '17 at 09:07
  • You should create your payment observer in the AppDelegate (or in an object instantiated and held by the app delegate), as shown in the In-App Purchase Programming guide. It is possible for transactions to complete across execution of your app; I would suspect that in the case of a promo code redemption, the transaction will be presented to your observer when the app is next launched. – Paulw11 Jan 30 '17 at 09:41

1 Answers1

0

basically, you have two ways to do so.

  1. If using StoreKit1, in this doc, Implementing Offer Codes in Your App , it says

When customers redeem a valid offer code, your app receives a successful transaction on the payment queue, and you receive a server notification if you’ve enabled App Store Server Notifications. The receipt contains an offer_code_ref_name field that identifies the offer. basically you can retrieve offer_code_ref_name from the receipt structure.

  1. If using StoreKit2, you can use OfferID and OfferType in Transaction

To identify offer code redemptions, including pending redemptions, use the OfferID and OfferType transaction properties in StoreKit, alongside the App Store Server API and App Store Server Notifications. --- https://developer.apple.com/app-store/subscriptions/#offer-codes

RY_ Zheng
  • 3,041
  • 29
  • 36