Skip to content

shashi278/android-iab-v3-kivy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IABwrapper

Wrapper around Anjlab's Android In-app Billing Version 3 to be used in Kivy apps

Build Status Python 3.6 PyPI format downloads code size repo size

Demo

Install

pip install iabwrapper

or add it in buildozer.spec requirements

requirements = ..., iabwrapper==0.0.5

Important ( Add these into your buildozer.spec )

  • android.gradle_repositories = "mavenCentral()"
  • android.gradle_dependencies = com.anjlab.android.iab.v3:library:2.0.0,
  • android.meta_data = billing_pubkey = "Your License Key from Play Console"
  • Necessary permissions:

    android.permissions = INTERNET,ACCESS_NETWORK_STATE,com.android.vending.BILLING

Usage

  • Import
    from iabwrapper import BillingProcessor
  • Create an Instance
    bp = BillingProcessor(
        license_key,
        onProductPurchasedMethod,
        onBillingErrorMethod,
        onPurchaseHistoryRestoredMethod=None,
        onBillingInitializedMethod=None,
    )
    
    # license_key is the license key string from Google Play Console
    
    # onProductPurchasedMethod expects two arguments: productId and purchaseInfo
    
    # onBillingErrorMethod expects two arguments: errorCode and error (use error.message to get the error message)
    
    # onPurchaseHistoryRestoredMethod does not expect any arguments
    
    # onBillingInitializedMethod does not expect any arguments

Useful Methods

  • Purchase a product

    purchase_product(product_id)
  • Consume a product(non-subscription)

    consume_purchase_async(product_id, success_listener=None, error_listener=None)
    
    # Both success_listener and error_listener doesn't take any arguments
  • Get details about a product (non-subscription)

    get_purchase_listing_async(product_id, success_listener=None, error_listener=None)
    
    # Both success_listener and error_listener expects a single argument.
    
    # success_listener gets a list with one element. Following details are available:
    if product_info.size() != 0:
        product_info = product_info[0]
        details= {
            "productId":        product_info.productId,
            "title":            product_info.title,
            "description":      product_info.description,
            "isSubscription":   product_info.isSubscription,
            "currency":         product_info.currency,
            "priceValue":       product_info.priceValue,
            "priceText":        product_info.priceText,
        }
    
    # error_listener gets a string with error message.
  • Subscribe to a product

    subscribe_product(product_id)
  • Get details about a subscription

    get_subscription_listing_async(product_id, success_listener=None, error_listener=None)
    
    # Both success_listener and error_listener expects a single argument.
    
    # Same as get_purchase_listing_async
  • Update information about users owned purchases/subscriptions. Use it to restore Purchases & Subscriptions.

    load_owned_purchases_async(success_listener=None, error_listener=None)
    
    # Both success_listener and error_listener doesn't take any arguments.
  • Check if service is initialized

    is_initialized()
  • Check if a product is already purchased(non-subscription)

    is_purchased(product_id)
  • Check if a product is already subscribed

    is_subscribed(product_id)
  • Before any usage it's good practice to check in-app billing services availability. In some older devices or chinese ones it may happen that Play Market is unavailable or is deprecated and doesn't support in-app billing.

    is_iab_service_available()
  • Please notice that calling BillingProcessor.isIabServiceAvailable() (only checks Play Market app installed or not) is not enough because there might be a case when it returns true but still payment won't succeed. Therefore, it's better to call bp.isConnected() after initializing BillingProcessor

    is_connected()
  • List owned products(non-subscription)

    list_owned_products()
    
    # Returns a list of product ids
  • List owned subscriptions

    list_owned_subscriptions()
    
    # Returns a list of product ids
  • Get very detailed info about a product(non-subscription)

    get_purchase_info(product_id)
    
    # Returns a `PurchaseInfo` object. Following details are available:
    purchase_info = bp.get_purchase_info(product_id)
    details = {
        "responseData": purchase_info.responseData,
        "signature": purchase_info.signature,
        "purchaseData":{
            "orderId": purchase_info.purchaseData.orderId,
            "productId": purchase_info.purchaseData.productId,
            "purchaseTime": purchase_info.purchaseData.purchaseTime,
            "purchaseToken": purchase_info.purchaseData.purchaseToken,
            "purchaseState": purchase_info.purchaseData.purchaseState,
            "autoRenewing": purchase_info.purchaseData.autoRenewing,
        }
    }
  • Get very detailed info about a subscription

    get_subscription_purchase_info(product_id)
    
    # Returns a `PurchaseInfo` object. Same as get_purchase_info

Example

See available demo application

More

To know more about what a method does, please see anjlab's android-inapp-billing-v3 docs for reference.

About

Wrapper around anjlab's Android In-app Billing Version 3

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages