From f7c01a00854725cb47d5d0d52664393b47ddb8ec Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Mon, 13 Jul 2020 20:08:17 +0300 Subject: [PATCH] [purchase] trial flag for validation callback dummy. --- android/jni/com/mapswithme/maps/Framework.cpp | 12 ++++++------ android/src/com/mapswithme/maps/Framework.java | 3 ++- .../mapswithme/maps/PurchaseOperationObservable.java | 6 +++--- .../maps/purchase/CoreValidationObserver.java | 2 +- .../maps/purchase/DefaultPurchaseValidator.java | 3 ++- .../Core/InappPurchase/Impl/MWMPurchaseValidation.mm | 4 ++-- map/purchase.cpp | 9 +++++++-- map/purchase.hpp | 8 +++++++- 8 files changed, 30 insertions(+), 17 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 128779d22b..c02645d7d0 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -941,18 +941,18 @@ void CallSetRoutingLoadPointsListener(shared_ptr listener, bool success RoutingManager::LoadRouteHandler g_loadRouteHandler; void CallPurchaseValidationListener(shared_ptr 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(code), serverId.get(), vendorId.get(), - receiptData.get()); + receiptData.get(), static_cast(validationResponce.m_isTrial)); } void CallStartPurchaseTransactionListener(shared_ptr listener, bool success, diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index 177c612cf0..00f891a0ce 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -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") diff --git a/android/src/com/mapswithme/maps/PurchaseOperationObservable.java b/android/src/com/mapswithme/maps/PurchaseOperationObservable.java index ad65204049..c6c1f26d6b 100644 --- a/android/src/com/mapswithme/maps/PurchaseOperationObservable.java +++ b/android/src/com/mapswithme/maps/PurchaseOperationObservable.java @@ -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 */); } } diff --git a/android/src/com/mapswithme/maps/purchase/CoreValidationObserver.java b/android/src/com/mapswithme/maps/purchase/CoreValidationObserver.java index 5070eaeebd..6904f25c76 100644 --- a/android/src/com/mapswithme/maps/purchase/CoreValidationObserver.java +++ b/android/src/com/mapswithme/maps/purchase/CoreValidationObserver.java @@ -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); } diff --git a/android/src/com/mapswithme/maps/purchase/DefaultPurchaseValidator.java b/android/src/com/mapswithme/maps/purchase/DefaultPurchaseValidator.java index d6861a141e..55cbf5b561 100644 --- a/android/src/com/mapswithme/maps/purchase/DefaultPurchaseValidator.java +++ b/android/src/com/mapswithme/maps/purchase/DefaultPurchaseValidator.java @@ -70,7 +70,8 @@ class DefaultPurchaseValidator implements PurchaseValidator, @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); diff --git a/iphone/Maps/Core/InappPurchase/Impl/MWMPurchaseValidation.mm b/iphone/Maps/Core/InappPurchase/Impl/MWMPurchaseValidation.mm index 13ea7627c8..4dfb50a0d3 100644 --- a/iphone/Maps/Core/InappPurchase/Impl/MWMPurchaseValidation.mm +++ b/iphone/Maps/Core/InappPurchase/Impl/MWMPurchaseValidation.mm @@ -30,7 +30,7 @@ static NSMutableDictionary 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 *serverId = @(validationInfo.m_serverId.c_str()); + NSString *serverId = @(validationResponse.m_info.m_serverId.c_str()); NSMutableArray *callbackArray = callbacks[serverId]; [callbackArray enumerateObjectsUsingBlock:^(ValidatePurchaseCallback _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { obj(result); diff --git a/map/purchase.cpp b/map/purchase.cpp index 4af5f96dd4..68da0f5893 100644 --- a/map/purchase.cpp +++ b/map/purchase.cpp @@ -39,6 +39,11 @@ std::array(SubscriptionType::Count)> const kSub "_BookmarksSights" // bookmarks city }; +std::array(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 */}); } }); } diff --git a/map/purchase.hpp b/map/purchase.hpp index 490d63fc0a..8fc9dd94e0 100644 --- a/map/purchase.hpp +++ b/map/purchase.hpp @@ -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; - using ValidationCallback = std::function; + using ValidationCallback = std::function; using StartTransactionCallback = std::function; using TrialEligibilityCallback = std::function;