SlideShare ist ein Scribd-Unternehmen logo
1 von 66
Downloaden Sie, um offline zu lesen
IAP auto-renewable
in practice
Cocoaheads Taipei ,2016.12
2
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
4
step 1~7
get products user can purchase 

5
6
NSSet *productsIDSet = ["product_identifiers1","product_identifiers2"]
self.productRequest = [[SKProductsRequest alloc]
initWithProductIdentifiers:productsIDSet];
productRequest.delegate = self;
[productRequest start];
7
SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
NSLog(@"receive products %@", response.products);
NSLog(@"invalidProductIdentifiers %@", response.invalidProductIdentifiers);
self.products = response.products;
……
}
[SKProduct] from productsIDSet
8
step 8
user select product to buy 

9
step 8
user select product to buy 

- (void)purchaseProduct:(SKProduct *)inProduct
{
SKPayment *p = [SKPayment paymentWithProduct:inProduct];
[[SKPaymentQueue defaultQueue] addPayment:p];
}
10
step 9 ~11
validate user AppleID/password 

11
step 12 ~14
receive receipt

12
SKPaymentTransactionObserver
- (void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions
{
NSMutableArray *purchasedTransactions = [NSMutableArray array];
for (SKPaymentTransaction *t in transactions) {
switch (t.transactionState) {
case SKPaymentTransactionStatePurchased:
[purchasedTransactions addObject:t];
[[SKPaymentQueue defaultQueue] finishTransaction:t];
break;
//ignore other case in sample code
}
}
if ([purchasedTransactions count] > 0) {
//handle receipts here,continue step 15
}
}
13
step 15~19
verify receipt with Apple server / Your server

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
15
step 20
Deliver purchased content

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
17
A lot of problems we met
18
Receive sandbox receipt on production environment
production validate API ->
receive 21007 status code ->
try sandbox API
Solution:
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
19
Critical:Network condition bad When Upload receipt to server
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
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
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
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
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
21
User purchase on iTunes instead of app
touch this
itms-apps://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptionscase 2
22
User purchase on iTunes instead of app
case 2 https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions
touch this
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
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
24
What is receipt (app side)
SKPaymentTransaction
@property(nonatomic, readonly, nullable) NSData *transactionReceipt
/* base64 encode string */
NSString *receiptString = [receipt base64EncodedStringWithOptions:0];
24
What is receipt (app side)
SKPaymentTransaction
@property(nonatomic, readonly, nullable) NSData *transactionReceipt
/* base64 encode string */
NSString *receiptString = [receipt base64EncodedStringWithOptions:0];
25
What is receipt (server side)
25
What is receipt (server side)
25
What is receipt (server side)
26
Critical: Auto-renew fail but user receive charge mail
26
Critical: Auto-renew fail but user receive charge mail
Solution: Trigger Verify API at Next day of expire_date
Not the same day
27
When switch from objC to swift
28
When switch from objC to swift
28
When switch from objC to swift
transactionReceipt property missing
can only use iOS 7 style receipt
29
iOS 7 receipt
29
iOS 7 receipt
29
iOS 7 receipt
30
iOS 7 receipt
30
iOS 7 receipt
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
32
Will original_transaction_id change?
purchase cancel purchase
again
A C
renew
a long time
B
32
Will original_transaction_id change?
purchase cancel purchase
again
A C
original_transaction_id in receipt A , B and C keep the same
renew
a long time
B
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
34
What will user see in iTune Connect If my app have multiple auto-
renewable products( A & B)?
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
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)?
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
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
37
if your service has
account system + multiple platform + multiple payment
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
38
Example:
User Apple ID KKTV
iTunes
KKTV
Result:
StoreKit
39
Example:
User Apple ID KKTV
iTunes
KKTV
Result:
receipt server
KKTV
Solution:
receipt Alert
39
Example:
User Apple ID KKTV
iTunes
KKTV
Result:
receipt server
KKTV
Solution:
receipt Alert
40
Example:
user IAP
iTunes IAP
40
Example:
user IAP
iTunes IAP
Result
IAP user
40
Example:
user IAP
iTunes IAP
Result
IAP user
Solution
app/server side user iTunes
41
Example:
user
IAP
..... KKTV
KKTV IAP
41
Example:
user
IAP
Result
AppleID user
..... KKTV
KKTV IAP
42
Financial
• report daily
• report user ID transactionID
• user cancel / refund
•
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
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

Weitere ähnliche Inhalte

Was ist angesagt?

ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CS
tutorialsruby
 

Was ist angesagt? (6)

Dependency injection in Java, from naive to functional
Dependency injection in Java, from naive to functionalDependency injection in Java, from naive to functional
Dependency injection in Java, from naive to functional
 
Distributed banking system using rmi project
Distributed banking system using rmi projectDistributed banking system using rmi project
Distributed banking system using rmi project
 
Webauthn Tutorial
Webauthn TutorialWebauthn Tutorial
Webauthn Tutorial
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Application Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The UglyApplication Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The Ugly
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CS
 

Andere mochten auch

快思慢想讀書會Ch9 10
快思慢想讀書會Ch9 10快思慢想讀書會Ch9 10
快思慢想讀書會Ch9 10
Hokila Jan
 
第五章 認知放鬆度 第六章_常模_驚訝與原因
第五章 認知放鬆度 第六章_常模_驚訝與原因第五章 認知放鬆度 第六章_常模_驚訝與原因
第五章 認知放鬆度 第六章_常模_驚訝與原因
Jimmy Yu
 
THT IAP Certification Presentation Day2 7Dec2010
THT IAP Certification Presentation Day2 7Dec2010THT IAP Certification Presentation Day2 7Dec2010
THT IAP Certification Presentation Day2 7Dec2010
Trompenaars Hampden-Turner
 

Andere mochten auch (20)

SwiftyJSON 慘痛經驗
SwiftyJSON   慘痛經驗SwiftyJSON   慘痛經驗
SwiftyJSON 慘痛經驗
 
接案公司的日子
接案公司的日子接案公司的日子
接案公司的日子
 
軟體接案自由職業者 (Freelancer) 意想不到的風險
軟體接案自由職業者 (Freelancer) 意想不到的風險軟體接案自由職業者 (Freelancer) 意想不到的風險
軟體接案自由職業者 (Freelancer) 意想不到的風險
 
恰如其分的 MySQL 設計技巧 [Modern Web 2016]
恰如其分的 MySQL 設計技巧 [Modern Web 2016]恰如其分的 MySQL 設計技巧 [Modern Web 2016]
恰如其分的 MySQL 設計技巧 [Modern Web 2016]
 
快思慢想讀書會Ch9 10
快思慢想讀書會Ch9 10快思慢想讀書會Ch9 10
快思慢想讀書會Ch9 10
 
第五章 認知放鬆度 第六章_常模_驚訝與原因
第五章 認知放鬆度 第六章_常模_驚訝與原因第五章 認知放鬆度 第六章_常模_驚訝與原因
第五章 認知放鬆度 第六章_常模_驚訝與原因
 
Uxpa 2012 Intersection between Accessibility & Plain Language
Uxpa 2012 Intersection between Accessibility & Plain LanguageUxpa 2012 Intersection between Accessibility & Plain Language
Uxpa 2012 Intersection between Accessibility & Plain Language
 
THT IAP Certification Presentation Day2 7Dec2010
THT IAP Certification Presentation Day2 7Dec2010THT IAP Certification Presentation Day2 7Dec2010
THT IAP Certification Presentation Day2 7Dec2010
 
Pattern Recognition midterm Proposal
Pattern Recognition midterm ProposalPattern Recognition midterm Proposal
Pattern Recognition midterm Proposal
 
The Future of Classical Music
The Future of Classical MusicThe Future of Classical Music
The Future of Classical Music
 
2014-10-25 App 及 Maker 開發者防身術 (MOPCON 2014)
2014-10-25 App 及 Maker 開發者防身術 (MOPCON 2014)2014-10-25 App 及 Maker 開發者防身術 (MOPCON 2014)
2014-10-25 App 及 Maker 開發者防身術 (MOPCON 2014)
 
In-App Purchase
In-App PurchaseIn-App Purchase
In-App Purchase
 
2016 ModernWeb 分享 - 恰如其分 MySQL 程式設計 (修)
2016 ModernWeb 分享 - 恰如其分 MySQL 程式設計 (修)2016 ModernWeb 分享 - 恰如其分 MySQL 程式設計 (修)
2016 ModernWeb 分享 - 恰如其分 MySQL 程式設計 (修)
 
談 Uber 從 PostgreSQL 轉用 MySQL 的技術爭議
談 Uber 從 PostgreSQL 轉用 MySQL 的技術爭議談 Uber 從 PostgreSQL 轉用 MySQL 的技術爭議
談 Uber 從 PostgreSQL 轉用 MySQL 的技術爭議
 
Lecture 06. iOS Programming. Основи Objective-C
Lecture 06. iOS Programming. Основи Objective-CLecture 06. iOS Programming. Основи Objective-C
Lecture 06. iOS Programming. Основи Objective-C
 
資料庫索引數據結構及主鍵設計(b+tree)(part 1)
資料庫索引數據結構及主鍵設計(b+tree)(part 1)資料庫索引數據結構及主鍵設計(b+tree)(part 1)
資料庫索引數據結構及主鍵設計(b+tree)(part 1)
 
Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)
 
淺入淺出 MySQL & PostgreSQL
淺入淺出 MySQL & PostgreSQL淺入淺出 MySQL & PostgreSQL
淺入淺出 MySQL & PostgreSQL
 
Redis, another step on the road
Redis, another step on the roadRedis, another step on the road
Redis, another step on the road
 
適合資工系畢業生的 一百零一種工作
適合資工系畢業生的  一百零一種工作適合資工系畢業生的  一百零一種工作
適合資工系畢業生的 一百零一種工作
 

Ähnlich wie IAP auto renewable in practice

Diving into VS 2015 Day4
Diving into VS 2015 Day4Diving into VS 2015 Day4
Diving into VS 2015 Day4
Akhil Mittal
 
Android In-App Billing @ Droidcon 2011
Android In-App Billing @ Droidcon 2011Android In-App Billing @ Droidcon 2011
Android In-App Billing @ Droidcon 2011
Robot Media
 
Android In-App Billing @ Barcelona GTUG
Android In-App Billing @ Barcelona GTUGAndroid In-App Billing @ Barcelona GTUG
Android In-App Billing @ Barcelona GTUG
Robot Media
 
Azure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptxAzure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptx
pythagorus143
 

Ähnlich wie IAP auto renewable in practice (20)

Self checkout application presentation
Self checkout application presentationSelf checkout application presentation
Self checkout application presentation
 
PowerBI Embedded in D365 Finance and Operations
PowerBI Embedded in D365 Finance and OperationsPowerBI Embedded in D365 Finance and Operations
PowerBI Embedded in D365 Finance and Operations
 
Dropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudDropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google Cloud
 
API Security - OWASP top 10 for APIs + tips for pentesters
API Security - OWASP top 10 for APIs + tips for pentestersAPI Security - OWASP top 10 for APIs + tips for pentesters
API Security - OWASP top 10 for APIs + tips for pentesters
 
App Store Subscriptions - Condensed Edition
App Store Subscriptions - Condensed EditionApp Store Subscriptions - Condensed Edition
App Store Subscriptions - Condensed Edition
 
Diving into VS 2015 Day4
Diving into VS 2015 Day4Diving into VS 2015 Day4
Diving into VS 2015 Day4
 
Adjust Workshop - PUSHING AND PULLING YOUR DATA
Adjust Workshop - PUSHING AND PULLING YOUR DATA Adjust Workshop - PUSHING AND PULLING YOUR DATA
Adjust Workshop - PUSHING AND PULLING YOUR DATA
 
Android In-App Billing @ Droidcon 2011
Android In-App Billing @ Droidcon 2011Android In-App Billing @ Droidcon 2011
Android In-App Billing @ Droidcon 2011
 
QSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & AQSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & A
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
 
Android In-App Billing @ Barcelona GTUG
Android In-App Billing @ Barcelona GTUGAndroid In-App Billing @ Barcelona GTUG
Android In-App Billing @ Barcelona GTUG
 
Rethinking your mobile tracking strategy by Ekaterina Petrakova
Rethinking your mobile tracking strategy by Ekaterina PetrakovaRethinking your mobile tracking strategy by Ekaterina Petrakova
Rethinking your mobile tracking strategy by Ekaterina Petrakova
 
5 Things Every Product Leader Needs to Know About API
5 Things Every Product Leader Needs to Know About API5 Things Every Product Leader Needs to Know About API
5 Things Every Product Leader Needs to Know About API
 
Z101666 best practices for delivering hybrid cloud capability with apis
Z101666 best practices for delivering hybrid cloud capability with apisZ101666 best practices for delivering hybrid cloud capability with apis
Z101666 best practices for delivering hybrid cloud capability with apis
 
Implémentez une intégration avec AEM presque sans code
Implémentez une intégration avec AEM presque sans codeImplémentez une intégration avec AEM presque sans code
Implémentez une intégration avec AEM presque sans code
 
Introduction to aop
Introduction to aopIntroduction to aop
Introduction to aop
 
Microsoft AZ-204 Exam Dumps
Microsoft AZ-204 Exam DumpsMicrosoft AZ-204 Exam Dumps
Microsoft AZ-204 Exam Dumps
 
Thinking Serverless (AWS re:Invent 2019 chalk talk SVS213). Solutions slides.
Thinking Serverless (AWS re:Invent 2019 chalk talk SVS213). Solutions slides.Thinking Serverless (AWS re:Invent 2019 chalk talk SVS213). Solutions slides.
Thinking Serverless (AWS re:Invent 2019 chalk talk SVS213). Solutions slides.
 
Preparing_for_PCA_Workbook.pptx
Preparing_for_PCA_Workbook.pptxPreparing_for_PCA_Workbook.pptx
Preparing_for_PCA_Workbook.pptx
 
Azure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptxAzure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptx
 

Mehr von Hokila Jan (9)

Tracking Event validator
Tracking Event validatorTracking Event validator
Tracking Event validator
 
Preparation for wwdc and not waste it
Preparation for wwdc and not waste itPreparation for wwdc and not waste it
Preparation for wwdc and not waste it
 
Third party module strategy
Third party module strategyThird party module strategy
Third party module strategy
 
How to cheat jb detector and detect cheating
How to cheat jb detector and detect cheatingHow to cheat jb detector and detect cheating
How to cheat jb detector and detect cheating
 
進擊的帳單
進擊的帳單進擊的帳單
進擊的帳單
 
讓你的App優雅的crash三部曲
讓你的App優雅的crash三部曲讓你的App優雅的crash三部曲
讓你的App優雅的crash三部曲
 
iOS app security
iOS app security  iOS app security
iOS app security
 
快思慢想Ch13 14
快思慢想Ch13 14快思慢想Ch13 14
快思慢想Ch13 14
 
從Scrum到放棄scrum
從Scrum到放棄scrum從Scrum到放棄scrum
從Scrum到放棄scrum
 

Kürzlich hochgeladen

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

IAP auto renewable in practice

  • 2. 2
  • 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
  • 4. 4 step 1~7 get products user can purchase 

  • 5. 5
  • 6. 6 NSSet *productsIDSet = ["product_identifiers1","product_identifiers2"] self.productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productsIDSet]; productRequest.delegate = self; [productRequest start];
  • 7. 7 SKProductsRequestDelegate - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSLog(@"receive products %@", response.products); NSLog(@"invalidProductIdentifiers %@", response.invalidProductIdentifiers); self.products = response.products; …… } [SKProduct] from productsIDSet
  • 8. 8 step 8 user select product to buy 

  • 9. 9 step 8 user select product to buy 
 - (void)purchaseProduct:(SKProduct *)inProduct { SKPayment *p = [SKPayment paymentWithProduct:inProduct]; [[SKPaymentQueue defaultQueue] addPayment:p]; }
  • 10. 10 step 9 ~11 validate user AppleID/password 

  • 12. 12 SKPaymentTransactionObserver - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { NSMutableArray *purchasedTransactions = [NSMutableArray array]; for (SKPaymentTransaction *t in transactions) { switch (t.transactionState) { case SKPaymentTransactionStatePurchased: [purchasedTransactions addObject:t]; [[SKPaymentQueue defaultQueue] finishTransaction:t]; break; //ignore other case in sample code } } if ([purchasedTransactions count] > 0) { //handle receipts here,continue step 15 } }
  • 13. 13 step 15~19 verify receipt with Apple server / Your server

  • 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
  • 17. 17 A lot of problems we met
  • 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
  • 20. 19 Critical:Network condition bad When Upload receipt to server
  • 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
  • 30. 24 What is receipt (app side) SKPaymentTransaction @property(nonatomic, readonly, nullable) NSData *transactionReceipt /* base64 encode string */ NSString *receiptString = [receipt base64EncodedStringWithOptions:0];
  • 31. 24 What is receipt (app side) SKPaymentTransaction @property(nonatomic, readonly, nullable) NSData *transactionReceipt /* base64 encode string */ NSString *receiptString = [receipt base64EncodedStringWithOptions:0];
  • 32. 25 What is receipt (server side)
  • 33. 25 What is receipt (server side)
  • 34. 25 What is receipt (server side)
  • 35. 26 Critical: Auto-renew fail but user receive charge mail
  • 36. 26 Critical: Auto-renew fail but user receive charge mail Solution: Trigger Verify API at Next day of expire_date Not the same day
  • 37. 27 When switch from objC to swift
  • 38. 28 When switch from objC to swift
  • 39. 28 When switch from objC to swift transactionReceipt property missing can only use iOS 7 style receipt
  • 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
  • 46. 32 Will original_transaction_id change? purchase cancel purchase again A C renew a long time B
  • 47. 32 Will original_transaction_id change? purchase cancel purchase again A C original_transaction_id in receipt A , B and C keep the same renew a long time B
  • 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
  • 56. 38 Example: User Apple ID KKTV iTunes KKTV Result: StoreKit
  • 57. 39 Example: User Apple ID KKTV iTunes KKTV Result: receipt server KKTV Solution: receipt Alert
  • 58. 39 Example: User Apple ID KKTV iTunes KKTV Result: receipt server KKTV Solution: receipt Alert
  • 61. 40 Example: user IAP iTunes IAP Result IAP user Solution app/server side user iTunes
  • 64. 42 Financial • report daily • report user ID transactionID • user cancel / refund •
  • 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