GithubHelp home page GithubHelp logo

eggheadgames / android-in-app-payments Goto Github PK

View Code? Open in Web Editor NEW
57.0 6.0 14.0 370 KB

Support Android Google Play and Amazon in-app billing (IAP) payments with one API

License: MIT License

Java 19.01% Kotlin 80.99%

android-in-app-payments's Introduction

Circle CI Release GitHub license

Android Payments

Support both Google Play and Amazon Kindle Fire in-app purchase payments with a single API

Handy for small apps with in-app purchase (IAP) items that need both Google Play store and Amazon App Store support - i.e. regular Android devices and Amazon Kindle Fire. We developed this as a convenient way to keep multiple apps updated with the latest IAP code for Play and Amazon.

About

A simple wrapper library that provides sample Google and Amazon in-app purchase APIs in a single API.

Features:

Not supported:

  • receipt validation (either local or server)
  • consumable items

Similar Libraries

This library is in the same category as OpenIAB (supports many more stores), OPFLab (replacement for OpenIAB). If you do not need Amazon support, there are several libraries that support just the Play store (see the Android Arsenal list).

Installation Instructions

Add the JitPack.io repository to your root build.gradle:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Add an appstore flavor to your application related build.gradle and the corresponding google and amazon dependencies.

android {
    flavorDimensions "appstore"
    productFlavors {
        google {
            dimension "appstore"
        }
        amazon {
            dimension "appstore"
        }
…
}

dependencies {
    googleImplementation "com.github.eggheadgames:android-in-app-payments:x.y.z:google@aar"
    googleImplementation 'com.android.billingclient:billing:3.0.0'  // fixme: not sure why this is not automatic

    amazonImplementation "com.github.eggheadgames:android-in-app-payments:x.y.z:amazon@aar"
}

Example

Setup

The following code snippet initializes the billing module:

    IAPManager.build(context, skuList, ArrayList<>());
    IAPManager.addPurchaseListener(new PurchaseServiceListener() {
            @Override
            public void onPricesUpdated(Map<String, String> map) {
                // list of available products will be received here, so you can update UI with prices if needed
            }
            
            @Override
            public void onProductPurchased(String sku) {
                // will be triggered whenever purchase succeeded 
            }

            @Override
            public void onProductRestored(String sku) {
                // will be triggered fetching owned products using IAPManager.init();
            }
    });
    IAPManager.init(googleIapKey /*can be ignored for Amazon target*/);
  1. Setup billing module.
IAPManager.build(Context context, List<String> skuList, List<String> subscriptionSkuList)
  • List<String> skuList - a list of products to fetch information about
  • List<String> subscriptionSkuList - a list of subscription products to fetch information about (or empty if none)
  1. Request info about available and owned products
IAPManager.init(String rot13LicenseKey)

String rot13LicenseKey is relevant only for the google flavor, and can be ignored for IAPManager.BUILD_TARGET_AMAZON. Note that this is the required Google License Key obtained from the app's Google Play console, after applying the ROT 13 algorithm. You might choose to store the key as ROT-13 in your app to avoid casual decoding of the strings, however, this is not really secure, so you are advised to follow Google's advice and then ROT-13 the key before passing it to the API:

Security Recommendation: Google highly recommends that you do not hard-code the exact public license key string value as provided by Google Play. Instead, construct the whole public license key string at runtime from substrings or retrieve it from an encrypted store before passing it to the constructor. This approach makes it more difficult for malicious third parties to modify the public license key string in your APK file.

Buying a product

To buy a product use the following method:

IAPManager.buy(Activity activity, String sku, int requestCode);

PurchaseServiceListener will notify application about the operation result

Subscriptions

The following listener can be used to obtain owned subscriptions and to get notification about subscription operation result

    IAPManager.addSubscriptionListener(new SubscriptionServiceListener() {
        @Override
        public void onSubscriptionRestored(String s) {
            // will be triggered upon fetching owned subscription using IAPManager.init();
        }

        @Override
        public void onSubscriptionPurchased(String s) {
            // will be triggered whenever subscription succeeded
        }

        @Override
        public void onPricesUpdated(Map<String, String> map) {
            // list of available products will be received here, so you can update UI with prices if needed            
        }
    });

To start a subscription use the following method:

IAPManager.subscribe(Activity activity, String sku, int requestCode);

String sku - a subscription ID int requestCode - a unique request code to be used to deliver result through onActivityResult SubscriptionServiceListener.onSubscriptionPurchased() will notify application about successful operation result

Use the following method to remove subscription

IAPManager.unsubscribe(Activity activity, String sku, int requestCode);

Please keep in mind that for Google In App Billing it will just lead user to the Google Pay Account Settings page where user may cancel subscription manually.

Note

When you are integrating Google In App Billing Subscriptions into your application please pay attention for the subscription cancellation handling. As long as currently subscription can be cancelled only through Google Play Account settings - application won't be notified about this event. Thus you have to query for the owned subscriptions each time you open the application (if needed), which is done via IAPManager.init() method.

android-in-app-payments's People

Contributors

alexdibrivnyy avatar apisov avatar eggheadgames avatar mikemee avatar yurii-diachenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

android-in-app-payments's Issues

Use new Google Subscription deep link

We should update the library to use this new link from Google:

On Android, open the Google Play Store, then tap Menu > Subscriptions.
On a computer, go to play.google.com, then in the left menu click My
subscriptions.
On either Android or a computer, use the URL
http://play.google.com/store/account/subscriptions to open the user's list
of subscriptions.
For active subscriptions, use the deep-link
http://play.google.com/store/account/subscriptions?package=samplePackage&sku=sampleSKU
with your package and SKU name to directly open the page to manage the
user's specific subscription. Learn more about the manage subscription
deep-link by checking out our documentation for subscription-specific
features.

Action required

Please update the instructions in your app or website to reflect this
change. If you are currently deep-linking to
http://play.google.com/store/account/ to manage subscriptions, please be
sure to update your instructions to one of the recommended options listed
above.

Ah, it looks like this is in the IAP library, here:

intent.setData(Uri.parse("https://play.google.com/store/account"));

I.e. this code:

  @Override
    public void unsubscribe(Activity activity, String sku, int id) {
        try {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://play.google.com/store/account"));
            activity.startActivity(intent);
            activity.finish();
        } catch (Exception e) {
            e.printStackTrace();
        }
}

So we need to replace the URL there I think...

Do i need to update from version 2.0.0?

Hi,
My apps is currently using version 2.0.0. Do i need to update to 3.0.0?
I checked releases, but not found any critical issues.
Thank you for very good IAP Lib!

Document that init method takes in a rot-13 encoded key.

I've just started using this library for my app, and couldn't for the life of me figure out why I wasn't getting any responses from the server.

After debugging through the code, it turns out you guys are expecting a rot-13 encoded key in the init method. It might be a good idea to document that somewhere.

Nice work on the lib btw!

Update to latest Amazon In-App Purchase SDK 2.0.76

Let's update to the latest (Sep 1, 2016) SDK 2.0.76 from our current version of 2.0.61.

According to the release notes, https://developer.amazon.com/docs/in-app-purchasing/iap-whats-new.html, the only change is:

Products returned by the getProductData API now include a Coins reward amount, an optional field that surfaces the amount of Amazon Coins a customer will be rewarded after purchasing that product

This shouldn't affect us (except perhaps we ignore that extra value?) because we don't do anything with Coins rewards.

Detect "already owned" message and unlock

A Google Play customer reports that if she purchases on one device and then tries to refresh her 2nd device (using the same Play account), that the new purchase doesn't register for 1-2 days.

However, if she tries to purchase the same volume on the 2nd device, it says: "You already own this". However, our library doesn't handle this and unlock the volume.

Is there something we can do about this, or are we at the mercy of Google?

How to know a product is not owned ?

Hi,
Your library seems great thanks for it, but is there a way to know a product is NOT owned ?
We know only when is it owned with the onProductRestored or onSubscriptionRestored callback, but we don't know when it is not owned.
A least a callback notifying when products or subscriptions lookup is finished would be great.
Please tell me is there is a way to do something similar.
Thanks !

Add new `init` function that does not take a key

Per discussion in #10, it would be nice to have an init function for Amazon that does not require a key, e.g. something like:

public static void init(boolean enableLogging) {
   init(null, enableLogging)
}

public static void init(String key, boolean enableLogging) {
   if(key!=null){        
      billingService.init(key);
   }
   billingService.enableDebugLogging(enableLogging);
}

Fix Google Families Ads Program rejection because "use of Amazon SDK"

Google contacted us (Egghead Games) warning that our "family friendly" app status is in jeopardy because:

We have detected the use of Amazon SDK

This turns out to be because this library is being used, and it always includes the Amazon file libs/in-app-purchasing-2.0.76 regardless of whether it is an APK built for Google Play or Amazon app stores.

The solution adopted is to use the Android flavor mechanism to build this aar so that the app can choose the correct flavor at build time. Details are in the README.md file.

This is (will be) fixed in version 3.0.0 of the library.


FYI, here is the full version of the Google notification email (after querying them for details):

During review, we found that your app (removed name of app) violates the policy: Families Ads Program

We have detected that your app includes non-certified ad SDKs and/or SDKs that are not approved for use in child-directed services. Any SDKs used in the app must be appropriate for use in child-directed services. Additionally, apps that solely target children must not contain any SDKs that are not approved for use in child-directed services, including ads SDKs. Apps in the Designed for Families program must only use ad SDKs that have certified their compliance with the Families Ads Program.

You can read through the Families Policy Requirements, Designed for Families Requirements, and Ads and Monetization policy for more information.

We have detected the use of Amazon SDK, which is not allowed in apps that are in the Families program. An ad SDK is not allowed if it has not self-certified its compliance with Play’s Families Ads Program (certified ad SDKs), or it is non-COPPA compliant per its own public documentation. Please note, the status of SDKs often changes and it is your responsibility to review documentation of all SDKs used in your app to ensure compliance with Families policies

Add SpotBugs

Let's get the full lint, PMD and SpotBugs (FindBugs) checking running, like we do on our other projects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.