SlideShare uma empresa Scribd logo
1 de 70
@robot_media
Android In-App Billing
        Demystified




       Hermés Piqué
         @hpique
Agenda

• In-App Billing Overview
• In-App Billing in Android
• Android Market Billing Service
• Android Billing Library
Freemium
Digital goods
Digital content
Subscriptions
Virtual currency
IAB for the user...

• Faster
• Simpler
• Contextual
• “Harmless”
• “Inexpensive”
IAB generates
  more sales
Agenda

• In-App Billing Overview
• In-App Billing in Android
• Android Market Billing Service
• Android Billing Library
Options

• Android Market In-App Billing
• PayPal Mobile Payments Library
• Others
• Any web payment processor
• Custom implementation
Android Market IAB

• Android Market only
• 30% of the sale price
• Android 1.6 upwards
• Only digital goods
PayPal Mobile Payments
• Starts at 2.9% of
  the sale price +
  transaction fee
• Android 1.5
  upwards
• Physical goods
  allowed
Others

• Paythru
• Movend
• Open Payments
• ...
“All fees received by Developers for Products
distributed via the Market must be processed by the
             Market's Payment Processor.”
   http://www.android.com/us/developer-distribution-agreement.html
Agenda

• In-App Billing Overview
• In-App Billing in Android
• Android Market Billing Service
• Android Billing Library
Purchase type

• Managed per user account
 •   premium, digital content, unique virtual goods

• Unmanaged
 •   subscriptions, virtual currency, unlimited virtual
     goods
Pre-requisites

• Services
• AIDL
• BroadcastReceiver
• PendingIntent
Overview

app
                      Android
  IAB                 Market
requests
                       Server
Messaging sequence
IAB requests

• CHECK_BILLING_SUPPORTED
• REQUEST_PURCHASE
• GET_PURCHASE_INFORMATION
• CONFIRM_NOTIFICATIONS
• RESTORE_TRANSACTIONS
IAB requests
• MarketBillingService interface defined in an
  Android Interface Definition Language file
  (IMarketBillingService.aidl)
• IAB requests sent by single IPC method
  (sendBillingRequest()) of the interface
• Request type and parameters are sent as a
  Bundle
Binding to
          MarketBillingService
try {
  boolean bindResult = mContext.bindService(
    new Intent("com.android.vending.billing.MarketBillingService.BIND"), this,
    Context.BIND_AUTO_CREATE);
  if (bindResult) {
    Log.i(TAG, "Service bind successful.");
  } else {
    Log.e(TAG, "Could not bind to the MarketBillingService.");
  }
} catch (SecurityException e) {
  Log.e(TAG, "Security exception: " + e);
}


public void onServiceConnected(ComponentName name, IBinder service) {
  Log.i(TAG, "MarketBillingService connected.");
  mService = IMarketBillingService.Stub.asInterface(service);
}
Request bundle
           parameters
•   Shared

    •   BILLING_REQUEST: request type

    •   API_VERSION: 1

    •   PACKAGE_NAME: app package

•   Specific

    •   ITEM_ID, NONCE, NOTIFY_ID,
        DEVELOPER_PAYLOAD
Request bundle

protected Bundle makeRequestBundle(String method) {
  Bundle request = new Bundle();
  request.putString(BILLING_REQUEST, method);
  request.putInt(API_VERSION, 1);
  request.putString(PACKAGE_NAME, getPackageName());
  return request;
}
Making a request


Bundle request = makeRequestBundle("REQUEST_PURCHASE");
request.putString(ITEM_ID, mProductId);
Bundle response = mService.sendBillingRequest(request);
IAB responses

• The IAB service responds to every request
  with a synchronous response
• Followed by 0..N asynchronous responses
  depending of the request type
Synchronous responses
• RESPONSE_CODE: status information and
  error information about a request
• REQUEST_ID: used to match
  asynchronous responses with requests
• PURCHASE_INTENT: PendingIntent, which
  you use to launch the checkout activity.
  REQUEST_PURCHASE only.
Asynchronous
      responses
• Broadcast intents:
 • RESPONSE_CODE
 • IN_APP_NOTIFY
 • PURCHASE_STATE_CHANGED
Receiving async
                  responses
 public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
      String signedData = intent.getStringExtra(INAPP_SIGNED_DATA);
      String signature = intent.getStringExtra(INAPP_SIGNATURE);
      // Do something with the signedData and the signature.
    } else if (ACTION_NOTIFY.equals(action)) {
      String notifyId = intent.getStringExtra(NOTIFICATION_ID);
      // Do something with the notifyId.
    } else if (ACTION_RESPONSE_CODE.equals(action)) {
      long requestId = intent.getLongExtra(INAPP_REQUEST_ID, -1);
      int responseCodeIndex = intent.getIntExtra(INAPP_RESPONSE_CODE,
        ResponseCode.RESULT_ERROR.ordinal());
      // Do something with the requestId and the responseCodeIndex.
    } else {
      Log.w(TAG, "unexpected action: " + action);
    }
  }
Check Billing
 Supported
Check Billing
               Supported
Parameters                      Basic
Sync response keys        RESPONSE_CODE
                             RESULT_OK
                     RESULT_BILLING_UNAVAILABLE
Response codes
                            RESULT_ERROR
                      RESULT_DEVELOPER_ERROR
Async response            RESPONSE_CODE
Request Purchase
Request Purchase
                                Basic
Parameters                    ITEM_ID
                       DEVELOPER_PAYLOAD
                         RESPONSE_CODE
Sync response keys      PURCHASE_INTENT
                            REQUEST_ID
                            RESULT_OK
Response codes             RESULT_ERROR
                     RESULT_DEVELOPER_ERROR
                         RESPONSE_CODE
Async response
                          IN_APP_NOTIFY
Get Purchase
             Information
                                Basic
Parameters                    NONCE
                             NOTIFY_IDS
                          RESPONSE_CODE
Sync response keys
                            REQUEST_ID
                             RESULT_OK
Response codes             RESULT_ERROR
                      RESULT_DEVELOPER_ERROR
                          RESPONSE_CODE
Async response
                     PURCHASE_STATE_CHANGED
Purchase State
            Changed JSON
{ "nonce" : 1836535032137741465,
  "orders" :
    { "notificationId" : "android.test.purchased",
      "orderId" : "transactionId.android.test.purchased",
      "packageName" : "com.example.dungeons",
      "productId" : "android.test.purchased",
      "developerPayload" : "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQ",
      "purchaseTime" : 1290114783411,
      "purchaseState" : 0 }
}
Purchase States

• Purchased (0)
• Canceled (1)
• Refunded (2)
Confirm Notifications
                               Basic
Parameters                   NONCE
                            NOTIFY_IDS
                         RESPONSE_CODE
Sync response keys
                           REQUEST_ID
                            RESULT_OK
Response codes            RESULT_ERROR
                     RESULT_DEVELOPER_ERROR
Async response           RESPONSE_CODE
Unsolicited In-App
       Notify

• Purchase when app is running in
  various devices
• Refunds
Unsolicited In-App
      Notify
Restore Transactions
Restore Transactions
                                Basic
Parameters
                              NONCE
                          RESPONSE_CODE
Sync response keys
                            REQUEST_ID
                             RESULT_OK
Response codes             RESULT_ERROR
                      RESULT_DEVELOPER_ERROR
                          RESPONSE_CODE
Async response
                     PURCHASE_STATE_CHANGED
Security Controls


• Signed purchase data
• In-App Notify Nonces
Purchase State
   Changed Extras

• inapp_signed_data: Signed JSON
  string (unencrypted)
• inapp_signature: Use the Android
  Market public key to validate
Agenda

• In-App Billing Overview
• In-App Billing in Android
• Android Market Billing Service
• Android Billing Library
requestPurchase("com.example.item");
Android Billing Library

    tiny.cc/android-billing

 • On github
 • Beta but...
 • “Better than starting from scratch”
Features
• Full Android IAB Service
  implementation
• Auto-confirmations
• Obfuscated purchases database
• Implements security best-practices
• Half-decent unit testing coverage
Overview
AndroidManifest.xml
    <!-- Add this permission to your manifest -->
    <uses-permission android:name="com.android.vending.BILLING" />
    <application>
    	 <!-- Add this service and receiver to your application -->
        <service android:name="net.robotmedia.billing.BillingService" />
        <receiver android:name="net.robotmedia.billing.BillingReceiver">
            <intent-filter>
                <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
                <action android:name="com.android.vending.billing.RESPONSE_CODE" />
                <action
android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
            </intent-filter>
        </receiver>
    </application>
Set Configuration
	   public void onCreate() {
	   	 super.onCreate();
	   	 BillingController.setDebug(true);
	   	 BillingController.setConfiguration(new BillingController.IConfiguration() {
	   	 	
	   	 	 @Override
	   	 	 public byte[] getObfuscationSalt() {
	   	 	 	 return new byte[] {41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127
	   	 	 }

	   	   	 @Override
	   	   	 public String getPublicKey() {
	   	   	 	 return "your public key here";
	   	   	 }
	   	   });
	   }
Check Billing
                Supported

   @Override

   public void onCreate(Bundle savedInstanceState) {

   
 // ...

   
 BillingController.registerObserver(mBillingObserver);

   
 BillingController.checkBillingSupported(this);

   
 // ...

   }


   public void onBillingChecked(boolean supported) {

   
 if (!supported) {

   
 
 showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);

   
 }

   }
Request Purchase
BillingController.requestPurchase(this, productId, true /*confirm*/);


@Override
public void onPurchaseIntent(String itemId, PendingIntent purchaseIntent) {
	 BillingController.startPurchaseIntent(activity, purchaseIntent, null);
}

@Override
public void onRequestPurchaseResponse(String itemId, ResponseCode response) {

}

@Override
public void onPurchaseStateChanged(String itemId, PurchaseState state) {

}
Restore Transactions
if (!mBillingObserver.isTransactionsRestored()) {
	 BillingController.restoreTransactions(this);
	 Toast.makeText(this, R.string.restoring_transactions,
Toast.LENGTH_LONG).show();
}

@Override
public void onTransactionsRestored() {
	 final SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(activity);
	 final Editor editor = preferences.edit();
	 editor.putBoolean(KEY_TRANSACTIONS_RESTORED, true);
	 editor.commit();
}
Suggested
implementation
Thanks!
Agenda
• In-App Billing Overview
• In-App Billing in Android
• Android Market Billing Service
• Android Billing Library
• Administering & Testing In-App Billing
• Security Best Practices
Purchase type

• Managed per user account
 •   premium, digital content, unique virtual goods

• Unmanaged
 •   subscriptions, virtual currency, unlimited virtual
     goods
Managing In-App
   Products
Public key
Reserved product ids

•   android.test.purchased

•   android.test.canceled

•   android.test.refunded

•   android.test.item_unavailable
Test purchase process
Signed test responses
Application ever   Draft uploaded &
                                        User
been published?     unpublished?

       *                  *           Developer

      Yes                No           Test user

      Yes                Yes              *
Agenda
• In-App Billing Overview
• In-App Billing in Android
• Android Market Billing Service
• Android Billing Library
• Administering & Testing In-App Billing
• Security Best Practices
Best practices

• Random nonces
• Obfuscate purchase data
• Embedding public key
• Code obfuscation
• Server-side signature validation
Thanks!

Mais conteúdo relacionado

Destaque

Dealing with Difficult Customers
Dealing with Difficult CustomersDealing with Difficult Customers
Dealing with Difficult CustomersKen Barnes, DBA
 
Customer / Patient Services in a Hospital
Customer / Patient Services in a HospitalCustomer / Patient Services in a Hospital
Customer / Patient Services in a HospitalaJerry4u
 
Use of modern communication technologies to disseminate health information
Use of modern communication technologies to disseminate health informationUse of modern communication technologies to disseminate health information
Use of modern communication technologies to disseminate health informationAmrit Banstola
 
Good news - Business Communication
Good news - Business CommunicationGood news - Business Communication
Good news - Business Communicationjulianmillar
 
Role and impact of media on society final ppt............
Role and impact of media on society final ppt............Role and impact of media on society final ppt............
Role and impact of media on society final ppt............Aaryendr
 
K-12 Module in TLE 8 (Electrical) 3rd Grading
K-12 Module in TLE 8 (Electrical) 3rd GradingK-12 Module in TLE 8 (Electrical) 3rd Grading
K-12 Module in TLE 8 (Electrical) 3rd GradingDaniel Manaog
 

Destaque (9)

Dealing with Difficult Customers
Dealing with Difficult CustomersDealing with Difficult Customers
Dealing with Difficult Customers
 
Industrial purchasing system
Industrial purchasing systemIndustrial purchasing system
Industrial purchasing system
 
Customer / Patient Services in a Hospital
Customer / Patient Services in a HospitalCustomer / Patient Services in a Hospital
Customer / Patient Services in a Hospital
 
Use of modern communication technologies to disseminate health information
Use of modern communication technologies to disseminate health informationUse of modern communication technologies to disseminate health information
Use of modern communication technologies to disseminate health information
 
Good news - Business Communication
Good news - Business CommunicationGood news - Business Communication
Good news - Business Communication
 
Role of Media
Role of MediaRole of Media
Role of Media
 
Role and impact of media on society final ppt............
Role and impact of media on society final ppt............Role and impact of media on society final ppt............
Role and impact of media on society final ppt............
 
Stakeholder Analysis
Stakeholder AnalysisStakeholder Analysis
Stakeholder Analysis
 
K-12 Module in TLE 8 (Electrical) 3rd Grading
K-12 Module in TLE 8 (Electrical) 3rd GradingK-12 Module in TLE 8 (Electrical) 3rd Grading
K-12 Module in TLE 8 (Electrical) 3rd Grading
 

Semelhante a Android In-App Billing @ Droidcon 2011

IAP auto renewable in practice
IAP auto renewable  in practiceIAP auto renewable  in practice
IAP auto renewable in practiceHokila Jan
 
2012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML52012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML5Jonathan LeBlanc
 
HTML5 Gaming Payment Platforms
HTML5 Gaming Payment PlatformsHTML5 Gaming Payment Platforms
HTML5 Gaming Payment PlatformsJonathan LeBlanc
 
AdVenture Capitalist Post-Mortem
AdVenture Capitalist Post-MortemAdVenture Capitalist Post-Mortem
AdVenture Capitalist Post-MortemPlayFab, Inc.
 
Big commerce app development
Big commerce app developmentBig commerce app development
Big commerce app developmentNascenia IT
 
INTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILE
INTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILEINTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILE
INTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILERajesh Roky
 
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...Amazon Web Services
 
API Product Management and Strategy
API Product Management and StrategyAPI Product Management and Strategy
API Product Management and Strategyadritab
 
Dropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudDropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudYun Zhi Lin
 
Paypal Integration For Android Application By LetsNurture
Paypal Integration For Android Application By LetsNurturePaypal Integration For Android Application By LetsNurture
Paypal Integration For Android Application By LetsNurtureKetan Raval
 
Self checkout application presentation
Self checkout application presentationSelf checkout application presentation
Self checkout application presentationAshwinBicholiya
 
Android Accessibility - The missing manual
Android Accessibility - The missing manualAndroid Accessibility - The missing manual
Android Accessibility - The missing manualTed Drake
 
Social Gold in-Flash Webinar Jan 2010
Social Gold in-Flash Webinar Jan 2010Social Gold in-Flash Webinar Jan 2010
Social Gold in-Flash Webinar Jan 2010Social Gold
 
Social Gold In-Flash Payments Webinar
Social Gold In-Flash Payments WebinarSocial Gold In-Flash Payments Webinar
Social Gold In-Flash Payments WebinarSocial Gold
 
Safex pay avantgarde -presentation
Safex pay avantgarde -presentationSafex pay avantgarde -presentation
Safex pay avantgarde -presentationParvezKhan173
 
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0InReceipts
 

Semelhante a Android In-App Billing @ Droidcon 2011 (20)

IAP auto renewable in practice
IAP auto renewable  in practiceIAP auto renewable  in practice
IAP auto renewable in practice
 
Samsung IAP SDK
Samsung IAP SDKSamsung IAP SDK
Samsung IAP SDK
 
2012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML52012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML5
 
HTML5 Gaming Payment Platforms
HTML5 Gaming Payment PlatformsHTML5 Gaming Payment Platforms
HTML5 Gaming Payment Platforms
 
AdVenture Capitalist Post-Mortem
AdVenture Capitalist Post-MortemAdVenture Capitalist Post-Mortem
AdVenture Capitalist Post-Mortem
 
Big commerce app development
Big commerce app developmentBig commerce app development
Big commerce app development
 
INTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILE
INTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILEINTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILE
INTEGRATED SHOPPING ASSISTANCE WITH FREDGE AND MOBILE
 
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
 
API Product Management and Strategy
API Product Management and StrategyAPI Product Management and Strategy
API Product Management and Strategy
 
Dropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudDropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google Cloud
 
Paypal Integration For Android Application By LetsNurture
Paypal Integration For Android Application By LetsNurturePaypal Integration For Android Application By LetsNurture
Paypal Integration For Android Application By LetsNurture
 
Self checkout application presentation
Self checkout application presentationSelf checkout application presentation
Self checkout application presentation
 
Android Accessibility - The missing manual
Android Accessibility - The missing manualAndroid Accessibility - The missing manual
Android Accessibility - The missing manual
 
Social Gold in-Flash Webinar Jan 2010
Social Gold in-Flash Webinar Jan 2010Social Gold in-Flash Webinar Jan 2010
Social Gold in-Flash Webinar Jan 2010
 
Social Gold In-Flash Payments Webinar
Social Gold In-Flash Payments WebinarSocial Gold In-Flash Payments Webinar
Social Gold In-Flash Payments Webinar
 
Workshop CQRS and DDD
Workshop CQRS and DDDWorkshop CQRS and DDD
Workshop CQRS and DDD
 
Shopify
ShopifyShopify
Shopify
 
In App Purchases
In  App  PurchasesIn  App  Purchases
In App Purchases
 
Safex pay avantgarde -presentation
Safex pay avantgarde -presentationSafex pay avantgarde -presentation
Safex pay avantgarde -presentation
 
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Android In-App Billing @ Droidcon 2011

  • 2. Android In-App Billing Demystified Hermés Piqué @hpique
  • 3. Agenda • In-App Billing Overview • In-App Billing in Android • Android Market Billing Service • Android Billing Library
  • 9. IAB for the user... • Faster • Simpler • Contextual • “Harmless” • “Inexpensive”
  • 10. IAB generates more sales
  • 11. Agenda • In-App Billing Overview • In-App Billing in Android • Android Market Billing Service • Android Billing Library
  • 12. Options • Android Market In-App Billing • PayPal Mobile Payments Library • Others • Any web payment processor • Custom implementation
  • 13. Android Market IAB • Android Market only • 30% of the sale price • Android 1.6 upwards • Only digital goods
  • 14. PayPal Mobile Payments • Starts at 2.9% of the sale price + transaction fee • Android 1.5 upwards • Physical goods allowed
  • 15. Others • Paythru • Movend • Open Payments • ...
  • 16. “All fees received by Developers for Products distributed via the Market must be processed by the Market's Payment Processor.” http://www.android.com/us/developer-distribution-agreement.html
  • 17. Agenda • In-App Billing Overview • In-App Billing in Android • Android Market Billing Service • Android Billing Library
  • 18. Purchase type • Managed per user account • premium, digital content, unique virtual goods • Unmanaged • subscriptions, virtual currency, unlimited virtual goods
  • 19. Pre-requisites • Services • AIDL • BroadcastReceiver • PendingIntent
  • 20. Overview app Android IAB Market requests Server
  • 22. IAB requests • CHECK_BILLING_SUPPORTED • REQUEST_PURCHASE • GET_PURCHASE_INFORMATION • CONFIRM_NOTIFICATIONS • RESTORE_TRANSACTIONS
  • 23. IAB requests • MarketBillingService interface defined in an Android Interface Definition Language file (IMarketBillingService.aidl) • IAB requests sent by single IPC method (sendBillingRequest()) of the interface • Request type and parameters are sent as a Bundle
  • 24. Binding to MarketBillingService try {   boolean bindResult = mContext.bindService(     new Intent("com.android.vending.billing.MarketBillingService.BIND"), this,     Context.BIND_AUTO_CREATE);   if (bindResult) {     Log.i(TAG, "Service bind successful.");   } else {     Log.e(TAG, "Could not bind to the MarketBillingService.");   } } catch (SecurityException e) {   Log.e(TAG, "Security exception: " + e); } public void onServiceConnected(ComponentName name, IBinder service) {   Log.i(TAG, "MarketBillingService connected.");   mService = IMarketBillingService.Stub.asInterface(service); }
  • 25. Request bundle parameters • Shared • BILLING_REQUEST: request type • API_VERSION: 1 • PACKAGE_NAME: app package • Specific • ITEM_ID, NONCE, NOTIFY_ID, DEVELOPER_PAYLOAD
  • 26. Request bundle protected Bundle makeRequestBundle(String method) {   Bundle request = new Bundle();   request.putString(BILLING_REQUEST, method);   request.putInt(API_VERSION, 1);   request.putString(PACKAGE_NAME, getPackageName());   return request; }
  • 27. Making a request Bundle request = makeRequestBundle("REQUEST_PURCHASE"); request.putString(ITEM_ID, mProductId); Bundle response = mService.sendBillingRequest(request);
  • 28. IAB responses • The IAB service responds to every request with a synchronous response • Followed by 0..N asynchronous responses depending of the request type
  • 29. Synchronous responses • RESPONSE_CODE: status information and error information about a request • REQUEST_ID: used to match asynchronous responses with requests • PURCHASE_INTENT: PendingIntent, which you use to launch the checkout activity. REQUEST_PURCHASE only.
  • 30. Asynchronous responses • Broadcast intents: • RESPONSE_CODE • IN_APP_NOTIFY • PURCHASE_STATE_CHANGED
  • 31. Receiving async responses public void onReceive(Context context, Intent intent) {     String action = intent.getAction();     if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) {       String signedData = intent.getStringExtra(INAPP_SIGNED_DATA);       String signature = intent.getStringExtra(INAPP_SIGNATURE);       // Do something with the signedData and the signature.     } else if (ACTION_NOTIFY.equals(action)) {       String notifyId = intent.getStringExtra(NOTIFICATION_ID);       // Do something with the notifyId.     } else if (ACTION_RESPONSE_CODE.equals(action)) {       long requestId = intent.getLongExtra(INAPP_REQUEST_ID, -1);       int responseCodeIndex = intent.getIntExtra(INAPP_RESPONSE_CODE,         ResponseCode.RESULT_ERROR.ordinal());       // Do something with the requestId and the responseCodeIndex.     } else {       Log.w(TAG, "unexpected action: " + action);     }   }
  • 33. Check Billing Supported Parameters Basic Sync response keys RESPONSE_CODE RESULT_OK RESULT_BILLING_UNAVAILABLE Response codes RESULT_ERROR RESULT_DEVELOPER_ERROR Async response RESPONSE_CODE
  • 35. Request Purchase Basic Parameters ITEM_ID DEVELOPER_PAYLOAD RESPONSE_CODE Sync response keys PURCHASE_INTENT REQUEST_ID RESULT_OK Response codes RESULT_ERROR RESULT_DEVELOPER_ERROR RESPONSE_CODE Async response IN_APP_NOTIFY
  • 36. Get Purchase Information Basic Parameters NONCE NOTIFY_IDS RESPONSE_CODE Sync response keys REQUEST_ID RESULT_OK Response codes RESULT_ERROR RESULT_DEVELOPER_ERROR RESPONSE_CODE Async response PURCHASE_STATE_CHANGED
  • 37. Purchase State Changed JSON { "nonce" : 1836535032137741465, "orders" : { "notificationId" : "android.test.purchased", "orderId" : "transactionId.android.test.purchased", "packageName" : "com.example.dungeons", "productId" : "android.test.purchased", "developerPayload" : "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQ", "purchaseTime" : 1290114783411, "purchaseState" : 0 } }
  • 38. Purchase States • Purchased (0) • Canceled (1) • Refunded (2)
  • 39. Confirm Notifications Basic Parameters NONCE NOTIFY_IDS RESPONSE_CODE Sync response keys REQUEST_ID RESULT_OK Response codes RESULT_ERROR RESULT_DEVELOPER_ERROR Async response RESPONSE_CODE
  • 40. Unsolicited In-App Notify • Purchase when app is running in various devices • Refunds
  • 43. Restore Transactions Basic Parameters NONCE RESPONSE_CODE Sync response keys REQUEST_ID RESULT_OK Response codes RESULT_ERROR RESULT_DEVELOPER_ERROR RESPONSE_CODE Async response PURCHASE_STATE_CHANGED
  • 44. Security Controls • Signed purchase data • In-App Notify Nonces
  • 45. Purchase State Changed Extras • inapp_signed_data: Signed JSON string (unencrypted) • inapp_signature: Use the Android Market public key to validate
  • 46.
  • 47.
  • 48. Agenda • In-App Billing Overview • In-App Billing in Android • Android Market Billing Service • Android Billing Library
  • 50. Android Billing Library tiny.cc/android-billing • On github • Beta but... • “Better than starting from scratch”
  • 51. Features • Full Android IAB Service implementation • Auto-confirmations • Obfuscated purchases database • Implements security best-practices • Half-decent unit testing coverage
  • 53. AndroidManifest.xml <!-- Add this permission to your manifest --> <uses-permission android:name="com.android.vending.BILLING" /> <application> <!-- Add this service and receiver to your application --> <service android:name="net.robotmedia.billing.BillingService" /> <receiver android:name="net.robotmedia.billing.BillingReceiver"> <intent-filter> <action android:name="com.android.vending.billing.IN_APP_NOTIFY" /> <action android:name="com.android.vending.billing.RESPONSE_CODE" /> <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" /> </intent-filter> </receiver> </application>
  • 54. Set Configuration public void onCreate() { super.onCreate(); BillingController.setDebug(true); BillingController.setConfiguration(new BillingController.IConfiguration() { @Override public byte[] getObfuscationSalt() { return new byte[] {41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127 } @Override public String getPublicKey() { return "your public key here"; } }); }
  • 55. Check Billing Supported @Override public void onCreate(Bundle savedInstanceState) { // ... BillingController.registerObserver(mBillingObserver); BillingController.checkBillingSupported(this); // ... } public void onBillingChecked(boolean supported) { if (!supported) { showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID); } }
  • 56. Request Purchase BillingController.requestPurchase(this, productId, true /*confirm*/); @Override public void onPurchaseIntent(String itemId, PendingIntent purchaseIntent) { BillingController.startPurchaseIntent(activity, purchaseIntent, null); } @Override public void onRequestPurchaseResponse(String itemId, ResponseCode response) { } @Override public void onPurchaseStateChanged(String itemId, PurchaseState state) { }
  • 57. Restore Transactions if (!mBillingObserver.isTransactionsRestored()) { BillingController.restoreTransactions(this); Toast.makeText(this, R.string.restoring_transactions, Toast.LENGTH_LONG).show(); } @Override public void onTransactionsRestored() { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); final Editor editor = preferences.edit(); editor.putBoolean(KEY_TRANSACTIONS_RESTORED, true); editor.commit(); }
  • 60. Agenda • In-App Billing Overview • In-App Billing in Android • Android Market Billing Service • Android Billing Library • Administering & Testing In-App Billing • Security Best Practices
  • 61. Purchase type • Managed per user account • premium, digital content, unique virtual goods • Unmanaged • subscriptions, virtual currency, unlimited virtual goods
  • 62. Managing In-App Products
  • 63.
  • 65. Reserved product ids • android.test.purchased • android.test.canceled • android.test.refunded • android.test.item_unavailable
  • 67. Signed test responses Application ever Draft uploaded & User been published? unpublished? * * Developer Yes No Test user Yes Yes *
  • 68. Agenda • In-App Billing Overview • In-App Billing in Android • Android Market Billing Service • Android Billing Library • Administering & Testing In-App Billing • Security Best Practices
  • 69. Best practices • Random nonces • Obfuscate purchase data • Embedding public key • Code obfuscation • Server-side signature validation

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n