mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
PaymentSession: some bug fixes and new accessors.
This commit is contained in:
parent
ce61bd211d
commit
0a2f7268dc
@ -22,6 +22,7 @@ import com.google.bitcoin.script.ScriptBuilder;
|
||||
import com.google.bitcoin.uri.BitcoinURI;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
@ -226,26 +227,30 @@ public class PaymentSession {
|
||||
* Message returned by the merchant in response to a Payment message.
|
||||
*/
|
||||
public class Ack {
|
||||
private String memo = "";
|
||||
@Nullable private String memo;
|
||||
|
||||
Ack(String memo) {
|
||||
Ack(@Nullable String memo) {
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the memo included by the merchant in the payment ack. This message is typically displayed to the user
|
||||
* as a notification (e.g. "Your payment was received and is being processed").
|
||||
* as a notification (e.g. "Your payment was received and is being processed"). If none was provided, returns
|
||||
* null.
|
||||
*/
|
||||
public String getMemo() {
|
||||
@Nullable public String getMemo() {
|
||||
return memo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the memo included by the merchant in the payment request.
|
||||
* Returns the memo included by the merchant in the payment request, or null if not found.
|
||||
*/
|
||||
public String getMemo() {
|
||||
return paymentDetails.getMemo();
|
||||
@Nullable public String getMemo() {
|
||||
if (paymentDetails.hasMemo())
|
||||
return paymentDetails.getMemo();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -373,7 +378,7 @@ public class PaymentSession {
|
||||
InputStream inStream = connection.getInputStream();
|
||||
Protos.PaymentACK.Builder paymentAckBuilder = Protos.PaymentACK.newBuilder().mergeFrom(inStream);
|
||||
Protos.PaymentACK paymentAck = paymentAckBuilder.build();
|
||||
String memo = "";
|
||||
String memo = null;
|
||||
if (paymentAck.hasMemo())
|
||||
memo = paymentAck.getMemo();
|
||||
return new Ack(memo);
|
||||
@ -420,8 +425,8 @@ public class PaymentSession {
|
||||
else if (pair.getType().equals(RFC4519Style.c))
|
||||
country = val;
|
||||
}
|
||||
if (org != null && location != null && country != null) {
|
||||
return org + ", " + location + ", " + country;
|
||||
if (org != null) {
|
||||
return Joiner.on(", ").skipNulls().join(org, location, country);
|
||||
} else {
|
||||
if (commonName == null)
|
||||
throw new PaymentRequestException.PkiVerificationException("Could not find any identity info for root CA");
|
||||
@ -616,10 +621,20 @@ public class PaymentSession {
|
||||
}
|
||||
// This won't ever happen in practice. It would only happen if the user provided outputs
|
||||
// that are obviously invalid. Still, we don't want to silently overflow.
|
||||
if (totalValue.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0)
|
||||
if (totalValue.compareTo(NetworkParameters.MAX_MONEY) > 0)
|
||||
throw new PaymentRequestException.InvalidOutputs("The outputs are way too big.");
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new PaymentRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the protobuf that this object was instantiated with. */
|
||||
public Protos.PaymentRequest getPaymentRequest() {
|
||||
return paymentRequest;
|
||||
}
|
||||
|
||||
/** Returns the protobuf that describes the payment to be made. */
|
||||
public Protos.PaymentDetails getPaymentDetails() {
|
||||
return paymentDetails;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user