3. 3
In App Purchase
Users use their Apple ID purchase virtual product(s)
Developer use receipt(s) to implement business logic
Financial receive simple report
14. 14
How server validate a receipt
1.Apple API
receipt product_id
receipt bid
receipt duration(auto-renewable)
https://sandbox.itunes.apple.com/verifyReceipt
https://buy.itunes.apple.com/verifyReceipt
2.DB
ensure receipt transaction_id not used
16. 16
Overview (bad side)
3.1.1 In-App Purchase, 3.1.2 Subscriptions:
If you want to unlock features or functionality within your app,you must use in-app purchase
only verify API, no webhook
When user cancel on iTunes ,Server will not get cancel request.
Can not know which Apple ID user use
Can not know purchase condition until receive receipt
18. 18
Receive sandbox receipt on production environment
production validate API ->
receive 21007 status code ->
try sandbox API
Solution:
19. 18
Receive sandbox receipt on production environment
production validate API ->
receive 21007 status code ->
try sandbox API
Solution:
Look like workaround,but it’s spec
21. 19
Critical:Network condition bad When Upload receipt to server
Business logic
Purchase
Manager
Purchase
Manager
StoreKit
Purchase
ViewController
SKProductsRequestDelegate
SKPaymentTransactionObserverdelegatedelegate
Solution:
cache receipts , remove cache after ensure receipt is uploaded
22. 19
Critical:Network condition bad When Upload receipt to server
Business logic
Purchase
Manager
Purchase
Manager
StoreKit
Purchase
ViewController
SKProductsRequestDelegate
SKPaymentTransactionObserverdelegatedelegate
cache receipts
Solution:
cache receipts , remove cache after ensure receipt is uploaded
23. 19
Critical:Network condition bad When Upload receipt to server
Business logic
Purchase
Manager
Purchase
Manager
StoreKit
Purchase
ViewController
SKProductsRequestDelegate
SKPaymentTransactionObserverdelegatedelegate
cache receipts
trigger API
remove receipts
Solution:
cache receipts , remove cache after ensure receipt is uploaded
24. 19
Critical:Network condition bad When Upload receipt to server
Business logic
Purchase
Manager
Purchase
Manager
StoreKit
Purchase
ViewController
SKProductsRequestDelegate
SKPaymentTransactionObserverdelegatedelegate
cache receipts
trigger API
remove receipts
UI
Solution:
cache receipts , remove cache after ensure receipt is uploaded
25. 20
User purchase on iTunes instead of app
case 1
1.touch purchase product on App
2.when validate AppleID, type wrong password more than 3 times
3.StoreKit ask user to change password
4.redirect to iTunes
5.type correct password and user can purchase on iTunes
26. 21
User purchase on iTunes instead of app
touch this
itms-apps://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptionscase 2
27. 22
User purchase on iTunes instead of app
case 2 https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions
touch this
28. 23
User purchase on iTunes instead of app
Business logic
Purchase
Manager
Purchase
Manager
StoreKit
Purchase
ViewController
SKProductsRequestDelegate
SKPaymentTransactionObserverdelegate
delegate
Solution: init purchase manager at app launch
29. 23
User purchase on iTunes instead of app
Business logic
Purchase
Manager
Purchase
Manager
StoreKit
Purchase
ViewController
SKProductsRequestDelegate
SKPaymentTransactionObserverdelegate
delegate
Solution: init purchase manager at app launch
AppDelegate init at app launch
45. 31
iOS 6 vs iOS 7 style transaction receipts
• each transaction has unique iOS 6 style receipt
• iOS 7 style receipt get all receipt data in one query
• base64 encode iOS 7 style receipt is much larger than iOS 6 style
48. 33
Can I manage auto-renewable subscription in Sandbox ?
No.
In addition,sandbox will auto-renew 5 times.
in the end will get 6 receipt
49. 34
What will user see in iTune Connect If my app have multiple auto-
renewable products( A & B)?
50. 34
What will user see in iTune Connect If my app have multiple auto-
renewable products( A & B)?
https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/
manageSubscriptions
This URL will only work for production accounts to display existing auto-renewing
subscriptions for management
51. 35
purchase
product A in app
cancel
auto-renew A
in iTune
purchase
product B in app
product A
expire
What will user see in iTune Connect If my app have multiple auto-
renewable products( A & B)?
52. 35
purchase
product A in app
cancel
auto-renew A
in iTune
purchase
product B in app
product A
expire
What will user see in iTune Connect If my app have multiple auto-
renewable products( A & B)?
iTune display product A product B
53. 36
You can not do anything If
You have a auto renewable product,also set trial period(Eq:1 month)
But Apple receipt trial period is more than your setting
KKTV happen this few times
54. 37
if your service has
account system + multiple platform + multiple payment
55. 37
if your service has
account system + multiple platform + multiple payment
email
facebook
phone number
iOS
Android
Web
PS4
…
IAP
credit card
mobile payment
POSA card
redeem code
convenient store code
65. 43
Conclusion
• IAP is unfriendly to Developer. But super easy for user.
• Tracking IAP log help find unexpected problems
• Raise IAP price could be an option
66. 44
Reference
TN2387:In-App Purchase Best Practices
TN2413: In-App Purchase FAQ
In-App Purchase Programming Guide
Receipt Validation Programming Guide
WWDC 2016: Using StoreKit for In-App Purchases with Swift 3
WWDC 2014: Optimizing In-App Purchases
WWDC 2012: Selling Products with Store Kit
WWDC 2013: Using Store Kit for In-App Purchases
WWDC 2012: Managing Subscriptions with In-App Purchase
TN2259: Adding In-App Purchase to your iOS and macOS Applications
https://forums.developer.apple.com/community/system-frameworks/in-app-purchase