Search in sources :

Example 1 with EmptyResponse

use of org.whispersystems.signalservice.internal.EmptyResponse in project Signal-Android by WhisperSystems.

the class SubscriptionKeepAliveJob method onRun.

@Override
protected void onRun() throws Exception {
    Subscriber subscriber = SignalStore.donationsValues().getSubscriber();
    if (subscriber == null) {
        return;
    }
    ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().putSubscription(subscriber.getSubscriberId()).blockingGet();
    verifyResponse(response);
    Log.i(TAG, "Successful call to PUT subscription ID", true);
    ServiceResponse<ActiveSubscription> activeSubscriptionResponse = ApplicationDependencies.getDonationsService().getSubscription(subscriber.getSubscriberId()).blockingGet();
    verifyResponse(activeSubscriptionResponse);
    Log.i(TAG, "Successful call to GET active subscription", true);
    ActiveSubscription activeSubscription = activeSubscriptionResponse.getResult().get();
    if (activeSubscription.getActiveSubscription() == null || !activeSubscription.getActiveSubscription().isActive()) {
        Log.i(TAG, "User does not have an active subscription. Exiting.", true);
        return;
    }
    if (activeSubscription.getActiveSubscription().getEndOfCurrentPeriod() > SignalStore.donationsValues().getLastEndOfPeriod()) {
        Log.i(TAG, String.format(Locale.US, "Last end of period change. Requesting receipt refresh. (old: %d to new: %d)", SignalStore.donationsValues().getLastEndOfPeriod(), activeSubscription.getActiveSubscription().getEndOfCurrentPeriod()), true);
        SubscriptionReceiptRequestResponseJob.createSubscriptionContinuationJobChain(true).enqueue();
    }
}
Also used : ActiveSubscription(org.whispersystems.signalservice.api.subscriptions.ActiveSubscription) Subscriber(org.thoughtcrime.securesms.subscription.Subscriber) EmptyResponse(org.whispersystems.signalservice.internal.EmptyResponse)

Example 2 with EmptyResponse

use of org.whispersystems.signalservice.internal.EmptyResponse in project Signal-Android by WhisperSystems.

the class DonationReceiptRedemptionJob method onRun.

@Override
protected void onRun() throws Exception {
    Data inputData = getInputData();
    if (inputData == null) {
        Log.w(TAG, "No input data. Exiting.", null, true);
        return;
    }
    byte[] presentationBytes = inputData.getStringAsBlob(INPUT_RECEIPT_CREDENTIAL_PRESENTATION);
    if (presentationBytes == null) {
        Log.d(TAG, "No response data. Exiting.", null, true);
        return;
    }
    ReceiptCredentialPresentation presentation = new ReceiptCredentialPresentation(presentationBytes);
    Log.d(TAG, "Attempting to redeem token... isForSubscription: " + isForSubscription(), true);
    ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().redeemReceipt(presentation, SignalStore.donationsValues().getDisplayBadgesOnProfile(), false).blockingGet();
    if (response.getApplicationError().isPresent()) {
        if (response.getStatus() >= 500) {
            Log.w(TAG, "Encountered a server exception " + response.getStatus(), response.getApplicationError().get(), true);
            throw new RetryableException();
        } else {
            Log.w(TAG, "Encountered a non-recoverable exception " + response.getStatus(), response.getApplicationError().get(), true);
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(errorSource));
            throw new IOException(response.getApplicationError().get());
        }
    } else if (response.getExecutionError().isPresent()) {
        Log.w(TAG, "Encountered a retryable exception", response.getExecutionError().get(), true);
        throw new RetryableException();
    }
    Log.i(TAG, "Successfully redeemed token with response code " + response.getStatus() + "... isForSubscription: " + isForSubscription(), true);
    if (isForSubscription()) {
        Log.d(TAG, "Clearing subscription failure", true);
        SignalStore.donationsValues().clearSubscriptionRedemptionFailed();
    }
}
Also used : ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) Data(org.thoughtcrime.securesms.jobmanager.Data) IOException(java.io.IOException) EmptyResponse(org.whispersystems.signalservice.internal.EmptyResponse)

Example 3 with EmptyResponse

use of org.whispersystems.signalservice.internal.EmptyResponse in project Signal-Android by signalapp.

the class SubscriptionKeepAliveJob method onRun.

@Override
protected void onRun() throws Exception {
    Subscriber subscriber = SignalStore.donationsValues().getSubscriber();
    if (subscriber == null) {
        return;
    }
    ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().putSubscription(subscriber.getSubscriberId()).blockingGet();
    verifyResponse(response);
    Log.i(TAG, "Successful call to PUT subscription ID", true);
    ServiceResponse<ActiveSubscription> activeSubscriptionResponse = ApplicationDependencies.getDonationsService().getSubscription(subscriber.getSubscriberId()).blockingGet();
    verifyResponse(activeSubscriptionResponse);
    Log.i(TAG, "Successful call to GET active subscription", true);
    ActiveSubscription activeSubscription = activeSubscriptionResponse.getResult().get();
    if (activeSubscription.getActiveSubscription() == null || !activeSubscription.getActiveSubscription().isActive()) {
        Log.i(TAG, "User does not have an active subscription. Exiting.", true);
        return;
    }
    if (activeSubscription.getActiveSubscription().getEndOfCurrentPeriod() > SignalStore.donationsValues().getLastEndOfPeriod()) {
        Log.i(TAG, String.format(Locale.US, "Last end of period change. Requesting receipt refresh. (old: %d to new: %d)", SignalStore.donationsValues().getLastEndOfPeriod(), activeSubscription.getActiveSubscription().getEndOfCurrentPeriod()), true);
        SubscriptionReceiptRequestResponseJob.createSubscriptionContinuationJobChain(true).enqueue();
    }
}
Also used : ActiveSubscription(org.whispersystems.signalservice.api.subscriptions.ActiveSubscription) Subscriber(org.thoughtcrime.securesms.subscription.Subscriber) EmptyResponse(org.whispersystems.signalservice.internal.EmptyResponse)

Example 4 with EmptyResponse

use of org.whispersystems.signalservice.internal.EmptyResponse in project Signal-Android by signalapp.

the class DonationReceiptRedemptionJob method onRun.

@Override
protected void onRun() throws Exception {
    Data inputData = getInputData();
    if (inputData == null) {
        Log.w(TAG, "No input data. Exiting.", null, true);
        return;
    }
    byte[] presentationBytes = inputData.getStringAsBlob(INPUT_RECEIPT_CREDENTIAL_PRESENTATION);
    if (presentationBytes == null) {
        Log.d(TAG, "No response data. Exiting.", null, true);
        return;
    }
    ReceiptCredentialPresentation presentation = new ReceiptCredentialPresentation(presentationBytes);
    Log.d(TAG, "Attempting to redeem token... isForSubscription: " + isForSubscription(), true);
    ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().redeemReceipt(presentation, SignalStore.donationsValues().getDisplayBadgesOnProfile(), false).blockingGet();
    if (response.getApplicationError().isPresent()) {
        if (response.getStatus() >= 500) {
            Log.w(TAG, "Encountered a server exception " + response.getStatus(), response.getApplicationError().get(), true);
            throw new RetryableException();
        } else {
            Log.w(TAG, "Encountered a non-recoverable exception " + response.getStatus(), response.getApplicationError().get(), true);
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(errorSource));
            throw new IOException(response.getApplicationError().get());
        }
    } else if (response.getExecutionError().isPresent()) {
        Log.w(TAG, "Encountered a retryable exception", response.getExecutionError().get(), true);
        throw new RetryableException();
    }
    Log.i(TAG, "Successfully redeemed token with response code " + response.getStatus() + "... isForSubscription: " + isForSubscription(), true);
    if (isForSubscription()) {
        Log.d(TAG, "Clearing subscription failure", true);
        SignalStore.donationsValues().clearSubscriptionRedemptionFailed();
    }
}
Also used : ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) Data(org.thoughtcrime.securesms.jobmanager.Data) IOException(java.io.IOException) EmptyResponse(org.whispersystems.signalservice.internal.EmptyResponse)

Aggregations

EmptyResponse (org.whispersystems.signalservice.internal.EmptyResponse)4 IOException (java.io.IOException)2 ReceiptCredentialPresentation (org.signal.zkgroup.receipts.ReceiptCredentialPresentation)2 Data (org.thoughtcrime.securesms.jobmanager.Data)2 Subscriber (org.thoughtcrime.securesms.subscription.Subscriber)2 ActiveSubscription (org.whispersystems.signalservice.api.subscriptions.ActiveSubscription)2