summaryrefslogtreecommitdiffstats
path: root/examples/demos/hangman/doc/src/baseclass.qdoc
blob: b5e36293af0c10fd890d7899d35697a995abfe52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
   \page qtpurchasing-baseclasses.html
   \title Base Classes
   \brief Base classes are used in purchasing demo to enable cross-platform for Android and iOS.
   \ingroup qtpurchasing-examples

   \section1 Classes
   \table
      \header
         \li Class
         \li Description
      \row
         \li \l InAppProduct
         \li A product registered in the store.
      \row
         \li \l InAppStore
         \li Main entry point for managing in-app purchases.
      \row
         \li \l InAppTransaction
         \li Contains information about a transaction in the external app store.
      \row
         \li \l InAppPurchaseBackend
         \li Communicates with the external store.
   \endtable

   \section1 InAppProduct

   InAppProduct encapsulates a product in the external store after it has been registered in
   InAppStore and confirmed to exist. It has an identifier which matches the identifier of the
   product in the external store, it has a price which is retrieved from the external store,
   and it has a product type.

   The product type can be \c Consumable or \c Unlockable. Consumable products can be
   purchased any number of times as long as each transaction is finalized explicitly by the
   application. Unlockable types can only be purchased once.

   InAppProduct has 5 returnable variables \c price, \c title, \c description \c identifier and
   \c productType. All return a QString except productType.

   ProductType is an enum type and returns \c 0 if it is Consumable and \c 1 if Unlockable.
   \code
   enum ProductType
   {
      Consumable,
      Unlockable
   };
   \endcode

   Check out the derived classes \c AndroidInAppProduct for Android and \c IosInAppProduct for iOS.

   \section1 InAppStore

   The main entry point for managing in-app purchases. It is the base class for \c AndroidInAppProduct and
   \c IosInAppProduct.

   InAppStore is used for managing in-app purchases in the application in a cross-platform way.
   Depending on the compiler, InAppStore checks what platform is available using \c Macros.

   \code
   void InAppStore::setupBackend()
   {
      #ifdef Q_OS_ANDROID
      d->backend = new AndroidInAppPurchaseBackend;
      #endif

      #ifdef Q_OS_IOS
      d->backend = new IosInAppPurchaseBackend;
      #endif

      d->backend->setStore(this);

      ...
   \endcode

   \section2 Initializing the store

   Upon going to the store page in the demo, InAppStore connects all signals to related slots in
   setupBackend() function. Then uses the registerProduct() function to register product ID and
   productType of each product registered in the external store to a QHash registeredProducts.

   Registering a product is asynchronous, and will at some point yield productRegistered()
   signals when its found from external store.

   \code
   void InAppStore::registerProduct(InAppProduct *product)
   {
      d->registeredProducts[product->identifier()] = product;
      emit productRegistered(product);
   }
   \endcode

   \section2 Completing a purchase

   Once the items have been successfully registered in the store, The user can purchase them by
   pressing on of the products on the apps store page. QML will call product.purchase()
   function in AndroidInAppProduct or \c IosInAppProduct which will open the external store's
   purchasing flow.

   When a purchase has been completed regardless of success, the transactionRedy signal will be
   sent to \c InAppProductQmlType, to notify QML to start finalize the transaction.

   \section2 Restoring purchases

   In the demo unlockable purchases will be saved on the apps storage. By clearing the storage
   the user will lose the unlockable purchase and it cannot be purchased again, as according to
   the external store it is already owned.

   You can use the  \c{restore purchases} button in the apps store page to restore your unlockable purchases.
   The restore purchases button calls the restorePurchases() function and will check the external store for already owned
   purchases. It emits the transactionRedy() signal to finalize and restore the purchase.

   InAppStore has no derived classes.

   \section1 InAppTransaction

   InAppTransaction contains information about a transaction in the external app store and is
   usually provided as a result of calling InAppProduct::purchase(). When the purchase flow has
   been completed by the user (confirming the purchase, for instance by entering their password),
   the InAppStore instance containing the product will emit a InAppStore::transactionReady()
   signal with data about the transaction.

   The status() function provides information on if the transaction was successful or not. If it was
   successful, then the application should take appropriate action. When the necessary action has
   been performed, finalize() should be called. The finalize() function should be called regardless
   of the status of the transaction.

   Check out the derived classes \c{AndroidInAppTransaction} for android and \c{IosInAppTransaction} for iOS.

   \section1 InAppPurchaseBackend

   \c InAppPurchaseBackend is used to create derived class for
   \c AndroidInAppPurchaseBackend and \c IosInAppPurchaseBackend.
*/