Implement the majority of the Donor UI.

This commit is contained in:
Alex Hart
2021-10-12 15:55:54 -03:00
committed by GitHub
parent 6cbc2f684d
commit 43e4cba3d7
96 changed files with 3601 additions and 266 deletions

View File

@@ -6,8 +6,11 @@ import org.whispersystems.signalservice.api.util.CredentialsProvider;
import org.whispersystems.signalservice.internal.EmptyResponse;
import org.whispersystems.signalservice.internal.ServiceResponse;
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import org.whispersystems.signalservice.internal.push.DonationIntentResult;
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import java.io.IOException;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
@@ -45,4 +48,21 @@ public class DonationsService {
}
}).subscribeOn(Schedulers.io());
}
/**
* Submits price information to the server to generate a payment intent via the payment gateway.
*
* @param amount Price, in the minimum currency unit (e.g. cents or yen)
* @param currencyCode The currency code for the amount
* @return A ServiceResponse containing a DonationIntentResult with details given to us by the payment gateway.
*/
public Single<ServiceResponse<DonationIntentResult>> createDonationIntentWithAmount(String amount, String currencyCode) {
return Single.fromCallable(() -> {
try {
return ServiceResponse.forResult(this.pushServiceSocket.createDonationIntentWithAmount(amount, currencyCode), 200, null);
} catch (IOException e) {
return ServiceResponse.<DonationIntentResult>forUnknownError(e);
}
}).subscribeOn(Schedulers.io());
}
}

View File

@@ -0,0 +1,16 @@
package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
class DonationIntentPayload {
@JsonProperty
private long amount;
@JsonProperty
private String currency;
public DonationIntentPayload(long amount, String currency) {
this.amount = amount;
this.currency = currency;
}
}

View File

@@ -0,0 +1,24 @@
package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
public class DonationIntentResult {
@JsonProperty("id")
private String id;
@JsonProperty("client_secret")
private String clientSecret;
public DonationIntentResult(@JsonProperty("id") String id, @JsonProperty("client_secret") String clientSecret) {
this.id = id;
this.clientSecret = clientSecret;
}
public String getId() {
return id;
}
public String getClientSecret() {
return clientSecret;
}
}

View File

@@ -230,9 +230,11 @@ public class PushServiceSocket {
private static final String PAYMENTS_CONVERSIONS = "/v1/payments/conversions";
private static final String SUBMIT_RATE_LIMIT_CHALLENGE = "/v1/challenge";
private static final String REQUEST_RATE_LIMIT_PUSH_CHALLENGE = "/v1/challenge/push";
private static final String DONATION_INTENT = "/v1/donation/authorize-apple-pay";
private static final String DONATION_REDEEM_RECEIPT = "/v1/donation/redeem-receipt";
private static final String REPORT_SPAM = "/v1/messages/report/%s/%s";
@@ -869,6 +871,15 @@ public class PushServiceSocket {
makeServiceRequest(DONATION_REDEEM_RECEIPT, "PUT", payload);
}
/**
* @return The PaymentIntent id
*/
public DonationIntentResult createDonationIntentWithAmount(String amount, String currencyCode) throws IOException {
String payload = JsonUtil.toJson(new DonationIntentPayload(Long.parseLong(amount), currencyCode.toLowerCase(Locale.ROOT)));
String result = makeServiceRequest(DONATION_INTENT, "POST", payload);
return JsonUtil.fromJsonResponse(result, DonationIntentResult.class);
}
public List<ContactTokenDetails> retrieveDirectory(Set<String> contactTokens)
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
{