[purchase] trial flag for validation callback dummy.

This commit is contained in:
Arsentiy Milchakov 2020-07-13 20:08:17 +03:00 committed by Aleksandr Zatsepin
parent ffed8eb0c2
commit f7c01a0085
8 changed files with 30 additions and 17 deletions

View file

@ -941,18 +941,18 @@ void CallSetRoutingLoadPointsListener(shared_ptr<jobject> listener, bool success
RoutingManager::LoadRouteHandler g_loadRouteHandler;
void CallPurchaseValidationListener(shared_ptr<jobject> listener, Purchase::ValidationCode code,
Purchase::ValidationInfo const & validationInfo)
Purchase::ValidationResponse const & validationResponce)
{
JNIEnv * env = jni::GetEnv();
jmethodID const methodId = jni::GetMethodID(env, *listener, "onValidatePurchase",
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
jni::TScopedLocalRef const serverId(env, jni::ToJavaString(env, validationInfo.m_serverId));
jni::TScopedLocalRef const vendorId(env, jni::ToJavaString(env, validationInfo.m_vendorId));
jni::TScopedLocalRef const receiptData(env, jni::ToJavaString(env, validationInfo.m_receiptData));
jni::TScopedLocalRef const serverId(env, jni::ToJavaString(env, validationResponce.m_info.m_serverId));
jni::TScopedLocalRef const vendorId(env, jni::ToJavaString(env, validationResponce.m_info.m_vendorId));
jni::TScopedLocalRef const receiptData(env, jni::ToJavaString(env, validationResponce.m_info.m_receiptData));
env->CallVoidMethod(*listener, methodId, static_cast<jint>(code), serverId.get(), vendorId.get(),
receiptData.get());
receiptData.get(), static_cast<jboolean>(validationResponce.m_isTrial));
}
void CallStartPurchaseTransactionListener(shared_ptr<jobject> listener, bool success,

View file

@ -151,7 +151,8 @@ public class Framework
public interface PurchaseValidationListener
{
void onValidatePurchase(@PurchaseValidationCode int code, @NonNull String serverId,
@NonNull String vendorId, @NonNull String encodedPurchaseData);
@NonNull String vendorId, @NonNull String encodedPurchaseData,
boolean isTrial);
}
@SuppressWarnings("unused")

View file

@ -62,7 +62,7 @@ public class PurchaseOperationObservable implements Framework.PurchaseValidation
@Override
public void onValidatePurchase(int code, @NonNull String serverId, @NonNull String vendorId,
@NonNull String encodedPurchaseData)
@NonNull String encodedPurchaseData, boolean isTrial)
{
byte[] tokenBytes = Base64.decode(encodedPurchaseData, Base64.DEFAULT);
String purchaseData = new String(tokenBytes);
@ -76,7 +76,7 @@ public class PurchaseOperationObservable implements Framework.PurchaseValidation
return;
}
observer.onValidatePurchase(status, serverId, vendorId, purchaseData);
observer.onValidatePurchase(status, serverId, vendorId, purchaseData, isTrial);
}
@Override
@ -98,7 +98,7 @@ public class PurchaseOperationObservable implements Framework.PurchaseValidation
mLogger.d(TAG, "Post pending validation result to '" + observer + "' for '"
+ orderId + "'");
observer.onValidatePurchase(result.getStatus(), result.getServerId(), result.getVendorId(),
result.getPurchaseData());
result.getPurchaseData(), true /* Dummy */);
}
}

View file

@ -5,5 +5,5 @@ import androidx.annotation.NonNull;
public interface CoreValidationObserver
{
void onValidatePurchase(@NonNull ValidationStatus status, @NonNull String serverId,
@NonNull String vendorId, @NonNull String purchaseData);
@NonNull String vendorId, @NonNull String purchaseData, boolean isTrial);
}

View file

@ -70,7 +70,8 @@ class DefaultPurchaseValidator implements PurchaseValidator<ValidationCallback>,
@Override
public void onValidatePurchase(@NonNull ValidationStatus status, @NonNull String serverId,
@NonNull String vendorId, @NonNull String purchaseData)
@NonNull String vendorId, @NonNull String purchaseData,
boolean isTrial)
{
LOGGER.i(TAG, "Validation code: " + status);
String orderId = PurchaseUtils.parseOrderId(purchaseData);

View file

@ -30,7 +30,7 @@ static NSMutableDictionary<NSString *, NSMutableArray<ValidatePurchaseCallback>
return;
}
GetFramework().GetPurchase()->SetValidationCallback([](auto validationCode, auto const &validationInfo) {
GetFramework().GetPurchase()->SetValidationCallback([](auto validationCode, auto const &validationResponse) {
MWMPurchaseValidationResult result;
switch (validationCode) {
case Purchase::ValidationCode::Verified:
@ -48,7 +48,7 @@ static NSMutableDictionary<NSString *, NSMutableArray<ValidatePurchaseCallback>
}
}
NSString *serverId = @(validationInfo.m_serverId.c_str());
NSString *serverId = @(validationResponse.m_info.m_serverId.c_str());
NSMutableArray<ValidatePurchaseCallback> *callbackArray = callbacks[serverId];
[callbackArray enumerateObjectsUsingBlock:^(ValidatePurchaseCallback _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj(result);

View file

@ -39,6 +39,11 @@ std::array<std::string, static_cast<size_t>(SubscriptionType::Count)> const kSub
"_BookmarksSights" // bookmarks city
};
std::array<std::string, static_cast<size_t>(SubscriptionType::Count)> const kTrialSuffix =
{
"_BookmarksAllTrial", // removeAds (empty string for back compatibility)
};
uint32_t constexpr kFirstWaitingTimeInSec = 1;
uint32_t constexpr kWaitingTimeScaleFactor = 2;
uint8_t constexpr kMaxAttemptIndex = 2;
@ -196,7 +201,7 @@ void Purchase::Validate(ValidationInfo const & validationInfo, std::string const
if (url.empty() || status == Platform::EConnectionType::CONNECTION_NONE || !validationInfo.IsValid())
{
if (m_validationCallback)
m_validationCallback(ValidationCode::ServerError, validationInfo);
m_validationCallback(ValidationCode::ServerError, {validationInfo, true /* Dummy */});
return;
}
@ -349,7 +354,7 @@ void Purchase::ValidateImpl(std::string const & url, ValidationInfo const & vali
else
{
if (m_validationCallback)
m_validationCallback(code, validationInfo);
m_validationCallback(code, {validationInfo, true /* Dummy */});
}
});
}

View file

@ -47,6 +47,12 @@ public:
bool IsValid() const { return !m_vendorId.empty() && !m_receiptData.empty(); }
};
struct ValidationResponse
{
ValidationInfo m_info;
bool m_isTrial = false;
};
enum class TrialEligibilityCode
{
Eligible, // trial is eligible
@ -55,7 +61,7 @@ public:
};
using InvalidTokenHandler = std::function<void()>;
using ValidationCallback = std::function<void(ValidationCode, ValidationInfo const &)>;
using ValidationCallback = std::function<void(ValidationCode, ValidationResponse const &)>;
using StartTransactionCallback = std::function<void(bool success, std::string const & serverId,
std::string const & vendorId)>;
using TrialEligibilityCallback = std::function<void(TrialEligibilityCode)>;