|
|
@@ -5,7 +5,9 @@ import android.os.Handler;
|
|
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
|
|
+import com.android.billingclient.api.AccountIdentifiers;
|
|
|
import com.android.billingclient.api.BillingClient;
|
|
|
+import com.android.billingclient.api.Purchase;
|
|
|
import com.atmob.app.lib.handler.RxHttpHandler;
|
|
|
import com.atmob.common.logging.AtmobLog;
|
|
|
import com.atmob.voiceai.data.api.AtmobApi;
|
|
|
@@ -14,18 +16,22 @@ import com.atmob.voiceai.data.api.request.BaseRequest;
|
|
|
import com.atmob.voiceai.data.api.request.OrderPayRequest;
|
|
|
import com.atmob.voiceai.data.api.request.OrderStatusRequest;
|
|
|
import com.atmob.voiceai.data.api.request.PayGoodsRequest;
|
|
|
+import com.atmob.voiceai.data.api.request.SubResumeRequest;
|
|
|
import com.atmob.voiceai.data.api.response.OrderPayResponse;
|
|
|
import com.atmob.voiceai.data.api.response.OrderStatusResponse;
|
|
|
import com.atmob.voiceai.data.api.response.PayGoodsResponse;
|
|
|
import com.atmob.voiceai.data.api.response.UserInfoResponse;
|
|
|
+import com.atmob.voiceai.sdk.billing.GPBillingClient;
|
|
|
import com.atmob.voiceai.utils.BoxingUtil;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
import atmob.reactivex.rxjava3.annotations.NonNull;
|
|
|
+import atmob.reactivex.rxjava3.core.Observable;
|
|
|
import atmob.reactivex.rxjava3.core.Single;
|
|
|
import atmob.reactivex.rxjava3.core.SingleObserver;
|
|
|
import atmob.reactivex.rxjava3.disposables.Disposable;
|
|
|
@@ -37,12 +43,14 @@ public class MemberRepository {
|
|
|
|
|
|
private final MutableLiveData<Boolean> isMember = new MutableLiveData<>();
|
|
|
private final AtmobApi atmobApi;
|
|
|
+ private final GPBillingClient gpBillingClient;
|
|
|
private boolean requestUserInfoDisabled;
|
|
|
private final Handler refreshMemberHandler = new Handler();
|
|
|
|
|
|
@Inject
|
|
|
- public MemberRepository(AtmobApi atmobApi) {
|
|
|
+ public MemberRepository(AtmobApi atmobApi, GPBillingClient gpBillingClient) {
|
|
|
this.atmobApi = atmobApi;
|
|
|
+ this.gpBillingClient = gpBillingClient;
|
|
|
refreshUserData();
|
|
|
}
|
|
|
|
|
|
@@ -51,8 +59,26 @@ public class MemberRepository {
|
|
|
return isMember;
|
|
|
}
|
|
|
|
|
|
+ public Single<Object> subscriptionResume() {
|
|
|
+ return gpBillingClient.queryPurchase(BillingClient.ProductType.SUBS)
|
|
|
+ .filter(purchases -> purchases != null && !purchases.isEmpty())
|
|
|
+ .toSingle()
|
|
|
+ .flatMap(purchases -> Observable.fromIterable(purchases)
|
|
|
+ .filter(purchase -> purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED)
|
|
|
+ .firstOrError()
|
|
|
+ .flatMap(purchase -> {
|
|
|
+ String googlePurchaseToken = purchase.getPurchaseToken();
|
|
|
+ return subscriptionResume(4, 1, googlePurchaseToken);
|
|
|
+ }))
|
|
|
+ .compose(RxJavaUtil.SingleSchedule.io2Main());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ private Single<Object> subscriptionResume(int payMethod, int payPlatform, String receiptData) {
|
|
|
+ return atmobApi.subscriptionResume(new SubResumeRequest(payMethod, payPlatform, receiptData))
|
|
|
+ .compose(RxHttpHandler.handle(true))
|
|
|
+ .compose(RxJavaUtil.SingleSchedule.io2Main());
|
|
|
+ }
|
|
|
|
|
|
public Single<PayGoodsResponse> payGoodsList() {
|
|
|
return atmobApi.payGoodsList(new PayGoodsRequest(false))
|