summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java18
-rw-r--r--src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp18
2 files changed, 25 insertions, 11 deletions
diff --git a/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java b/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java
index 002e94b..94bc202 100644
--- a/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java
+++ b/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java
@@ -374,7 +374,7 @@ public class QtInAppPurchase
m_publicKey = publicKey;
}
- public IntentSender createBuyIntentSender(String identifier)
+ public IntentSender createBuyIntentSender(String identifier, int requestCode)
{
if (m_service == null) {
Log.e(TAG, "Unable to create buy intent. No IAP service connection.");
@@ -388,9 +388,21 @@ public class QtInAppPurchase
TYPE_INAPP,
identifier);
int response = bundleResponseCode(purchaseBundle);
+
if (response != RESULT_OK) {
- Log.e(TAG, "Unable to create buy intent. Response code: " + response);
- return null;
+ Log.e(TAG, "Unable to create buy intent. Response code: " + response);
+ String errorString;
+ switch (response) {
+ case RESULT_BILLING_UNAVAILABLE: errorString = "Billing unavailable"; break;
+ case RESULT_ITEM_UNAVAILABLE: errorString = "Item unavailable"; break;
+ case RESULT_DEVELOPER_ERROR: errorString = "Developer error"; break;
+ case RESULT_ERROR: errorString = "Fatal error occurred"; break;
+ case RESULT_ITEM_ALREADY_OWNED: errorString = "Item already owned"; break;
+ default: errorString = "Unknown billing error " + response; break;
+ };
+
+ purchaseFailed(requestCode, FAILUREREASON_ERROR, errorString);
+ return null;
}
PendingIntent pendingIntent = purchaseBundle.getParcelable("BUY_INTENT");
diff --git a/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp b/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp
index e6a42cb..ee00591 100644
--- a/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp
+++ b/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp
@@ -334,14 +334,6 @@ void QAndroidInAppPurchaseBackend::purchaseProduct(QAndroidInAppProduct *product
return;
}
- QAndroidJniObject intentSender = m_javaObject.callObjectMethod("createBuyIntentSender",
- "(Ljava/lang/String;)Landroid/content/IntentSender;",
- QAndroidJniObject::fromString(product->identifier()).object<jstring>());
- if (!intentSender.isValid()) {
- purchaseFailed(product, QInAppTransaction::ErrorOccurred, QStringLiteral("Unable to get intent sender from service"));
- return;
- }
-
int requestCode = 0;
while (m_activePurchaseRequests.contains(requestCode)) {
requestCode++;
@@ -352,6 +344,16 @@ void QAndroidInAppPurchaseBackend::purchaseProduct(QAndroidInAppProduct *product
}
m_activePurchaseRequests[requestCode] = product;
+
+ QAndroidJniObject intentSender = m_javaObject.callObjectMethod("createBuyIntentSender",
+ "(Ljava/lang/String;I)Landroid/content/IntentSender;",
+ QAndroidJniObject::fromString(product->identifier()).object<jstring>(), requestCode);
+
+ if (!intentSender.isValid()) {
+ m_activePurchaseRequests.remove(requestCode);
+ return;
+ }
+
QtAndroid::startIntentSender(intentSender, requestCode, this);
}