summaryrefslogtreecommitdiffstats
path: root/src/purchasing/inapppurchase/qinapptransaction.cpp
blob: faa9103e83829113848db52da7e53be52483e217 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Purchasing module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3-COMM$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qinapptransaction.h"

QT_BEGIN_NAMESPACE

class QInAppTransactionPrivate
{
public:
    QInAppTransactionPrivate(QInAppTransaction::TransactionStatus s,
                             QInAppProduct *p)
        : status(s)
        , product(p)
    {
    }

    QInAppTransaction::TransactionStatus status;
    QInAppProduct *product;
};

/*!
    \qmltype Transaction
    \inqmlmodule QtPurchasing
    \since QtPurchasing 1.0
    \ingroup qtpurchasing
    \brief Contains information about an in-app transaction.

    Transaction contains information about a transaction in the external app store and is
    usually provided as a result of calling \l{QtPurchasing::Product::purchase()}{purchase()}
    on a product. When the purchase flow has ended, whether it's successful or not, either the
    product's \l{QtPurchasing::Product::onPurchaseSucceeded}{onPurchaseSucceeded} or
    \l{QtPurchasing::Product::onPurchaseFailed}{onPurchaseFailed} handler will be called
    with a transaction object as argument.

    Transaction cannot be created directly in QML, but is only provided as an argument to
    the purchase handlers in the products.
*/


/*!
  \class QInAppTransaction
  \inmodule QtPurchasing
  \brief Contains information about a transaction in the external app store.

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

  The status() provides information on whether 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.

  It is important that the application stores the purchase information before calling finalize().
  If a transaction is not finalized (for example because the application was interrupted before
  it had a chance to save the information), then the transaction will be emitted again the next
  time the product is registered by QInAppStore::registerProduct().

  Transactions can also be emitted after calling QInAppStore::restorePurchases(), at which point
  a new transaction will be emitted for each previously purchased unlockable product with the
  status of PurchaseRestored.

  \note Since transactions may under certain circumstances be emitted for the same transaction
  several times, the application should always check if the transaction has been registered
  before. Do not expect each transaction to be unique.
 */

/*!
 * \internal
 */\
QInAppTransaction::QInAppTransaction(TransactionStatus status,
                                     QInAppProduct *product,
                                     QObject *parent)
    : QObject(parent)
{
    d = QSharedPointer<QInAppTransactionPrivate>(new QInAppTransactionPrivate(status, product));
}

/*!
 * \internal
 */\
QInAppTransaction::~QInAppTransaction()
{
}

/*!
 * \qmlproperty object QtPurchasing::Transaction::product
 *
 * This property holds the product which is the object of this transaction.
 */

/*!
 * \property QInAppTransaction::product
 *
 * This property holds the product which is the object of this transaction.
 */
QInAppProduct *QInAppTransaction::product() const
{
    return d->product;
}

/*!
  \enum QInAppTransaction::TransactionStatus

  This enum type is used to specify the status of the transaction.

  \value Unknown The transaction status has not been set.
  \value PurchaseApproved The purchase was successfully completed.
  \value PurchaseFailed The purchase was not completed for some reason. This could be because
  the user canceled the transaction, but it could also for example be caused by a missing
  network connection.
  \value PurchaseRestored The product has previously been purchased and the purchase has
  now been restored as a result of calling \l{QInAppStore::restorePurchases()}.

*/

/*!
  \enum QInAppTransaction::FailureReason

  This enum type specifies the reason for failure if a transaction has the \l PurchaseFailed status.

  \value NoFailure The status of the transaction is not \l PurchaseFailed.
  \value CanceledByUser The transaction was manually canceled by the user.
  \value ErrorOccurred An error occurred, preventing the transaction from completing. See the \l errorString
  property for more information on the precise error that occurred.
*/

/*!
  \qmlproperty enum QtPurchasing::Transaction::status

  This property holds the status of the transaction.

  \list
  \li Transaction.PurchaseApproved The purchase was successfully completed.
  \li Transaction.PurchaseFailed The purchase was not completed for some reason. This could be because
  the user canceled the transaction, but it could also for example be caused by a missing
  network connection.
  \li PurchaseRestored The product has previously been purchased and the purchase has
  now been restored as a result of calling \l{QtPurchasing::Store::restorePurchases()}{restorePurchases()}.
  \endlist
 */

/*!
 * \property QInAppTransaction::status
 *
 * This property holds the status of the transaction. If the purchase was successfully
 * completed, the status will be PurchaseApproved. If the purchase failed
 * or was unsuccessful then the status will be PurchaseFailed. If the
 * transaction was restored as a result of calling QInAppStore::restorePurchases()
 * then the status will be PurchaseRestored.
 */

QInAppTransaction::TransactionStatus QInAppTransaction::status() const
{
    return d->status;
}

/*!
 * \qmlproperty enum QtPurchasing::Transaction::failureReason
 *
 * This property holds the reason for the failure if the transaction failed.
 *
 * \list
 * \li Transaction.NoFailure The transaction did not fail.
 * \li Transaction.CanceledByUser The transaction was canceled by the user.
 * \li Transaction.ErrorOccurred The transaction failed due to an error.
 * \endlist
 *
 * \sa errorString
 */

/*!
 * \property QInAppTransaction::failureReason
 *
 * This property holds the reason for the failure if the transaction's status is
 * \l{PurchaseFailed}. If the purchase was canceled by the user, the failure
 * reason will be \l{CanceledByUser}. If the purchase failed due to an error, it
 * will be \l{ErrorOccurred}. If the purchase did not fail, the failure reason
 * will be \l{NoFailure}.
 *
 * \sa errorString, status
 */
QInAppTransaction::FailureReason QInAppTransaction::failureReason() const
{
    return NoFailure;
}

/*!
 * \qmlproperty string QtPurchasing::Transaction::errorString
 *
 * This property holds a string describing the error if the transaction failed
 * due to an error. The contents of the error string is platform-specific.
 *
 * \sa failureReason, status
 */

/*!
 * \property QInAppTransaction::errorString
 *
 * This property holds a string describing the error if the transaction failed
 * due to an error. The contents of the error string is platform-specific.
 *
 * \sa failureReason, status
 */
QString QInAppTransaction::errorString() const
{
    return QString();
}

/*!
 * \qmlproperty time QtPurchasing::Transaction::timestamp
 *
 * This property holds the timestamp of the transaction. The timestamp
 * can be invalid if there is no valid transaction, for example if the user
 * canceled the purchase.
 *
 * \sa orderId
 */

/*!
 * \property QInAppTransaction::timestamp
 *
 * This property holds the timestamp of the transaction. The timestamp
 * can be invalid if there is no valid transaction, for example if the user
 * canceled the purchase.
 *
 * \sa orderId
 */
QDateTime QInAppTransaction::timestamp() const
{
    return QDateTime();
}

/*!
 * \qmlproperty string QtPurchasing::Transaction::orderId
 *
 * This property holds a unique identifier for this transaction. This value may be an empty
 * string if no transaction was registered (for example for canceled purchases).
 */

/*!
 * \property QInAppTransaction::orderId
 *
 * This property holds a unique identifier for this transaction. This value may be an empty
 * string if no transaction was registered (for example for canceled purchases).
 */
QString QInAppTransaction::orderId() const
{
    return QString();
}



/*!
 * Returns the platform-specific property given by \a propertyName.
 *
 * The following properties are available on Google Play:
 * \list
 * \li AndroidSignature: The signature of the transaction, as given by the
 *     private key for the application.
 * \li AndroidPurchaseData: The purchase data returned by the Google Play store.
 * \endlist
 * These properties can be used to verify the purchase using the public key of
 * your application. It is also possible to have the back-end verify the purchases
 * by passing in the public key before registering products, using
 * QInAppStore::setPlatformProperty().
 */
QString QInAppTransaction::platformProperty(const QString &propertyName) const
{
    Q_UNUSED(propertyName);
    return QString();
}

/*!
 * \fn void QInAppTransaction::finalize()
 *
 * Call this when the application has finished performing all necessary reactions
 * to the purchase. If the status is PurchaseApproved, the application should
 * store the information about the transaction in a safe way before finalizing it.
 * All transactions should be finalized.
 */

/*!
 * \qmlmethod void QtPurchasing::Transaction::finalize()
 *
 * Call this when the application has finished performing all necessary reactions
 * to the purchase. If the purchase succeeded, the application should store the
 * information about the transaction in a safe way before finalizing it.
 * All transactions should be finalized.
 */

QT_END_NAMESPACE