Implement in-app purchase in aide ide
Toturial on how add android In-App billing in your android app project. In this tutorial im using anjlab v.3 library, this library supports: In-App Product Purchases (both non-consumable and consumable) and Subscriptions.
Note this tutorial require developer console in order to get license key from playstore.
Lets start coding, first goto your "build.gradle" and add anjlab library:
compile 'com.anjlab.android.iab.v3:library:1.0.44'
compile 'com.android.billingclient:billing:1.0'
Next goto you "AndroidManifest.xml" and add permission.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
In your java files e.g "MainActivity.java" add this following codes:
import com.anjlab.android.iab.v3.*;
implements BillingProcessor.IBillingHandler
BillingProcessor bp;
String LicenceKoy = "xxxxxxxxxxccccccccccccxxxxxxxxxxxxxxxccccccxxxxxxxxxxxxxxxccccccccccccxxxxxxxxxxxxxxxccccccxxxxxxxxxxxxxxxccccccccccccxxxxxxxxxxxxxxxccccccxxxxxxxxxxxxxxxccccccccccccxxxxxxxxxxxxxxxccccccxxxxxxxxxxxxxxxccccccccccccxxxxxxxxxxxxxxxccccccxxxxx";
Follow this screenshot:
bp = new BillingProcessor(this, LicenceKoy, this);
bp.purchase(donate.this, "plan1_5k");
and the last step:
@Override
public void onBillingInitialized() {
/*
* Called when BillingProcessor was initialized and it's ready to purchase
*/
}
@Override
public void onProductPurchased(String productId, TransactionDetails details) {
/*
* Called when requested PRODUCT ID was successfully purchased
*/
Toast.makeText(getApplicationContext(), "Payment successful ", Toast.LENGTH_LONG).show();
}
@Override
public void onBillingError(int errorCode, Throwable error) {
/*
* Called when some error occurred. See Constants class for more details
*
* Note - this includes handling the case where the user canceled the buy dialog:
* errorCode = Constants.BILLING_RESPONSE_RESULT_USER_CANCELED
*/
Toast.makeText(getApplicationContext(), "Payment unsuccessful!!", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
if (bp != null) {
bp.release();
}
super.onDestroy();
}
@Override
public void onPurchaseHistoryRestored() {
/*
* Called when purchase history was restored and the list of all owned PRODUCT ID's
* was loaded from Google Play
*/
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!bp.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
Type of purchase:
Non-consumable:
bp.purchase(YOUR_ACTIVITY, "YOUR PRODUCT ID FROM GOOGLE PLAY CONSOLE HERE");
Subcribe:
bp.subscribe(YOUR_ACTIVITY, "YOUR SUBSCRIPTION ID FROM GOOGLE PLAY CONSOLE HERE");
Consumable:
bp.consumePurchase("YOUR PRODUCT ID FROM GOOGLE PLAY CONSOLE HERE");
For more documentation about anjlab library, please visit this link: https://github.com/anjlab/android-inapp-billing-v3
Faq:
Q: How to get a licence key?
A: After finish creating account in Developer console upload your apps, after finish upload click your app that uploaded and go to "Development tools" » "Services & API" and the result it look like this.
Q: How to get product id?
A: Goto "Store presense" » "In-app product" » "Manage Product" and the result it look like this.
Q: Can i use your Lincence key and product id for beta testing?
A: yes, download note this a sample only.. recommend create google developer account to get the license key and product id..
Watch the video tutorial here
Thank for this tutorial now i know how to add in-app purchase to my aide ide project
ReplyDeleteNice tutorials
ReplyDeleteTop react native app development company in Noida : Kickr Technology is an India-based digital marketing and web development company. Whether you are looking for large scale marketing solutions or a simple React native development mobile apps, our team will manage them in the best way.
ReplyDelete