mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
InAppPurchases: return failure status of restoring products bought list if IAP is unavailable.
This commit is contained in:
parent
d1c8762e8f
commit
99c4f716da
1 changed files with 18 additions and 11 deletions
|
|
@ -202,10 +202,10 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
|
||||
void restoreProductsBoughtList (bool, const juce::String&)
|
||||
{
|
||||
auto callback = [this](const Array<InAppPurchases::Listener::PurchaseInfo>& purchases)
|
||||
auto callback = [this](const GetProductsBoughtJob::Result& r)
|
||||
{
|
||||
const ScopedLock lock (getProductsBoughtJobResultsLock);
|
||||
getProductsBoughtJobResults.insert (0, purchases);
|
||||
getProductsBoughtJobResults.insert (0, r);
|
||||
triggerAsyncUpdate();
|
||||
};
|
||||
|
||||
|
|
@ -541,7 +541,14 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
//==============================================================================
|
||||
struct GetProductsBoughtJob : public ThreadPoolJob
|
||||
{
|
||||
using Callback = std::function<void(const Array<InAppPurchases::Listener::PurchaseInfo>&)>;
|
||||
struct Result
|
||||
{
|
||||
bool success = false;
|
||||
Array<InAppPurchases::Listener::PurchaseInfo> purchases;
|
||||
String statusDescription;
|
||||
};
|
||||
|
||||
using Callback = std::function<void(const Result&)>;
|
||||
|
||||
GetProductsBoughtJob (Pimpl& parent,
|
||||
const LocalRef<jstring>& packageNameToUse,
|
||||
|
|
@ -569,12 +576,12 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
purchases.add ({ purchase, {} });
|
||||
|
||||
if (callback)
|
||||
callback (purchases);
|
||||
callback ({true, purchases, "Success"});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (callback)
|
||||
callback ({});
|
||||
callback ({false, {}, "In-App purchases unavailable"});
|
||||
}
|
||||
|
||||
return jobHasFinished;
|
||||
|
|
@ -656,8 +663,8 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
public:
|
||||
struct Result
|
||||
{
|
||||
bool success = false;
|
||||
String productIdentifier;
|
||||
bool success;
|
||||
String statusDescription;
|
||||
};
|
||||
|
||||
|
|
@ -687,7 +694,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
if (token.isEmpty())
|
||||
{
|
||||
if (callback)
|
||||
callback ({ productIdentifier, false, NEEDS_TRANS ("Item not owned") });
|
||||
callback ({ false, productIdentifier, NEEDS_TRANS ("Item not owned") });
|
||||
|
||||
return jobHasFinished;
|
||||
}
|
||||
|
|
@ -696,12 +703,12 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
(jstring)packageName.get(), javaString (token).get());
|
||||
|
||||
if (callback)
|
||||
callback ({ productIdentifier, responseCode == 0, statusCodeToUserString (responseCode) });
|
||||
callback ({ responseCode == 0, productIdentifier, statusCodeToUserString (responseCode) });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (callback)
|
||||
callback ({{}, false, "In-App purchases unavailable"});
|
||||
callback ({false, {}, "In-App purchases unavailable"});
|
||||
}
|
||||
|
||||
return jobHasFinished;
|
||||
|
|
@ -785,7 +792,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
{
|
||||
const auto& result = getProductsBoughtJobResults.getReference (i);
|
||||
|
||||
owner.listeners.call (&Listener::purchasesListRestored, result, true, NEEDS_TRANS ("Success"));
|
||||
owner.listeners.call (&Listener::purchasesListRestored, result.purchases, result.success, result.statusDescription);
|
||||
getProductsBoughtJobResults.remove (i);
|
||||
}
|
||||
}
|
||||
|
|
@ -918,7 +925,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
|
|||
consumePurchaseJobResultsLock;
|
||||
|
||||
Array<Array<InAppPurchases::Product>> getProductsInformationJobResults;
|
||||
Array<Array<InAppPurchases::Listener::PurchaseInfo>> getProductsBoughtJobResults;
|
||||
Array<GetProductsBoughtJob::Result> getProductsBoughtJobResults;
|
||||
Array<ConsumePurchaseJob::Result> consumePurchaseJobResults;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue