RxIAPv3 icon indicating copy to clipboard operation
RxIAPv3 copied to clipboard

event handlers called by rx-methods

Open sergio11 opened this issue 8 years ago • 7 comments

Hi,

When I use the method billingProcessor.purchaseObservable the buying process is successful, but the observable does not emit anything. However the event handlers for no rx-methods are called.

Here I show the code snippet:

@Override
    public void onPurchase(final ContinentSubscription continent) {
        Timber.d("Id de la subscripción del continente: %s ", Utils.getSubscriptionIdFromContinentCode(continent.getCode()));
        billingProcessor.purchaseObservable(this, Utils.getSubscriptionIdFromContinentCode(continent.getCode())).doOnNext(new Action1<PurchaseModel>() {
            @Override
            public void call(PurchaseModel purchaseModel) {
                Timber.d("Purchase Model: %s", purchaseModel.toString());
                Toast.makeText(ContinentsActivity.this, "Purchase Model: " + purchaseModel.toString(), Toast.LENGTH_LONG);
                if (!purchaseModel.isSuccess())
                    throw new PurchaseFailException();
            }
        }).flatMap(new Func1<PurchaseModel, Observable<ConsumeModel>>() {
            @Override
            public Observable<ConsumeModel> call(PurchaseModel purchaseModel) {
                Timber.d("Consume Model: %s ", purchaseModel.toString());
                Toast.makeText(ContinentsActivity.this, "Consume Model: " + purchaseModel.toString(), Toast.LENGTH_LONG);
                return billingProcessor.consumePurchaseObservable(purchaseModel.getPurchaseDataModel().getProductId());
            }
        }).doOnNext(new Action1<ConsumeModel>() {
            @Override
            public void call(ConsumeModel consumeModel) {
                if (!consumeModel.isSuccess())
                    throw new ConsumeFailException();
            }
        })

the doOnNext responsible for checking the result of the process is never called. However the event handler onProductPurchased if it is called

@Override
    public void onProductPurchased(String productId, PurchaseDataModel purchaseDataModel) {
        Timber.d("onProductPurchased: %s, purchase datamodel: %s ", productId, purchaseDataModel.toString());
    }

I have followed the example of the repository

thanks.

sergio11 avatar Nov 09 '16 16:11 sergio11

So, what you mean is that consumePurchaseObservable does not return a value downstream?

pavlospt avatar Nov 09 '16 18:11 pavlospt

yes, billingProcessor.purchaseObservable does not return a value downstream.

sergio11 avatar Nov 09 '16 19:11 sergio11

Can you add a Subscriber and check if onError is called?

pavlospt avatar Nov 09 '16 19:11 pavlospt

The above was an excerpt. The full flow is quite broad but in the end I subscribe in this way:

.subscribe(new Action1<Boolean>() {
            @Override
            public void call(Boolean result) {
                hideLoadingDialog();
                onSubscriptionSuccess();
                reloadSubscriptions();
            }
        }, new CommonErrorHandler() {
            @Override
            public void onRetrofitException(JacksonApiError response) {
                int code = response != null ? response.getCode() : -1;
                hideLoadingDialog();
                onSubscriptionError(code);
            }

            @Override
            public void onOtherException(Throwable throwable) {
                hideLoadingDialog();
                onSubscriptionError(-1);
                Timber.d(throwable.getMessage());
            }
        });

No error occurs, onProductPurchased event handler is called.

sergio11 avatar Nov 09 '16 20:11 sergio11

I've taken a look to handle handleActivityResult on BillingProcessor and in this method only billing listener is notified. then I should not concatenate operations to purchaseObservable?

sergio11 avatar Nov 10 '16 11:11 sergio11

Probably yes, but it is being a long time since I wrote, will have to re-investigate why I did that. Maybe it is because this operation has to invoke startActivityForResult() internally and it can not use an Rx stream to notify back.

pavlospt avatar Nov 10 '16 11:11 pavlospt

facing the same issue right now. any plans?

chriswiesner avatar Dec 29 '17 08:12 chriswiesner