QInAppTransaction Class

Contains information about a transaction in the external app store 更多...

头: #include <QInAppTransaction>
继承: QObject

公共类型

enum FailureReason { NoFailure, CanceledByUser, ErrorOccurred }
enum TransactionStatus { Unknown, PurchaseApproved, PurchaseFailed, PurchaseRestored }

特性

公共函数

virtual QString errorString () const
virtual FailureReason failureReason () const
virtual void finalize () = 0
virtual QString orderId () const
virtual QString platformProperty (const QString & propertyName ) const
QInAppProduct * product () const
TransactionStatus status () const
virtual QDateTime timestamp () const

额外继承成员

详细描述

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.

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 .

注意: 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.

成员类型文档编制

enum QInAppTransaction:: FailureReason

This enum type specifies the reason for failure if a transaction has the PurchaseFailed 状态。

常量 描述
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.

常量 描述
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 ().

特性文档编制

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.

访问函数:

virtual QString errorString () const

另请参阅 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 .

访问函数:

virtual FailureReason failureReason () const

另请参阅 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).

访问函数:

virtual QString orderId () const

product : QInAppProduct * const

This property holds the product which is the object of this transaction.

访问函数:

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 .

访问函数:

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.

访问函数:

virtual QDateTime timestamp () const

另请参阅 orderId .

成员函数文档编制

[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.

[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 ().