├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── demo
│ │ └── iap
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── demo
│ │ │ └── iap
│ │ │ ├── IAPHelper.java
│ │ │ ├── MainActivity.java
│ │ │ └── Security.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── coins.png
│ │ ├── crown.png
│ │ ├── get_coin.png
│ │ ├── ic_launcher_background.xml
│ │ ├── necklace.png
│ │ └── ring.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── demo
│ └── iap
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── in-app.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .externalNativeBuild
3 | .cxx
4 |
5 | # Built application files
6 | *.apk
7 | *.ap_
8 |
9 | # Files for the ART/Dalvik VM
10 | *.dex
11 |
12 | # Java class files
13 | *.class
14 |
15 | # Generated files
16 | bin/
17 | gen/
18 | out/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | .idea/caches
48 | .idea/modules.xml
49 | .idea/navEditor.xml
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # InAppPurchaseDemo
2 | In-app purchasing means buying digital goods and services within the app. What does that mean for developers?
3 | It means another great way to make money.
4 |
5 | Google Play Billing allows you to sell items and additional features, or to remove ads.
6 | Google Play handles the checkout details so your app never has to process financial transactions and user gets a familiar,
7 | reliable, and secure experience.
8 |
9 | This demo Android app demonstrates implementation of in-app purchasing with google library for one-time products (no subs).
10 |
11 | You can read more about it here : https://medium.com/@surabhichoudhary/in-app-purchasing-with-google-play-billing-library-6a72e289a78e
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 | defaultConfig {
7 | applicationId "com.demo.iap"
8 | minSdkVersion 19
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31 | implementation 'com.android.billingclient:billing:2.1.0'
32 | implementation 'com.jakewharton:butterknife:10.2.1'
33 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'androidx.test:runner:1.2.0'
36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
37 | }
38 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/demo/iap/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.demo.iap;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.demo.iap", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/demo/iap/IAPHelper.java:
--------------------------------------------------------------------------------
1 | package com.demo.iap;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.Log;
6 |
7 | import com.android.billingclient.api.AcknowledgePurchaseParams;
8 | import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
9 | import com.android.billingclient.api.BillingClient;
10 | import com.android.billingclient.api.BillingClientStateListener;
11 | import com.android.billingclient.api.BillingFlowParams;
12 | import com.android.billingclient.api.BillingResult;
13 | import com.android.billingclient.api.ConsumeParams;
14 | import com.android.billingclient.api.ConsumeResponseListener;
15 | import com.android.billingclient.api.Purchase;
16 | import com.android.billingclient.api.PurchasesUpdatedListener;
17 | import com.android.billingclient.api.SkuDetails;
18 | import com.android.billingclient.api.SkuDetailsParams;
19 | import com.android.billingclient.api.SkuDetailsResponseListener;
20 |
21 | import java.util.HashMap;
22 | import java.util.List;
23 |
24 |
25 | public class IAPHelper {
26 |
27 | private String TAG = IAPHelper.class.getSimpleName();
28 |
29 | private Context context;
30 | private BillingClient mBillingClient;
31 | private IAPHelperListener IAPHelperListener;
32 | private List skuList;
33 |
34 | /**
35 | * To instantiate the object
36 | * @param context It will be used to get an application context to bind to the in-app billing service.
37 | * @param IAPHelperListener Your listener to get the response for your query.
38 | * @param skuList
39 | */
40 | public IAPHelper(Context context, IAPHelperListener IAPHelperListener, List skuList) {
41 | this.context = context;
42 | this.IAPHelperListener = IAPHelperListener;
43 | this.skuList = skuList;
44 | this.mBillingClient = BillingClient.newBuilder(context)
45 | .enablePendingPurchases()
46 | .setListener(getPurchaseUpdatedListener())
47 | .build();
48 | if (!mBillingClient.isReady()) {
49 | Log.d(TAG, "BillingClient: Start connection...");
50 | startConnection();
51 | }
52 | }
53 |
54 | /**
55 | * To establish the connection with play library
56 | * It will be used to notify that setup is complete and the billing
57 | * client is ready. You can query whatever you want.
58 | */
59 | private void startConnection() {
60 | mBillingClient.startConnection(new BillingClientStateListener() {
61 | @Override
62 | public void onBillingSetupFinished(BillingResult billingResult) {
63 | int billingResponseCode = billingResult.getResponseCode();
64 | Log.d(TAG, "onBillingSetupFinished: " + billingResult.getResponseCode());
65 | if (billingResponseCode == BillingClient.BillingResponseCode.OK) {
66 | getPurchasedItems();
67 | getSKUDetails(skuList);
68 | }
69 | }
70 |
71 | @Override
72 | public void onBillingServiceDisconnected() {
73 | Log.d(TAG, "onBillingServiceDisconnected: ");
74 | }
75 | });
76 | }
77 |
78 | /**
79 | * Get purchases details for all the items bought within your app.
80 | */
81 | public void getPurchasedItems() {
82 | Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
83 | if (IAPHelperListener != null)
84 | IAPHelperListener.onPurchasehistoryResponse(purchasesResult.getPurchasesList());
85 | }
86 |
87 | /**
88 | * Perform a network query to get SKU details and return the result asynchronously.
89 | */
90 | public void getSKUDetails(List skuList) {
91 | final HashMap skuDetailsHashMap = new HashMap<>();
92 | SkuDetailsParams skuParams = SkuDetailsParams.newBuilder().setType(BillingClient.SkuType.INAPP).setSkusList(skuList).build();
93 | mBillingClient.querySkuDetailsAsync(skuParams, new SkuDetailsResponseListener() {
94 | @Override
95 | public void onSkuDetailsResponse(BillingResult billingResult, List skuDetailsList) {
96 | if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
97 | for (SkuDetails skuDetails : skuDetailsList) {
98 | skuDetailsHashMap.put(skuDetails.getSku(), skuDetails);
99 | }
100 | if (IAPHelperListener != null)
101 | IAPHelperListener.onSkuListResponse(skuDetailsHashMap);
102 | }
103 | }
104 | });
105 | }
106 |
107 | /**
108 | * Initiate the billing flow for an in-app purchase or subscription.
109 | *
110 | * @param skuDetails skudetails of the product to be purchased
111 | * Developer console.
112 | */
113 | public void launchBillingFLow(final SkuDetails skuDetails) {
114 | if(mBillingClient.isReady()){
115 | BillingFlowParams mBillingFlowParams = BillingFlowParams.newBuilder()
116 | .setSkuDetails(skuDetails)
117 | .build();
118 | mBillingClient.launchBillingFlow((Activity) context, mBillingFlowParams);
119 | }
120 | }
121 |
122 | /**
123 | * Your listener to get the response for purchase updates which happen when, the user buys
124 | * something within the app or by initiating a purchase from Google Play Store.
125 | */
126 | private PurchasesUpdatedListener getPurchaseUpdatedListener() {
127 | return (billingResult, purchases) -> {
128 | int responseCode = billingResult.getResponseCode();
129 | if (responseCode == BillingClient.BillingResponseCode.OK && purchases != null) {
130 | //here when purchase completed
131 | for (Purchase purchase : purchases) {
132 | //I have named sku in such a way that I get sku name as "type_name" for ex: "nc_ring"
133 | //For non consumable I will acknowledge purchase
134 | //For consumable I will consume purchase
135 | String type = purchase.getSku().split("_")[0];
136 | if(type.equals("nc"))
137 | acknowledgePurchase(purchase);
138 | else
139 | consumePurchase(purchase);
140 | }
141 | } else if (responseCode == BillingClient.BillingResponseCode.USER_CANCELED) {
142 | // Handle an error caused by a user cancelling the purchase flow.
143 | Log.d(TAG, "user cancelled");
144 | } else if (responseCode == BillingClient.BillingResponseCode.SERVICE_DISCONNECTED) {
145 | Log.d(TAG , "service disconnected");
146 | startConnection();
147 | }
148 | };
149 | }
150 |
151 | public void acknowledgePurchase(Purchase purchase) {
152 | if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED
153 | && isSignatureValid(purchase)) {
154 |
155 | //This is for Consumable product
156 | AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
157 | .setPurchaseToken(purchase.getPurchaseToken())
158 | .build();
159 | mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, new AcknowledgePurchaseResponseListener() {
160 | @Override
161 | public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
162 | Log.d("purchase", "Purchase Acknowledged");
163 | }
164 | });
165 |
166 | if (IAPHelperListener != null)
167 | IAPHelperListener.onPurchaseCompleted(purchase);
168 | }
169 | }
170 |
171 | public void consumePurchase(Purchase purchase) {
172 | if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED
173 | && isSignatureValid(purchase)) {
174 |
175 | //This is for Consumable product
176 | ConsumeParams consumeParams = ConsumeParams.newBuilder()
177 | .setPurchaseToken(purchase.getPurchaseToken())
178 | .build();
179 | mBillingClient.consumeAsync(consumeParams, new ConsumeResponseListener() {
180 | @Override
181 | public void onConsumeResponse(BillingResult billingResult, String s) {
182 | Log.d("purchase", "Purchase Consumed");
183 | }
184 | });
185 |
186 | if (IAPHelperListener != null)
187 | IAPHelperListener.onPurchaseCompleted(purchase);
188 | }
189 | }
190 |
191 | private boolean isSignatureValid(Purchase purchase) {
192 | return Security.verifyPurchase(Security.BASE_64_ENCODED_PUBLIC_KEY, purchase.getOriginalJson(), purchase.getSignature());
193 | }
194 |
195 | /**
196 | * Call this method once you are done with this BillingClient reference.
197 | */
198 | public void endConnection() {
199 | if (mBillingClient != null && mBillingClient.isReady()) {
200 | mBillingClient.endConnection();
201 | mBillingClient = null;
202 | }
203 | }
204 |
205 | /**
206 | * Listener interface for handling the various responses of the Purchase helper util
207 | */
208 | public interface IAPHelperListener {
209 | void onSkuListResponse(HashMap skuDetailsHashMap);
210 | void onPurchasehistoryResponse(List purchasedItem);
211 | void onPurchaseCompleted(Purchase purchase);
212 | }
213 |
214 |
215 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/demo/iap/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.demo.iap;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.Manifest;
6 | import android.content.SharedPreferences;
7 | import android.os.Bundle;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.android.billingclient.api.BillingClient;
14 | import com.android.billingclient.api.ConsumeParams;
15 | import com.android.billingclient.api.Purchase;
16 | import com.android.billingclient.api.SkuDetails;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Locale;
23 |
24 | import butterknife.BindView;
25 | import butterknife.ButterKnife;
26 | import butterknife.OnClick;
27 |
28 | public class MainActivity extends AppCompatActivity implements IAPHelper.IAPHelperListener {
29 |
30 | private String TAG = MainActivity.class.getSimpleName();
31 |
32 |
33 | IAPHelper iapHelper;
34 | HashMap skuDetailsHashMap = new HashMap<>();
35 | //For non_consumable tag "nc" is used at start
36 | final String RING = "nc_ring";
37 | final String NECKLACE = "nc_necklace";
38 | final String CROWN = "nc_crown";
39 | final String COIN = "coin";
40 | final String TEST = "android.test.purchased"; //This id can be used for testing purpose
41 | private List skuList = Arrays.asList(COIN, RING, NECKLACE, CROWN, TEST);
42 |
43 | private SharedPreferences pref;
44 | private String SETTINGS = "saved_settings";
45 | private String SETTINGS_COINS = "saved_coins";
46 |
47 | @BindView(R.id.tvTotalCoinsNum)
48 | TextView tvtotalCoin;
49 |
50 | private Integer totalCoins;
51 |
52 | @Override
53 | protected void onCreate(Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 | setContentView(R.layout.activity_main);
56 | ButterKnife.bind(this);
57 |
58 | iapHelper = new IAPHelper(this, this, skuList);
59 |
60 | //Get previous coins from shared pref data
61 | pref = getSharedPreferences(SETTINGS, 0);
62 | totalCoins = pref.getInt(SETTINGS_COINS, 0);
63 | tvtotalCoin.setText(String.format(Locale.getDefault(), "%d", totalCoins));
64 | }
65 |
66 | @OnClick(R.id.llBuyCoin)
67 | public void buyCoin(){
68 | launch(TEST);
69 | }
70 |
71 | @OnClick(R.id.llUnlockRing)
72 | public void unlockRing(){
73 | launch(RING);
74 | }
75 |
76 | @OnClick(R.id.llUnlockNecklace)
77 | public void unlockNecklace(){
78 | launch(NECKLACE);
79 | }
80 |
81 | @OnClick(R.id.llUnlockCrown)
82 | public void unlockCrown(){
83 | launch(CROWN);
84 | }
85 |
86 | private void launch(String sku){
87 | if(!skuDetailsHashMap.isEmpty())
88 | iapHelper.launchBillingFLow(skuDetailsHashMap.get(sku));
89 | }
90 |
91 |
92 | @Override
93 | public void onSkuListResponse(HashMap skuDetails) {
94 | skuDetailsHashMap = skuDetails;
95 | }
96 |
97 | @Override
98 | public void onPurchasehistoryResponse(List purchasedItems) {
99 | if (purchasedItems != null) {
100 | for (Purchase purchase : purchasedItems) {
101 | //Update UI and backend according to purchased items if required
102 | // Like in this project I am updating UI for purchased items
103 | String sku = purchase.getSku();
104 | switch (sku) {
105 | case RING:
106 | findViewById(R.id.tvRingBought).setVisibility(View.VISIBLE);
107 | break;
108 | case NECKLACE:
109 | findViewById(R.id.tvNecklaceBought).setVisibility(View.VISIBLE);
110 | break;
111 | case CROWN:
112 | findViewById(R.id.tvCrownBought).setVisibility(View.VISIBLE);
113 | break;
114 | }
115 | }
116 | }
117 | }
118 |
119 | @Override
120 | public void onPurchaseCompleted(Purchase purchase) {
121 | Toast.makeText(getApplicationContext(), "Purchase Successful", Toast.LENGTH_SHORT).show();
122 | updatePurchase(purchase);
123 | }
124 |
125 | private void updatePurchase(Purchase purchase){
126 | String sku = purchase.getSku();
127 | switch (sku) {
128 | case RING:
129 | findViewById(R.id.tvRingBought).setVisibility(View.VISIBLE);
130 | break;
131 | case NECKLACE:
132 | findViewById(R.id.tvNecklaceBought).setVisibility(View.VISIBLE);
133 | break;
134 | case CROWN:
135 | findViewById(R.id.tvCrownBought).setVisibility(View.VISIBLE);
136 | break;
137 | case TEST:
138 | totalCoins += 25;
139 | pref.edit().putInt(SETTINGS_COINS, totalCoins).apply();
140 | tvtotalCoin.setText(String.format(Locale.getDefault(), "%d", totalCoins));
141 | break;
142 | }
143 | }
144 |
145 | @Override
146 | protected void onDestroy() {
147 | super.onDestroy();
148 | if (iapHelper != null)
149 | iapHelper.endConnection();
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/java/com/demo/iap/Security.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2012 Google Inc.
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package com.demo.iap;
17 |
18 | import android.text.TextUtils;
19 | import android.util.Base64;
20 | import android.util.Log;
21 |
22 | import com.android.billingclient.api.Purchase;
23 |
24 | import java.security.InvalidKeyException;
25 | import java.security.KeyFactory;
26 | import java.security.NoSuchAlgorithmException;
27 | import java.security.PublicKey;
28 | import java.security.Signature;
29 | import java.security.SignatureException;
30 | import java.security.spec.InvalidKeySpecException;
31 | import java.security.spec.X509EncodedKeySpec;
32 |
33 | /**
34 | * Security-related methods. For a secure implementation, all of this code
35 | * should be implemented on a server that communicates with the
36 | * application on the device. For the sake of simplicity and clarity of this
37 | * example, this code is included here and is executed on the device. If you
38 | * must verify the purchases on the phone, you should obfuscate this code to
39 | * make it harder for an attacker to replace the code with stubs that treat all
40 | * purchases as verified.
41 | */
42 | public class Security {
43 | private static final String TAG = Security.class.getSimpleName();
44 |
45 | private static final String KEY_FACTORY_ALGORITHM = "RSA";
46 | private static final String SIGNATURE_ALGORITHM = "SHA1withRSA";
47 |
48 | //This you will get from Services & API in your application console
49 | public static String BASE_64_ENCODED_PUBLIC_KEY = "your_public_key_that you_get_from_google_play_console";
50 |
51 | /**
52 | * Verifies that the data was signed with the given signature, and returns
53 | * the verified purchase. The data is in JSON format and signed
54 | * with a private key. The data also contains the {@link Purchase.PurchaseState}
55 | * and product ID of the purchase.
56 | * @param base64PublicKey the base64-encoded public key to use for verifying.
57 | * @param signedData the signed JSON string (signed, not encrypted)
58 | * @param signature the signature for the data, signed with the private key
59 | */
60 | public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
61 | if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
62 | TextUtils.isEmpty(signature)) {
63 | Log.e(TAG, "Purchase verification failed: missing data.");
64 | return false;
65 | }
66 |
67 | PublicKey key = Security.generatePublicKey(base64PublicKey);
68 | return Security.verify(key, signedData, signature);
69 | }
70 |
71 | /**
72 | * Generates a PublicKey instance from a string containing the
73 | * Base64-encoded public key.
74 | *
75 | * @param encodedPublicKey Base64-encoded public key
76 | * @throws IllegalArgumentException if encodedPublicKey is invalid
77 | */
78 | private static PublicKey generatePublicKey(String encodedPublicKey) {
79 | try {
80 | byte[] decodedKey = Base64.decode(encodedPublicKey, Base64.DEFAULT);
81 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
82 | return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
83 | } catch (NoSuchAlgorithmException e) {
84 | throw new RuntimeException(e);
85 | } catch (InvalidKeySpecException e) {
86 | Log.e(TAG, "Invalid key specification.");
87 | throw new IllegalArgumentException(e);
88 | }
89 | }
90 |
91 | /**
92 | * Verifies that the signature from the server matches the computed
93 | * signature on the data. Returns true if the data is correctly signed.
94 | *
95 | * @param publicKey public key associated with the developer account
96 | * @param signedData signed data from server
97 | * @param signature server signature
98 | * @return true if the data and signature match
99 | */
100 | private static boolean verify(PublicKey publicKey, String signedData, String signature) {
101 | byte[] signatureBytes;
102 | try {
103 | signatureBytes = Base64.decode(signature, Base64.DEFAULT);
104 | } catch (IllegalArgumentException e) {
105 | Log.e(TAG, "Base64 decoding failed.");
106 | return false;
107 | }
108 | try {
109 | Signature sig = Signature.getInstance(SIGNATURE_ALGORITHM);
110 | sig.initVerify(publicKey);
111 | sig.update(signedData.getBytes());
112 | if (!sig.verify(signatureBytes)) {
113 | Log.e(TAG, "Signature verification failed.");
114 | return false;
115 | }
116 | return true;
117 | } catch (NoSuchAlgorithmException e) {
118 | Log.e(TAG, "NoSuchAlgorithmException.");
119 | } catch (InvalidKeyException e) {
120 | Log.e(TAG, "Invalid key specification.");
121 | } catch (SignatureException e) {
122 | Log.e(TAG, "Signature exception.");
123 | }
124 | return false;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/coins.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/drawable/coins.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/crown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/drawable/crown.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/get_coin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/drawable/get_coin.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/necklace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/drawable/necklace.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ring.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/drawable/ring.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
31 |
32 |
43 |
44 |
50 |
51 |
62 |
63 |
64 |
76 |
77 |
82 |
83 |
91 |
92 |
93 |
94 |
105 |
106 |
118 |
119 |
124 |
125 |
133 |
134 |
143 |
144 |
145 |
146 |
158 |
159 |
164 |
165 |
173 |
174 |
183 |
184 |
185 |
186 |
198 |
199 |
204 |
205 |
213 |
214 |
223 |
224 |
225 |
226 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | In-App Purchase Demo
3 |
4 | Consumable Product
5 | Non-Consumable Products
6 | Buy 25 Coins
7 | Unlocked Collection
8 | Ring
9 | Necklace
10 | Crown
11 | Bought
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/demo/iap/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.demo.iap;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.0'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 |
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 25 10:26:28 IST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/in-app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/surabhi6/InAppPurchaseDemo/5b417ee970247e825e1f56948e3d714f5c19384c/in-app.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='IAP'
3 |
--------------------------------------------------------------------------------