{"id":799,"date":"2018-08-20T12:54:47","date_gmt":"2018-08-20T12:54:47","guid":{"rendered":"http:\/\/www.inwizards.com\/blog\/?p=799"},"modified":"2023-10-27T06:44:10","modified_gmt":"2023-10-27T06:44:10","slug":"introduction-google-play-app-billing-google-play-billing-overview","status":"publish","type":"post","link":"https:\/\/www.inwizards.com\/blog\/introduction-google-play-app-billing-google-play-billing-overview\/","title":{"rendered":"Introduction of google play in app billing -Google Play Billing Overview"},"content":{"rendered":"<p>Google launched the Android\u00a0In-app Billing API\u00a0to make it easy for users to buy digital products and subscriptions. Since then Google have continuously improved the API by introducing subscription upgrades\/downgrades facilities, promotion codes, and much more. Google Play Billing supports credit cards, gift cards, PayPal and carrier billing in over 130 countries around the world. It&#8217;s a great way for you to legitimize your app without having to worry about managing your users&#8217; payment information and setting up relationships with payment providers.<\/p>\n<p>The new\u00a0Play Billing Library\u00a0provides a simple API for integration with Google Play In-app Billing. The new Java library makes it easy to create and manage transactions without dealing with a complex service interface.<\/p>\n<h2><b>Play Billing Library Features<\/b><\/h2>\n<p>1 &#8211; Get details of your in-app items and subscriptions in your app<br \/>\n2 &#8211; Charge users around the globe for in-app items and subscriptions<br \/>\n3 &#8211; Manage your in-app items and subscriptions dynamically<br \/>\n4 &#8211; Get the list of non-consumed purchases as well as purchases history<\/p>\n<h3><b>Google Play In-app Billing<\/b><\/h3>\n<p>1 &#8211; In-app Billing is a Google Play service that lets you sell digital content from your applications<br \/>\n2 &#8211; You can use In-app Billing to sell products as:<br \/>\n3 &#8211; Standard in-app products (one-time billing),<br \/>\n4 &#8211; Subscriptions, (recurring, automated billing)<br \/>\n5 &#8211; Any application that you publish through Google Play can implement In-app Billing functionality.<\/p>\n<h3><b>Product Types<\/b><\/h3>\n<p><b>1 &#8211; Non-consumable Items &#8211; <\/b>One Time purchased, these items will be permanently associated of the user&#8217;s Google Play account. An example of a non-consumable in- app product is a premium upgrade or a level pack.<\/p>\n<p><b>2 &#8211; Consumable items &#8211; <\/b>Implement consumption for items that can be made available for purchase multiple times. Typically, these items provide some temporary effects. For example, the user&#8217;s in-game character might gain life points or gain extra coins in their inventory.<\/p>\n<p><b>3 &#8211; Subscriptions &#8211; <\/b>A subscription is offered in In-app Billing that lets you sell your Application data, services, or features to users from your app with recurring monthly or annual subscription.<\/p>\n<h3><b>Create In-App Product<\/b><\/h3>\n<p>1 &#8211; Login with your Google Play Publisher Account<\/p>\n<p>https:\/\/play.google.com\/apps\/publish\/<\/p>\n<p>2 &#8211; Create a new Application<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-801\" src=\"https:\/\/i1.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_application-1.png?resize=570%2C152&#038;ssl=1\" alt=\"\" width=\"570\" height=\"152\" srcset=\"https:\/\/i1.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_application-1.png?resize=300%2C80&amp;ssl=1 300w, https:\/\/i1.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_application-1.png?resize=768%2C204&amp;ssl=1 768w, https:\/\/i1.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_application-1.png?w=962&amp;ssl=1 962w\" sizes=\"(max-width: 570px) 100vw, 570px\" data-recalc-dims=\"1\" \/><\/p>\n<h3><b>Create In-App Product (Cont.)<\/b><\/h3>\n<p>1 &#8211; Click on Store Presence in left drawer<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-802\" src=\"https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/store_presence.png?resize=229%2C300&#038;ssl=1\" alt=\"\" width=\"229\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/store_presence.png?resize=229%2C300&amp;ssl=1 229w, https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/store_presence.png?w=299&amp;ssl=1 299w\" sizes=\"(max-width: 229px) 100vw, 229px\" data-recalc-dims=\"1\" \/><\/p>\n<p>2 &#8211; Then click on in-app products<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-803\" src=\"https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/inappproduct.png?resize=215%2C300&#038;ssl=1\" alt=\"\" width=\"215\" height=\"300\" srcset=\"https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/inappproduct.png?resize=215%2C300&amp;ssl=1 215w, https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/inappproduct.png?w=284&amp;ssl=1 284w\" sizes=\"(max-width: 215px) 100vw, 215px\" data-recalc-dims=\"1\" \/><\/p>\n<h3><b>Create In-App Product (Cont.) &#8211; <\/b><\/h3>\n<p>In-app Product configuration option.<\/p>\n<p>1 &#8211; Title<br \/>\n2 &#8211; Description<br \/>\n3 &#8211; Product ID<br \/>\n4 &#8211; Price<br \/>\n5 &#8211; Billing Period<br \/>\n6 &#8211; Free Trial Period<br \/>\n7 &#8211; Grace Period<\/p>\n<h3><b>Implementation of In-App Billing<\/b><\/h3>\n<p>1 &#8211; Add Billing library.<br \/>\n2 &#8211; Create a BillingClient<br \/>\n3 &#8211; Implement Purchase Update methond.<\/p>\n<h3><b>Get SKUs with details<\/b><\/h3>\n<p>Once\u00a0onBillingSetupFinished\u00a0is called with\u00a0BillingResponse.OK, the\u00a0BillingClient\u00a0is ready to be used.<\/p>\n<p>First, try to query for SKU(Products) details. For example we have two in-app products (&#8220;coach&#8221;,\u00a0&#8220;student&#8221;) and two subscriptions SKUs (&#8220;coach_monthly&#8221;,\u00a0&#8220;student_yearly&#8221;).<\/p>\n<p>Let&#8217;s query to get their details.<\/p>\n<p>querySkuDetailsAsync<\/p>\n<h3><b>Start a purchase flow<\/b><\/h3>\n<p>Display Google Play Billing dialog<\/p>\n<p>Implement the code snippet below inside\u00a0BillingManager.startPurchaseFlow(). The method\u00a0startPurchaseFlow\u00a0is execute when any of the buttons inside\u00a0ProductFragment\u00a0(i.e.\u00a0SkusListAdapter) is clicked. It also knows the SKU of the product and billing type of the product that had the button triggered.<\/p>\n<p>BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder() .setType(billingType).setSku(skuId).build(); mBillingClient.launchBillingFlow(mActivity, billingFlowParams);<\/p>\n<h3><b>Real-time developer notifications<\/b><\/h3>\n<p>Google Play Billing provides server push notification allowing you to check state changes for play managed subscriptions. To enable this capability:<\/p>\n<p>1 &#8211; Setup Clout Pub\/Sub using your Google Cloud Platform project.<br \/>\n2 &#8211; Enable real-time developer notification for your Android application.<\/p>\n<h3><b>Create Topic for Pub\/Sub<\/b><\/h3>\n<ul>\n<li>Open you Google Cloud consol.<\/li>\n<li>Select your project and click Pub\/Sub in left hand navigation.<\/li>\n<li>Click on Create Topic button for create your Topic<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-804\" src=\"https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_topic.png?resize=478%2C215&#038;ssl=1\" alt=\"\" width=\"478\" height=\"215\" srcset=\"https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_topic.png?resize=300%2C135&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_topic.png?resize=570%2C255&amp;ssl=1 570w, https:\/\/i0.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/create_topic.png?w=723&amp;ssl=1 723w\" sizes=\"(max-width: 478px) 100vw, 478px\" data-recalc-dims=\"1\" \/><\/p>\n<h4><b>Enable real-time developer notifications for your app<\/b><\/h4>\n<ul>\n<li>Open the Google Play console.<\/li>\n<li>Select your Android app.<\/li>\n<li>Navigate to Development tools &gt; Services &amp; APIs page.<\/li>\n<li>Scroll to the Real-time Developer Notification section at the bottom of the page.<\/li>\n<li>In the Topic name field, enter the full Cloud Pub\/Sub topic name.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-805\" src=\"https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/enaboel_notication.png?resize=467%2C179&#038;ssl=1\" alt=\"\" width=\"467\" height=\"179\" srcset=\"https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/enaboel_notication.png?resize=300%2C115&amp;ssl=1 300w, https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/enaboel_notication.png?resize=768%2C294&amp;ssl=1 768w, https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/enaboel_notication.png?w=949&amp;ssl=1 949w\" sizes=\"(max-width: 467px) 100vw, 467px\" data-recalc-dims=\"1\" \/><\/p>\n<p><b>Implement Cloud Pub\/Sub triggers<\/b><\/p>\n<ul>\n<li>Trigger a Pub\/Sub function<\/li>\n<\/ul>\n<p>exports.helloPubSub = functions.pubsub.topic(&#8216;topic-name&#8217;).onPublish((message) =&gt; {<\/p>\n<p>\/\/ &#8230;<\/p>\n<p>});<\/p>\n<ul>\n<li>Access the Pub\/Sub message payload<\/li>\n<\/ul>\n<p>The payload for the Pub\/Sub message in accessible from the Message object returned to your function. For messages with json in the Pub\/Sub message body, the firebase SDK for Cloud Functions has a helper property to decode message. For example here is a message published with a simple JSON payload.<\/p>\n<p>gcloud pubsub topics publish topic-name &#8211;message &#8216;{&#8220;subscription&#8221;:&#8221;cancel&#8221;}&#8217;<\/p>\n<p>You can parse data from the JSON.<\/p>\n<p><b>Sample Real-time developer notifications<\/b><\/p>\n<p>This is the JSON user will get in notification<\/p>\n<p>{<\/p>\n<p>&#8220;version&#8221;:&#8221;1.0&#8243;,<\/p>\n<p>&#8220;packageName&#8221;:&#8221;com.inwizards.inappbilling&#8221;,<\/p>\n<p>&#8220;eventTimeMillis&#8221;:&#8221;1503349566168&#8243;,<\/p>\n<p>&#8220;subscriptionNotification&#8221;:<\/p>\n<p>{<\/p>\n<p>&#8220;version&#8221;:&#8221;1.0&#8243;,<\/p>\n<p>&#8220;notificationType&#8221;:4,<\/p>\n<p>&#8220;purchaseToken&#8221;:&#8221;PURCHASE_TOKEN&#8221;,<\/p>\n<p>&#8220;subscriptionId&#8221;:&#8221;my.sku&#8221;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p><b>Real-time developer notifications type<\/b><\/p>\n<p>(1) SUBSCRIPTION_RECOVERED &#8211; A subscription was recovered from account hold.<br \/>\n(2) SUBSCRIPTION_RENEWED &#8211; An active subscription was renewed.<br \/>\n(3) SUBSCRIPTION_CANCELED &#8211; A subscription was either voluntarily or involuntarily cancelled. For voluntary cancellation, sent when the user cancels.<br \/>\n(4) SUBSCRIPTION_PURCHASED &#8211; A new subscription was purchased.<br \/>\n(5) SUBSCRIPTION_ON_HOLD &#8211; A subscription has entered account hold (if enabled).<br \/>\n(6) SUBSCRIPTION_IN_GRACE_PERIOD &#8211; A subscription has entered grace period (if enabled).<br \/>\n(7) SUBSCRIPTION_RESTARTED &#8211; User has reactivated their subscription from Play &gt; Account &gt; Subscriptions (requires opt-in for subscription restoration)<\/p>\n<p>By &#8211; Deepak Tiwari<br \/>\nReference &#8211;\u00a0https:\/\/developer.android.com<\/p>\n<p>Looking for <strong><a href=\"https:\/\/www.inwizards.com\/\">Top software development Company<\/a><\/strong> in USA, Consult Inwizards software Technologies now!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google launched the Android\u00a0In-app Billing API\u00a0to make it easy for users to buy digital products and subscriptions. Since then Google have continuously improved the API by introducing subscription upgrades\/downgrades facilities, promotion codes, and much more. Google Play Billing supports credit<\/p>\n","protected":false},"author":1,"featured_media":806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2018\/08\/3073android-in-app-purchase-version-3.jpg?fit=944%2C418&ssl=1","_links":{"self":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/799"}],"collection":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/comments?post=799"}],"version-history":[{"count":6,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/799\/revisions"}],"predecessor-version":[{"id":2529,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/799\/revisions\/2529"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/media\/806"}],"wp:attachment":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/media?parent=799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/categories?post=799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/tags?post=799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}