1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2020 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 6 End-User License
11 Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
12
13 End User License Agreement: www.juce.com/juce-6-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24 */
25
26 namespace juce
27 {
28
29 //==============================================================================
JUCE_IMPLEMENT_SINGLETON(InAppPurchases)30 JUCE_IMPLEMENT_SINGLETON (InAppPurchases)
31
32 InAppPurchases::InAppPurchases()
33 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
34 : pimpl (new Pimpl (*this))
35 #endif
36 {}
37
~InAppPurchases()38 InAppPurchases::~InAppPurchases() { clearSingletonInstance(); }
39
isInAppPurchasesSupported() const40 bool InAppPurchases::isInAppPurchasesSupported() const
41 {
42 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
43 return pimpl->isInAppPurchasesSupported();
44 #else
45 return false;
46 #endif
47 }
48
getProductsInformation(const StringArray & productIdentifiers)49 void InAppPurchases::getProductsInformation (const StringArray& productIdentifiers)
50 {
51 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
52 pimpl->getProductsInformation (productIdentifiers);
53 #else
54 Array<Product> products;
55 for (auto productId : productIdentifiers)
56 products.add (Product { productId, {}, {}, {}, {} });
57
58 listeners.call ([&] (Listener& l) { l.productsInfoReturned (products); });
59 #endif
60 }
61
purchaseProduct(const String & productIdentifier,const String & upgradeProductIdentifier,bool creditForUnusedSubscription)62 void InAppPurchases::purchaseProduct (const String& productIdentifier,
63 const String& upgradeProductIdentifier,
64 bool creditForUnusedSubscription)
65 {
66 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
67 pimpl->purchaseProduct (productIdentifier, upgradeProductIdentifier, creditForUnusedSubscription);
68 #else
69 Listener::PurchaseInfo purchaseInfo { Purchase { "", productIdentifier, {}, {}, {} }, {} };
70
71 listeners.call ([&] (Listener& l) { l.productPurchaseFinished (purchaseInfo, false, "In-app purchases unavailable"); });
72 ignoreUnused (upgradeProductIdentifier, creditForUnusedSubscription);
73 #endif
74 }
75
restoreProductsBoughtList(bool includeDownloadInfo,const String & subscriptionsSharedSecret)76 void InAppPurchases::restoreProductsBoughtList (bool includeDownloadInfo, const String& subscriptionsSharedSecret)
77 {
78 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
79 pimpl->restoreProductsBoughtList (includeDownloadInfo, subscriptionsSharedSecret);
80 #else
81 listeners.call ([] (Listener& l) { l.purchasesListRestored ({}, false, "In-app purchases unavailable"); });
82 ignoreUnused (includeDownloadInfo, subscriptionsSharedSecret);
83 #endif
84 }
85
consumePurchase(const String & productIdentifier,const String & purchaseToken)86 void InAppPurchases::consumePurchase (const String& productIdentifier, const String& purchaseToken)
87 {
88 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
89 pimpl->consumePurchase (productIdentifier, purchaseToken);
90 #else
91 listeners.call ([&] (Listener& l) { l.productConsumed (productIdentifier, false, "In-app purchases unavailable"); });
92 ignoreUnused (purchaseToken);
93 #endif
94 }
95
addListener(Listener * l)96 void InAppPurchases::addListener (Listener* l) { listeners.add (l); }
removeListener(Listener * l)97 void InAppPurchases::removeListener (Listener* l) { listeners.remove (l); }
98
startDownloads(const Array<Download * > & downloads)99 void InAppPurchases::startDownloads (const Array<Download*>& downloads)
100 {
101 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
102 pimpl->startDownloads (downloads);
103 #else
104 ignoreUnused (downloads);
105 #endif
106 }
107
pauseDownloads(const Array<Download * > & downloads)108 void InAppPurchases::pauseDownloads (const Array<Download*>& downloads)
109 {
110 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
111 pimpl->pauseDownloads (downloads);
112 #else
113 ignoreUnused (downloads);
114 #endif
115 }
116
resumeDownloads(const Array<Download * > & downloads)117 void InAppPurchases::resumeDownloads (const Array<Download*>& downloads)
118 {
119 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
120 pimpl->resumeDownloads (downloads);
121 #else
122 ignoreUnused (downloads);
123 #endif
124 }
125
cancelDownloads(const Array<Download * > & downloads)126 void InAppPurchases::cancelDownloads (const Array<Download*>& downloads)
127 {
128 #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
129 pimpl->cancelDownloads (downloads);
130 #else
131 ignoreUnused (downloads);
132 #endif
133 }
134
135 } // namespace juce
136