mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
IAP fixes
This commit is contained in:
parent
19b194a1b2
commit
b5b6c23b74
4 changed files with 39 additions and 31 deletions
|
|
@ -2,8 +2,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.habitrpg.android.habitica"
|
||||
android:versionCode="93"
|
||||
android:versionName="0.0.31.0"
|
||||
android:versionCode="97"
|
||||
android:versionName="0.0.31.1"
|
||||
android:screenOrientation="portrait"
|
||||
android:installLocation="auto" >
|
||||
|
||||
|
|
|
|||
|
|
@ -288,17 +288,7 @@ public class APIHelper implements Action1<Throwable> {
|
|||
this.showConnectionProblemDialog(R.string.network_error_no_network_body);
|
||||
} else if (throwableClass.equals(HttpException.class)) {
|
||||
HttpException error = (HttpException) throwable;
|
||||
retrofit2.Response<?> response = error.response();
|
||||
ErrorResponse res = null;
|
||||
|
||||
Converter<ResponseBody, ?> errorConverter =
|
||||
gsonConverter
|
||||
.responseBodyConverter(ErrorResponse.class, new Annotation[0], retrofitAdapter);
|
||||
try {
|
||||
res = (ErrorResponse) errorConverter.convert(response.errorBody());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ErrorResponse res = getErrorResponse(error);
|
||||
|
||||
int status = error.code();
|
||||
if (status >= 400 && status < 500) {
|
||||
|
|
@ -318,6 +308,18 @@ public class APIHelper implements Action1<Throwable> {
|
|||
}
|
||||
}
|
||||
|
||||
public ErrorResponse getErrorResponse(HttpException error) {
|
||||
retrofit2.Response<?> response = error.response();
|
||||
Converter<ResponseBody, ?> errorConverter =
|
||||
gsonConverter
|
||||
.responseBodyConverter(ErrorResponse.class, new Annotation[0], retrofitAdapter);
|
||||
try {
|
||||
return (ErrorResponse) errorConverter.convert(response.errorBody());
|
||||
} catch (IOException e) {
|
||||
return new ErrorResponse();
|
||||
}
|
||||
}
|
||||
|
||||
public Observable<HabitRPGUser> retrieveUser(boolean withTasks) {
|
||||
Observable<HabitRPGUser> userObservable = apiService.getUser();
|
||||
if (withTasks) {
|
||||
|
|
@ -382,11 +384,6 @@ public class APIHelper implements Action1<Throwable> {
|
|||
});
|
||||
}
|
||||
|
||||
public PurchaseValidationResult validatePurchase(PurchaseValidationRequest request) throws IOException {
|
||||
Call<PurchaseValidationResult> response = apiService.validatePurchase(request);
|
||||
return response.execute().body();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Observable.Transformer<T, T> configureApiCallObserver() {
|
||||
return (Observable.Transformer<T, T>) apiCallTransformer;
|
||||
|
|
@ -400,7 +397,7 @@ public class APIHelper implements Action1<Throwable> {
|
|||
Amplitude.getInstance().setUserId(this.hostConfig.getUser());
|
||||
}
|
||||
|
||||
public class ErrorResponse {
|
||||
public static class ErrorResponse {
|
||||
public String message;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
|
||||
/**
|
||||
* Created by Negue on 26.11.2015.
|
||||
*/
|
||||
|
|
@ -52,20 +54,29 @@ public class HabiticaPurchaseVerifier extends BasePurchaseVerifier {
|
|||
validationRequest.transaction.receipt = purchase.data;
|
||||
validationRequest.transaction.signature = purchase.signature;
|
||||
|
||||
try {
|
||||
PurchaseValidationResult purchaseValidationResult = apiHelper.validatePurchase(validationRequest);
|
||||
if (purchaseValidationResult.ok) {
|
||||
purchasedOrderList.add(purchase.orderId);
|
||||
apiHelper.apiService.validatePurchase(validationRequest).subscribe(purchaseValidationResult -> {
|
||||
purchasedOrderList.add(purchase.orderId);
|
||||
|
||||
verifiedPurchases.add(purchase);
|
||||
verifiedPurchases.add(purchase);
|
||||
|
||||
requestListener.onSuccess(verifiedPurchases);
|
||||
} else {
|
||||
requestListener.onError(purchases.indexOf(purchase), new Exception(purchaseValidationResult.data.toString()));
|
||||
requestListener.onSuccess(verifiedPurchases);
|
||||
}, throwable -> {
|
||||
if (throwable.getClass().equals(HttpException.class)) {
|
||||
HttpException error = (HttpException)throwable;
|
||||
APIHelper.ErrorResponse res = apiHelper.getErrorResponse((HttpException) throwable);
|
||||
if (error.code() == 401) {
|
||||
if (res.message.equals("RECEIPT_ALREADY_USED")) {
|
||||
purchasedOrderList.add(purchase.orderId);
|
||||
|
||||
verifiedPurchases.add(purchase);
|
||||
|
||||
requestListener.onSuccess(verifiedPurchases);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
requestListener.onError(purchases.indexOf(purchase), new Exception());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ public interface ApiService {
|
|||
Observable<Void> leaveQuest(@Path("gid") String groupId);
|
||||
|
||||
@POST("/iap/android/verify")
|
||||
Call<PurchaseValidationResult> validatePurchase(@Body PurchaseValidationRequest request);
|
||||
Observable<PurchaseValidationResult> validatePurchase(@Body PurchaseValidationRequest request);
|
||||
|
||||
//Members URL
|
||||
@POST("members/send-private-message")
|
||||
|
|
|
|||
Loading…
Reference in a new issue