Index

Cloneder provides the building blocks to implement In-App purchases specific to your app. Example code is provided which handles the cases of a one-off pro version purchase, a subscription, and consumable credits.

By default the in-app purchases plugin is not installed. You will need to install it by running the command ionic cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="[BILLING_KEY]"

With [BILLING_KEY] replaced with your billing key in your Android Play store console.

Billing code

The example code in the InAppPurchasesService service will update the premium flag on the User model for pro/subscription purchases, and update the credits field for consumable products.


    constructor(private userService: UserService, private inAppPurchases: InAppPurchasesService) {}

    premiumActionClick() {
      if(!this.inAppPurchases.isAvailable()) {
        console.error('Oops, need to install in-app purchases plugin')
        return
      }

      if(!this.userService.getCurrentUser().premium) {
        this.inAppPurchases.order('premium')
      } else {
        this.doPremiumAction()
      }
    }


    creditActionClick() {

      if(this.userService.getCurrentUser().credits === 0) {
        this.inAppPurchases.order('credits10')
        // or show a popup with options with options of credit packs to buy
      } else {
        // This would usually call to the server code which would then decrement the credits for the user
        this.doCreditAction()
      }
    }

Check the example code for the suggested id's to use when registering the in-app purchase products in your app stores.

Please refer to the Android, iOS and plugin documentation for the full details on in-app purchases.

https://github.com/j3k0/cordova-plugin-purchase

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

Stripe integration

For the web/PWA version you can use Stripe for purchases (and also in the mobile app versions for non-digital products where you are not required to use In-app purchases)

For subscription products you must first create a Plan in the Stripe dashboard for each recurring subscription product. Use the same id for the plan as for the corresponding app store subscription products.