Skip to main content

In App Purchases

buildfire.services.commerce.inAppPurchase#

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:

If you haven't setup your app for In App Purchases in buildfire or have not yet added any products go through the following links first:

note

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.
Notes for iOS
  • For testing purchases the build must be downloaded from TestFlight.

Requirements#

Widget#

Include inAppPurchase.js file in widget header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/services/commerce/inAppPurchase.js"></script>
</head>

Control#

Include inAppPurchase.js file in control header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../../scripts/buildfire/services/commerce/inAppPurchase.js"></script>
</head>

Methods#

getProducts()
#

buildfire.services.commerce.inAppPurchase.getProducts(callback)

Used to ask about the current app products list that are defined at buildfire control panel.

buildfire.services.commerce.inAppPurchase.getProducts((err, products) => {
if (err) return console.error(err);
console.log("In app purchase products", products);
});

callback(err, products)#

Callback function called when products are fetched. Might get error if called too early before InAppPurchase initializes.

NameTypeDescription
errstringerror string, null when operation is successfull
products[object]Array of products available

purchase()
#

buildfire.services.commerce.inAppPurchase.purchase(productId, callback)

Used to begin a purchase request

buildfire.services.commerce.inAppPurchase.purchase(
"m1eo1i1e91da2si2d12",
(err, result) => {
if (err) return console.error(err);
console.log("Purchase request result", result);
}
);

productId#

Id sasigned 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.

NameTypeRequiredDescriptionDefault
productIdtypeyesId sasigned 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, result)#

Callback function called when purchase request 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).

NameTypeDescription
errstringerror string, null when operation is successfull
resultobjectObject containing purchase result details

result#

NameTypeDescription
productobjectProduct object
isApprovedbooleanIndicates if payment is approved
hasErrorsbooleanIndicates if payment error happened
isCancelledbooleanIndicates if payment was cancelled