Skip to main content

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

Project description

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

IABwrapper-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

IABwrapper-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file IABwrapper-1.0.0.tar.gz.

File metadata

  • Download URL: IABwrapper-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.6

File hashes

Hashes for IABwrapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4fa8798c709ef16e6d581d406a3437854bf4142b7567085856c9ebbc2655ebf3
MD5 fe37762c9a53a8c47af71a07dbc1b3c8
BLAKE2b-256 177afb651dda710bbb015bd394ff758b8d250a02e4bf324176c945869156cec2

See more details on using hashes here.

Provenance

File details

Details for the file IABwrapper-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: IABwrapper-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.6

File hashes

Hashes for IABwrapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ff2954dbefd9f2fb158246e5066a31fea04697f3dc68aabcc00b452d4d650a
MD5 60fa5c759b5f9a6de69b5153a0a1049b
BLAKE2b-256 49a2a19bb0967cd8366b8486e820e7ba027d995b32974b8d9f605efd6fd68b36

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page