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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations