QInAppTransaction Class
Contains information about a transaction in the external app store. More...
Header: | #include <QInAppTransaction> |
Inherits: | QObject |
Public Types
enum | FailureReason { NoFailure, CanceledByUser, ErrorOccurred } |
enum | TransactionStatus { Unknown, PurchaseApproved, PurchaseFailed, PurchaseRestored } |
Properties
|
Public Functions
virtual QString | errorString() const |
virtual QInAppTransaction::FailureReason | failureReason() const |
virtual void | finalize() = 0 |
virtual QString | orderId() const |
virtual QString | platformProperty(const QString &propertyName) const |
QInAppProduct * | product() const |
QInAppTransaction::TransactionStatus | status() const |
virtual QDateTime | timestamp() const |
Detailed Description
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.
Member Type Documentation
enum QInAppTransaction::FailureReason
This enum type specifies the reason for failure if a transaction has the PurchaseFailed status.
Constant | Value | Description |
---|---|---|
QInAppTransaction::NoFailure | 0 | The status of the transaction is not PurchaseFailed. |
QInAppTransaction::CanceledByUser | 1 | The transaction was manually canceled by the user. |
QInAppTransaction::ErrorOccurred | 2 | An error occurred, preventing the transaction from completing. See the errorString property for more information on the precise error that occurred. |
enum QInAppTransaction::TransactionStatus
This enum type is used to specify the status of the transaction.
Constant | Value | Description |
---|---|---|
QInAppTransaction::Unknown | 0 | The transaction status has not been set. |
QInAppTransaction::PurchaseApproved | 1 | The purchase was successfully completed. |
QInAppTransaction::PurchaseFailed | 2 | 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. |
QInAppTransaction::PurchaseRestored | 3 | The product has previously been purchased and the purchase has now been restored as a result of calling QInAppStore::restorePurchases(). |
Property Documentation
errorString : const QString
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.
Access functions:
virtual QString | errorString() const |
See also failureReason and status.
failureReason : const FailureReason
This property holds the reason for the failure if the transaction's status is PurchaseFailed. If the purchase was canceled by the user, the failure reason will be CanceledByUser. If the purchase failed due to an error, it will be ErrorOccurred. If the purchase did not fail, the failure reason will be NoFailure.
Access functions:
virtual QInAppTransaction::FailureReason | failureReason() const |
See also errorString and status.
orderId : const QString
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).
Access functions:
virtual QString | orderId() const |
product : QInAppProduct* const
This property holds the product which is the object of this transaction.
Access functions:
QInAppProduct * | product() const |
status : const TransactionStatus
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.
Access functions:
QInAppTransaction::TransactionStatus | status() const |
timestamp : const QDateTime
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.
Access functions:
virtual QDateTime | timestamp() const |
See also orderId.
Member Function Documentation
[pure virtual]
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.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[virtual]
QString QInAppTransaction::platformProperty(const QString &propertyName) const
Returns the platform-specific property given by propertyName.
The following properties are available on Google Play:
- AndroidSignature: The signature of the transaction, as given by the private key for the application.
- AndroidPurchaseData: The purchase data returned by the Google Play store.
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().
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.