forked from organicmaps/organicmaps
[purchase] trial subscription dummies.
This commit is contained in:
parent
e747ce71cd
commit
26c7179aef
2 changed files with 46 additions and 8 deletions
|
@ -232,6 +232,33 @@ void Purchase::StartTransaction(std::string const & serverId, std::string const
|
|||
});
|
||||
}
|
||||
|
||||
void Purchase::SetTrialEligibilityCallback(TrialEligibilityCallback && callback)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
m_trialEligibilityCallback = std::move(callback);
|
||||
}
|
||||
|
||||
void Purchase::CheckTrialEligibility(ValidationInfo const & validationInfo)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
std::string const url = ValidationUrl();
|
||||
auto const status = GetPlatform().ConnectionStatus();
|
||||
if (url.empty() || status == Platform::EConnectionType::CONNECTION_NONE || !validationInfo.IsValid())
|
||||
{
|
||||
if (m_trialEligibilityCallback)
|
||||
m_trialEligibilityCallback(TrialEligibilityCode::ServerError);
|
||||
return;
|
||||
}
|
||||
|
||||
GetPlatform().RunTask(Platform::Thread::Network, [this, url, validationInfo]()
|
||||
{
|
||||
// Dummy, will be changed to http request when server will be done.
|
||||
if (m_trialEligibilityCallback)
|
||||
m_trialEligibilityCallback(TrialEligibilityCode::Eligible);
|
||||
});
|
||||
}
|
||||
|
||||
void Purchase::ValidateImpl(std::string const & url, ValidationInfo const & validationInfo,
|
||||
std::string const & accessToken, bool startTransaction,
|
||||
uint8_t attemptIndex, uint32_t waitingTimeInSeconds)
|
||||
|
|
|
@ -28,14 +28,6 @@ public:
|
|||
class Purchase
|
||||
{
|
||||
public:
|
||||
using InvalidTokenHandler = std::function<void()>;
|
||||
|
||||
explicit Purchase(InvalidTokenHandler && onInvalidToken);
|
||||
void RegisterSubscription(SubscriptionListener * listener);
|
||||
bool IsSubscriptionActive(SubscriptionType type) const;
|
||||
|
||||
void SetSubscriptionEnabled(SubscriptionType type, bool isEnabled);
|
||||
|
||||
enum class ValidationCode
|
||||
{
|
||||
// Do not change the order.
|
||||
|
@ -55,9 +47,24 @@ public:
|
|||
bool IsValid() const { return !m_vendorId.empty() && !m_receiptData.empty(); }
|
||||
};
|
||||
|
||||
enum class TrialEligibilityCode
|
||||
{
|
||||
Eligible, // trial is eligible
|
||||
NotEligible, // trial is not eligible
|
||||
ServerError, // server error during validation
|
||||
};
|
||||
|
||||
using InvalidTokenHandler = std::function<void()>;
|
||||
using ValidationCallback = std::function<void(ValidationCode, ValidationInfo const &)>;
|
||||
using StartTransactionCallback = std::function<void(bool success, std::string const & serverId,
|
||||
std::string const & vendorId)>;
|
||||
using TrialEligibilityCallback = std::function<void(TrialEligibilityCode)>;
|
||||
|
||||
explicit Purchase(InvalidTokenHandler && onInvalidToken);
|
||||
void RegisterSubscription(SubscriptionListener * listener);
|
||||
bool IsSubscriptionActive(SubscriptionType type) const;
|
||||
|
||||
void SetSubscriptionEnabled(SubscriptionType type, bool isEnabled);
|
||||
|
||||
void SetValidationCallback(ValidationCallback && callback);
|
||||
void Validate(ValidationInfo const & validationInfo, std::string const & accessToken);
|
||||
|
@ -66,6 +73,9 @@ public:
|
|||
void StartTransaction(std::string const & serverId, std::string const & vendorId,
|
||||
std::string const & accessToken);
|
||||
|
||||
void SetTrialEligibilityCallback(TrialEligibilityCallback && callback);
|
||||
void CheckTrialEligibility(ValidationInfo const & validationInfo);
|
||||
|
||||
private:
|
||||
void ValidateImpl(std::string const & url, ValidationInfo const & validationInfo,
|
||||
std::string const & accessToken, bool startTransaction,
|
||||
|
@ -89,6 +99,7 @@ private:
|
|||
ValidationCallback m_validationCallback;
|
||||
StartTransactionCallback m_startTransactionCallback;
|
||||
InvalidTokenHandler m_onInvalidToken;
|
||||
TrialEligibilityCallback m_trialEligibilityCallback;
|
||||
|
||||
ThreadChecker m_threadChecker;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue