mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-07 04:10:08 +00:00
IAP: Ensured that IAP can compile even on platforms that don't support IAP
This commit is contained in:
parent
6cbae93696
commit
ba1cba9547
6 changed files with 101 additions and 36 deletions
|
|
@ -48,15 +48,6 @@ public:
|
|||
dm.initialiseWithDefaultDevices (0, 2);
|
||||
|
||||
mainWindow = new MainWindow;
|
||||
|
||||
Timer::callAfterDelay(1000, [] ()
|
||||
{
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
|
||||
"Your credit card will be charged!",
|
||||
"You are running the sample code for JUCE In-App purchases."
|
||||
"Although this is only sample code, it will still CHARGE YOUR CREDIT CARD!",
|
||||
"Understood!");
|
||||
});
|
||||
}
|
||||
|
||||
void shutdown() override
|
||||
|
|
|
|||
|
|
@ -97,7 +97,25 @@ private:
|
|||
//==============================================================================
|
||||
void productsInfoReturned (const Array<InAppPurchases::Product>& products) override
|
||||
{
|
||||
if (products.size() != 0)
|
||||
if (! inAppPurchases.isInAppPurchasesSupported())
|
||||
{
|
||||
for (auto idx = 1; idx < voiceProducts.size(); ++idx)
|
||||
{
|
||||
auto& voiceProduct = voiceProducts.getReference (idx);
|
||||
|
||||
voiceProduct.isPurchased = false;
|
||||
voiceProduct.priceIsKnown = false;
|
||||
voiceProduct.purchasePrice = "In-App purcahses unavailable";
|
||||
}
|
||||
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
|
||||
"In-app purchase is unavailable!",
|
||||
"In-App purchases are not available. This either means you are trying "
|
||||
"to use IAP on a platform that does not support IAP or you haven't setup "
|
||||
"your app correctly to work with IAP.",
|
||||
"OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto product : products)
|
||||
{
|
||||
|
|
@ -111,17 +129,12 @@ private:
|
|||
voiceProduct.purchasePrice = product.price;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (! inAppPurchases.isInAppPurchasesSupported())
|
||||
{
|
||||
for (auto idx = 1; idx < voiceProducts.size(); ++idx)
|
||||
{
|
||||
auto& voiceProduct = voiceProducts.getReference (idx);
|
||||
|
||||
voiceProduct.isPurchased = false;
|
||||
voiceProduct.priceIsKnown = false;
|
||||
voiceProduct.purchasePrice = "In-App purcahses unavailable";
|
||||
}
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
|
||||
"Your credit card will be charged!",
|
||||
"You are running the sample code for JUCE In-App purchases. "
|
||||
"Although this is only sample code, it will still CHARGE YOUR CREDIT CARD!",
|
||||
"Understood!");
|
||||
}
|
||||
|
||||
guiUpdater.triggerAsyncUpdate();
|
||||
|
|
|
|||
|
|
@ -25,17 +25,33 @@
|
|||
*/
|
||||
|
||||
|
||||
InAppPurchases::InAppPurchases() : pimpl (new Pimpl (*this)) {}
|
||||
InAppPurchases::InAppPurchases()
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
: pimpl (new Pimpl (*this))
|
||||
#endif
|
||||
{}
|
||||
InAppPurchases::~InAppPurchases() {}
|
||||
|
||||
bool InAppPurchases::isInAppPurchasesSupported() const
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
return pimpl->isInAppPurchasesSupported();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::getProductsInformation (const StringArray& productIdentifiers)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->getProductsInformation (productIdentifiers);
|
||||
#else
|
||||
Array<Product> products;
|
||||
for (auto productId : productIdentifiers)
|
||||
products.add (Product {productId});
|
||||
|
||||
listeners.call (&Listener::productsInfoReturned, products);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::purchaseProduct (const String& productIdentifier,
|
||||
|
|
@ -43,24 +59,72 @@ void InAppPurchases::purchaseProduct (const String& productIdentifier,
|
|||
const StringArray& upgradeProductIdentifiers,
|
||||
bool creditForUnusedSubscription)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->purchaseProduct (productIdentifier, isSubscription,
|
||||
upgradeProductIdentifiers, creditForUnusedSubscription);
|
||||
#else
|
||||
Listener::PurchaseInfo purchaseInfo { Purchase {"", productIdentifier}, {} };
|
||||
|
||||
listeners.call (&Listener::productPurchaseFinished, purchaseInfo, false, "In-app purchases unavailable");
|
||||
ignoreUnused (isSubscription, upgradeProductIdentifiers, creditForUnusedSubscription);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::restoreProductsBoughtList (bool includeDownloadInfo, const String& subscriptionsSharedSecret)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->restoreProductsBoughtList (includeDownloadInfo, subscriptionsSharedSecret);
|
||||
#else
|
||||
listeners.call (&Listener::purchasesListRestored, Array<Listener::PurchaseInfo>(), false, "In-app purchases unavailable");
|
||||
ignoreUnused (includeDownloadInfo, subscriptionsSharedSecret);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::consumePurchase (const String& productIdentifier, const String& purchaseToken)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->consumePurchase (productIdentifier, purchaseToken);
|
||||
#else
|
||||
listeners.call (&Listener::productConsumed, productIdentifier, false, "In-app purchases unavailable");
|
||||
ignoreUnused (purchaseToken);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::addListener (Listener* l) { listeners.add (l); }
|
||||
void InAppPurchases::removeListener (Listener* l) { listeners.remove (l); }
|
||||
|
||||
void InAppPurchases::startDownloads (const Array<Download*>& downloads) { pimpl->startDownloads (downloads); }
|
||||
void InAppPurchases::pauseDownloads (const Array<Download*>& downloads) { pimpl->pauseDownloads (downloads); }
|
||||
void InAppPurchases::resumeDownloads (const Array<Download*>& downloads) { pimpl->resumeDownloads (downloads); }
|
||||
void InAppPurchases::cancelDownloads (const Array<Download*>& downloads) { pimpl->cancelDownloads (downloads); }
|
||||
void InAppPurchases::startDownloads (const Array<Download*>& downloads)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->startDownloads (downloads);
|
||||
#else
|
||||
ignoreUnused (downloads);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::pauseDownloads (const Array<Download*>& downloads)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->pauseDownloads (downloads);
|
||||
#else
|
||||
ignoreUnused (downloads);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::resumeDownloads (const Array<Download*>& downloads)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->resumeDownloads (downloads);
|
||||
#else
|
||||
ignoreUnused (downloads);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InAppPurchases::cancelDownloads (const Array<Download*>& downloads)
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
pimpl->cancelDownloads (downloads);
|
||||
#else
|
||||
ignoreUnused (downloads);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,8 +262,10 @@ private:
|
|||
friend void juce_inAppPurchaseCompleted (void*);
|
||||
#endif
|
||||
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
struct Pimpl;
|
||||
friend struct Pimpl;
|
||||
|
||||
ScopedPointer<Pimpl> pimpl;
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,16 +50,13 @@
|
|||
|
||||
namespace juce
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
#if JUCE_ANDROID
|
||||
#include "native/juce_android_InAppPurchases.cpp"
|
||||
#elif JUCE_IOS
|
||||
#include "native/juce_ios_InAppPurchases.cpp"
|
||||
#endif
|
||||
|
||||
#include "in_app_purchases/juce_InAppPurchases.cpp"
|
||||
#if JUCE_ANDROID
|
||||
#include "native/juce_android_InAppPurchases.cpp"
|
||||
#elif JUCE_IOS
|
||||
#include "native/juce_ios_InAppPurchases.cpp"
|
||||
#endif
|
||||
|
||||
#include "in_app_purchases/juce_InAppPurchases.cpp"
|
||||
#include "marketplace/juce_OnlineUnlockStatus.cpp"
|
||||
|
||||
#if JUCE_MODULE_AVAILABLE_juce_data_structures
|
||||
|
|
|
|||
|
|
@ -79,9 +79,7 @@
|
|||
|
||||
namespace juce
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
#include "in_app_purchases/juce_InAppPurchases.h"
|
||||
#endif
|
||||
#include "in_app_purchases/juce_InAppPurchases.h"
|
||||
|
||||
#if JUCE_MODULE_AVAILABLE_juce_data_structures
|
||||
#include "marketplace/juce_OnlineUnlockStatus.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue