Review fixes

This commit is contained in:
r.kuznetsov 2018-08-24 11:20:24 +03:00 committed by Daria Volvenkova
parent 6e572cb3ac
commit 32950ad239
4 changed files with 27 additions and 19 deletions

View file

@ -1741,13 +1741,13 @@ Java_com_mapswithme_maps_Framework_nativeMakeCrash(JNIEnv *env, jclass type)
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeValidateSubscription(JNIEnv * env, jclass,
jstring receiptData)
jstring purchaseToken)
{
auto const & subscription = frm()->GetSubscription();
if (subscription == nullptr)
return;
subscription->Validate(jni::ToNativeString(env, receiptData), frm()->GetUser().GetAccessToken());
subscription->Validate(jni::ToNativeString(env, purchaseToken), frm()->GetUser().GetAccessToken());
}
JNIEXPORT void JNICALL
@ -1773,9 +1773,7 @@ JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_Framework_nativeHasActiveSubscription(JNIEnv *, jclass)
{
auto const & subscription = frm()->GetSubscription();
if (subscription == nullptr)
return static_cast<jboolean>(false);
return static_cast<jboolean>(subscription->IsActive());
return subscription != nullptr ? static_cast<jboolean>(subscription->IsActive())
: static_cast<jboolean>(false);
}
} // extern "C"

View file

@ -104,11 +104,8 @@ public class Framework
@IntDef({ SUBSCRIPTION_ACTIVE, SUBSCRIPTION_NOT_ACTIVE, SUBSCRIPTION_VALIDATION_FAILURE })
public @interface SubscriptionValidationCode {}
// Subscription is active.
public static final int SUBSCRIPTION_ACTIVE = 0;
// Subscription is not active.
public static final int SUBSCRIPTION_NOT_ACTIVE = 1;
// Validation failed, real subscription status is unknown, current one acts.
public static final int SUBSCRIPTION_VALIDATION_FAILURE = 2;
@SuppressWarnings("unused")
@ -473,7 +470,7 @@ public class Framework
public static native void nativeMakeCrash();
public static native void nativeValidateSubscription(@NonNull String receiptData);
public static native void nativeValidateSubscription(@NonNull String purchaseToken);
public static native void nativeSetSubscriptionValidationListener(
@Nullable SubscriptionValidationListener listener);
public static native boolean nativeHasActiveSubscription();

View file

@ -47,29 +47,29 @@ std::string ValidationUrl()
struct ReceiptData
{
std::string m_data;
std::string m_type;
ReceiptData(std::string const & data, std::string const & type)
: m_data(data)
, m_type(type)
{}
std::string m_data;
std::string m_type;
DECLARE_VISITOR(visitor(m_data, "data"),
visitor(m_type, "type"))
};
struct ValidationData
{
std::string m_productId;
ReceiptData m_receipt;
ValidationData(std::string const & productId, std::string const & receiptData,
std::string const & receiptType)
: m_productId(productId)
, m_receipt(receiptData, receiptType)
{}
std::string m_productId;
ReceiptData m_receipt;
DECLARE_VISITOR(visitor(m_productId, "product_id"),
visitor(m_receipt, "receipt"))
};
@ -122,8 +122,20 @@ void Subscription::Validate(std::string const & receiptData, std::string const &
return;
}
// If we validate the subscription immediately after purchasing, we believe that
// the subscription is valid and apply it before the validation. If the result of
// validation will be different, we return everything back.
if (m_subscriptionId.empty() && !receiptData.empty())
{
m_isActive = true;
m_subscriptionId = GetSubscriptionId();
GetPlatform().GetSecureStorage().Save(kSubscriptionId, m_subscriptionId);
for (auto & listener : m_listeners)
listener->OnSubscriptionChanged(true /* isActive */);
}
auto const status = GetPlatform().ConnectionStatus();
if (status == Platform::EConnectionType::CONNECTION_NONE)
if (status == Platform::EConnectionType::CONNECTION_NONE || receiptData.empty())
{
ApplyValidation(ValidationCode::Failure);
return;
@ -154,8 +166,8 @@ void Subscription::Validate(std::string const & receiptData, std::string const &
{
ValidationResult result;
{
coding::DeserializerJson des(request.ServerResponse());
des(result);
coding::DeserializerJson deserializer(request.ServerResponse());
deserializer(result);
}
code = result.m_isValid ? ValidationCode::Active : ValidationCode::NotActive;

View file

@ -19,6 +19,7 @@ class Subscription
public:
enum class ValidationCode
{
// Do not change the order.
Active, // Subscription is active.
NotActive, // Subscription is not active.
Failure, // Validation failed, real subscription status is unknown, current one acts.