Fix inapps

This commit is contained in:
Alexey Kulish 2016-12-02 17:29:35 +02:00
parent fa1eff79cd
commit b5b718139b
2 changed files with 6 additions and 2 deletions

View file

@ -904,6 +904,7 @@ public class OsmandSettings {
public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none"; public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none";
public final OsmandPreference<String> BILLING_USER_ID = new StringPreference("billing_user_id", "").makeGlobal(); public final OsmandPreference<String> BILLING_USER_ID = new StringPreference("billing_user_id", "").makeGlobal();
public final OsmandPreference<String> BILLING_USER_TOKEN = new StringPreference("billing_user_token", "").makeGlobal();
public final OsmandPreference<String> BILLING_USER_NAME = new StringPreference("billing_user_name", "").makeGlobal(); public final OsmandPreference<String> BILLING_USER_NAME = new StringPreference("billing_user_name", "").makeGlobal();
public final OsmandPreference<String> BILLING_USER_EMAIL = new StringPreference("billing_user_email", "").makeGlobal(); public final OsmandPreference<String> BILLING_USER_EMAIL = new StringPreference("billing_user_email", "").makeGlobal();
public final OsmandPreference<String> BILLING_USER_COUNTRY = new StringPreference("billing_user_country", "").makeGlobal(); public final OsmandPreference<String> BILLING_USER_COUNTRY = new StringPreference("billing_user_country", "").makeGlobal();

View file

@ -231,7 +231,7 @@ public class InAppHelper {
boolean needSendToken = false; boolean needSendToken = false;
if (!isDeveloperVersion && liveUpdatesPurchase != null) { if (!isDeveloperVersion && liveUpdatesPurchase != null) {
OsmandSettings settings = ctx.getSettings(); OsmandSettings settings = ctx.getSettings();
if (Algorithms.isEmpty(settings.BILLING_USER_ID.get()) if ((Algorithms.isEmpty(settings.BILLING_USER_ID.get()) || Algorithms.isEmpty(settings.BILLING_USER_TOKEN.get()))
&& !Algorithms.isEmpty(liveUpdatesPurchase.getDeveloperPayload())) { && !Algorithms.isEmpty(liveUpdatesPurchase.getDeveloperPayload())) {
String payload = liveUpdatesPurchase.getDeveloperPayload(); String payload = liveUpdatesPurchase.getDeveloperPayload();
if (!Algorithms.isEmpty(payload)) { if (!Algorithms.isEmpty(payload)) {
@ -241,6 +241,7 @@ public class InAppHelper {
} }
if (arr.length > 1) { if (arr.length > 1) {
token = arr[1]; token = arr[1];
settings.BILLING_USER_TOKEN.set(token);
} }
} }
} }
@ -324,8 +325,9 @@ public class InAppHelper {
try { try {
JSONObject obj = new JSONObject(response); JSONObject obj = new JSONObject(response);
userId = obj.getString("userid"); userId = obj.getString("userid");
token = obj.getString("token");
ctx.getSettings().BILLING_USER_ID.set(userId); ctx.getSettings().BILLING_USER_ID.set(userId);
token = obj.getString("token");
ctx.getSettings().BILLING_USER_TOKEN.set(token);
logDebug("UserId=" + userId); logDebug("UserId=" + userId);
} catch (JSONException e) { } catch (JSONException e) {
String message = "JSON parsing error: " String message = "JSON parsing error: "
@ -432,6 +434,7 @@ public class InAppHelper {
private void sendToken(String purchaseToken, final OnRequestResultListener listener) { private void sendToken(String purchaseToken, final OnRequestResultListener listener) {
final String userId = ctx.getSettings().BILLING_USER_ID.get(); final String userId = ctx.getSettings().BILLING_USER_ID.get();
final String token = ctx.getSettings().BILLING_USER_TOKEN.get();
final String email = ctx.getSettings().BILLING_USER_EMAIL.get(); final String email = ctx.getSettings().BILLING_USER_EMAIL.get();
try { try {
Map<String, String> parameters = new HashMap<>(); Map<String, String> parameters = new HashMap<>();