Skip to content

moritzstoetter/qt6purchasing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

qt6purchasing


Logo

Qt6/QML In-App-Purchasing

Bringing In-App-Purchasing to Qt6

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact

About The Project

This project provides a library wrapper, that provides an abstraction of the native app store libraries, and makes the necessary functionalities available in Qt6 and QML. Compatible with Apple App Store and Google Play Store.

Here's why:

  • In-App-Purchasing might be an important way of monetizing your Qt/QML mobile app.
  • QtPurchasing didn't make it to Qt6.

(back to top)

Built With

Qt6
Cpp
Objective-C
Java
Cmake

(back to top)

Getting Started

To add In-App-Purchasing capabilities to your Qt6/QML project follow the steps below.

Prerequisites

  • Qt/QML 6
  • Apple StoreKit
  • Android Billing Client

Installation

  1. Clone this repo into a folder in your project.
git clone https://github.com/moritzstoetter/qt6purchasing.git
  1. Move 'android/GooglePlayBilling.java' to QT_ANDROID_PACKAGE_SOURCE_DIR/src/com/COMPANY_NAME/APP_NAME/GooglePlayBilling.java For more information on how to include custom Java-Code in your Android App see Deploying an Application on Android.
  2. Add the qt6purchasing Library to your Project. In your project's CMakeLists.txt add the following:
    target_link_libraries(APP_NAME
     PRIVATE
         ...
         store
     )
  3. Expose the purchasing classes to QML. In your main.cpp include the following lines:
#if defined Q_OS_ANDROID
#include <QJniObject>
#include <QCoreApplication>
#include "backend/store/android/googleplaystorebackend.h"
#include "backend/store/android/googleplaystoreproduct.h"
#include "backend/store/android/googleplaystoretransaction.h"
#endif

#if defined Q_OS_DARWIN
#include "backend/store/apple/appleappstorebackend.h"
#include "backend/store/apple/appleappstoreproduct.h"
#include "backend/store/apple/appleappstoretransaction.h"
#endif

...

qmlRegisterUncreatableType<AbstractStoreBackend>("AbstractStoreBackend",1,0,"AbstractStoreBackend","AbstractProduct uncreatable");
qmlRegisterUncreatableType<AbstractProduct>("AbstractProduct",1,0,"AbstractProduct","AbstractProduct uncreatable");
qmlRegisterUncreatableType<AbstractTransaction>("AbstractTransaction",1,0,"AbstractTransaction","AbstractTransaction uncreatable");
#if defined Q_OS_ANDROID
qmlRegisterType<GooglePlayStoreBackend>("Store", 1, 0, "Store");
qmlRegisterType<GooglePlayStoreProduct>("Product", 1, 0, "Product");
#elif defined Q_OS_DARWIN
qmlRegisterType<AppleAppStoreBackend>("Store", 1, 0, "Store");
qmlRegisterType<AppleAppStoreProduct>("Product", 1, 0, "Product");
#endif

(back to top)

Usage

  1. In your QML file include the purchasing classes:
import Store
import Product  
  1. Use it like this, for a product that is called "test_1" in the app store(s):
Store {
  id: iapStore
  Product {
    id: testingProduct
    identifier: "test_1"
    type: Product.Consumable
  }
}

StoreItem {
  id: testingStoreItem
  product: testingProduct

  onIapCompleted: root.accepted()
}

StoreItem.qml:

import QtQuick
import Product

Item {
  id: root
  required property Product product

  signal iapCompleted

  enum PurchasingStatus {
      NoPurchase,
      PurchaseProcessing,
      PurchaseSuccess,
      PurchaseFail
  }
  property int purchasingStatus: StoreItem.PurchasingStatus.NoPurchase

  function purchase() {
      purchasingStatus = StoreItem.PurchasingStatus.PurchaseProcessing
      product.purchase()
  }

  function finalize(transaction) {
      purchasingStatus = StoreItem.PurchasingStatus.PurchaseSuccess
      transaction.finalize()
  }

  Connections {
      target: product
      function onPurchaseSucceeded(transaction) {
          finalize(transaction)
      }
      function onPurchaseRestored(transaction) {
          finalize(transaction)
      }
      function onPurchaseFailed(transaction) {
          purchasingStatus = StoreItem.PurchasingStatus.PurchaseFail
      }
      function onPurchaseConsumed(transaction) {
          root.iapCompleted()
      }
  }
}

(back to top)

Contributing

Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Moritz Stötter - moritzstoetter.dev - [email protected]

(back to top)

About

Qt6/QML In-App-Purchasing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published