Looks like QtPurchasing uses deprecated AIDL billing library and people say that it crashes on some devices. See https://developer.android.com/google/play/billing/deprecation-faq for more information. Probably they are going to update it in 5.15.7 and move it into examples in QT 6, so it is not clear exactly what will happen with it, we probably better wait QT 5.15.7 to be released.
Below I provided an example of QML code that uses QtPurchasing:
Store {
id: appStore
Product {
id: adfreeProduct
type: Product.Unlockable
identifier: "adfree"
//identifier: "android.test.purchased"
onStatusChanged: {
switch (status) {
case Product.PendingRegistration: console.debug("Registering " + identifier); break;
case Product.Registered: console.debug(identifier + " registered with price " + price + " owned: " + scene.adfree); break;
case Product.Unknown: console.debug(identifier + " was not found in the market place"); break;
}
}
onPurchaseSucceeded: {
console.log(identifier + " purchase successful");
scene.adfree = true;
transaction.finalize();
}
onPurchaseFailed: {
console.log(identifier + " purchase failed");
console.log("reason: "+ transaction.failureReason === Transaction.CanceledByUser ? "Canceled" : transaction.errorString);
fading.show(transaction.failureReason === Transaction.CanceledByUser ? qsTr("PurchaseCanceled") : qsTr("PurchaseFailed"), FadingMessage.Duration.Long);
transaction.finalize();
}
onPurchaseRestored: {
console.log(identifier + "purchase restored");
scene.adfree = true;
transaction.finalize();
}
}
}
function purchaseAdfree()
{
if (adfreeProduct.status === Product.Registered)
{
adfreeProduct.purchase()
}
else
{
fading.show(qsTr("PurchaseFailed"), FadingMessage.Duration.Long);
}
}
Theoretically QtPurchasing can be reimplement it with Billing Library v4 without updating QML code.
To test it we probably need some app in Google Play with a product id.
They move it into examples in QT 6.2.
Building a sample
I built some Google Play Billing Sample and got this message on the emulator:
Java sources from the sample probably compiles in my project if I add the following line to build.gradle
:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'com.google.android.gms:play-services-ads:18.3.0'
implementation "com.android.billingclient:billing:4.0.0"
}