Skip to content

In App Purchases Commerce Services

o5faruk edited this page May 2, 2021 · 4 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/in-app-purchases-commerce/

⚠️⚠️⚠️

##In App Purchases

IAP (In App Purchases) allows the user to gain access to premium digital content or features.

Both iOS and Android supports IAP.

Check links below for more info:

https://developer.apple.com/in-app-purchase/

https://developer.android.com/google/play/billing/billing_overview.html

If you haven't setup your app for IAP in buildfire or have added products go through the following links first:

https://github.com/BuildFire/sdk/wiki/Setup-IAP-for-Google-Play

https://github.com/BuildFire/sdk/wiki/Set-up-IAP-for-iOS

buildfire.services.commerce.inAppPurchase

Use this service on the widget side to retrieve products and make purchases. This service can also be used on the control side also but only for products retrieval.

Requirements

  • From the Widget or Control page
<script src="../../../scripts/buildfire/services/commerce/inAppPurchase.js"></script>

Constructor

none. inAppPurchase is a singleton

Methods

  • getProducts function (callback) : used to ask about the current app products list that are defined at buildfire control panel.
    • callback (err, products): callback function called when command is completed. might error out if called too early before InAppPurchase initializes.

Example

buildfire.services.commerce.inAppPurchase.getProducts(function(err, products) {
    if (!err) {
        // display the returned products
    }
});
  • purchase function (productId, callback) : used to begin a purchase request.
    • productId: Buildfire assigned ID to the product. Note that this ID is not the Google Play product ID or the iOS product ID. It is an auto generated ID that can be retrieved using getProducts function.

    • callback (err, products): callback function called when command is completed. may not be called if user leaves the purchase. Will return the result of the purchase request if request is successful (the request not the purchase itself). result will be one of these:

      • { product: approvedProduct, isApproved: true } if payment is approved
      • { product: product, hasErrors: true } if an error happened
      • { product: cancelledProduct, isCancelled: true } if payment is cancelled

Example

buildfire.services.commerce.inAppPurchase.purchase("[[BUILDFIRE-PRODUCT-ID]]", function(err, result) { 
    if (!err) {
        if(result.isApproved) {
            // display approved message
        } else {
            // display not approved message
        }
    }
});

###Notes:

  • Testing purchases only works on a mobile device.

###Notes for Android:

  • For testing purchases the build must be a release build and installed from Google Play Store (Alpha, Beta or Production).
  • Only testers added in your Google Play Store account can test purchases without requiring a real payment to be processed.
  • The Google Play Store account user cannot be an IAP tester or have the account user linked on testing devices.
Clone this wiki locally