public class PaymentSession
extends java.lang.Object
Provides a standard implementation of the Payment Protocol (BIP 0070)
A PaymentSession can be initialized from one of the following:
BitcoinURI
object that conforms to BIP 0072Protos.PaymentRequest
can be fetchedProtos.PaymentRequest
objectIf initialized with a BitcoinURI or a url, a network request is made for the payment request object and a ListenableFuture is returned that will be notified with the PaymentSession object after it is downloaded.
Once the PaymentSession is initialized, typically a wallet application will prompt the user to confirm that the amount and recipient are correct, perform any additional steps, and then construct a list of transactions to pass to the sendPayment method.
Call sendPayment with a list of transactions that will be broadcast. A Protos.Payment
message will be sent
to the merchant if a payment url is provided in the PaymentRequest. NOTE: sendPayment does NOT broadcast the
transactions to the bitcoin network. Instead it returns a ListenableFuture that will be notified when a
Protos.PaymentACK
is received from the merchant. Typically a wallet will show the message to the user
as a confirmation message that the payment is now "processing" or that an error occurred, and then broadcast the
tx itself later if needed.
Modifier and Type | Field and Description |
---|---|
PaymentProtocol.PkiVerificationData |
pkiVerificationData
Stores the calculated PKI verification data, or null if none is available.
|
Constructor and Description |
---|
PaymentSession(Protos.PaymentRequest request)
Creates a PaymentSession from the provided
Protos.PaymentRequest . |
PaymentSession(Protos.PaymentRequest request,
boolean verifyPki)
Creates a PaymentSession from the provided
Protos.PaymentRequest . |
PaymentSession(Protos.PaymentRequest request,
boolean verifyPki,
TrustStoreLoader trustStoreLoader)
Creates a PaymentSession from the provided
Protos.PaymentRequest . |
Modifier and Type | Method and Description |
---|---|
static com.google.common.util.concurrent.ListenableFuture<PaymentSession> |
createFromBitcoinUri(BitcoinURI uri)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
|
static com.google.common.util.concurrent.ListenableFuture<PaymentSession> |
createFromBitcoinUri(BitcoinURI uri,
boolean verifyPki)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
|
static com.google.common.util.concurrent.ListenableFuture<PaymentSession> |
createFromBitcoinUri(BitcoinURI uri,
boolean verifyPki,
TrustStoreLoader trustStoreLoader)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
|
static com.google.common.util.concurrent.ListenableFuture<PaymentSession> |
createFromUrl(java.lang.String url)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
|
static com.google.common.util.concurrent.ListenableFuture<PaymentSession> |
createFromUrl(java.lang.String url,
boolean verifyPki)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
|
static com.google.common.util.concurrent.ListenableFuture<PaymentSession> |
createFromUrl(java.lang.String url,
boolean verifyPki,
TrustStoreLoader trustStoreLoader)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
|
java.util.Date |
getDate()
Returns the date that the payment request was generated.
|
java.util.Date |
getExpires()
Returns the expires time of the payment request, or null if none.
|
java.lang.String |
getMemo()
Returns the memo included by the merchant in the payment request, or null if not found.
|
byte[] |
getMerchantData()
Returns the merchant data included by the merchant in the payment request, or null if none.
|
NetworkParameters |
getNetworkParameters()
Gets the params as read from the PaymentRequest.network field: main is the default if missing.
|
java.util.List<PaymentProtocol.Output> |
getOutputs()
Returns the outputs of the payment request.
|
Protos.Payment |
getPayment(java.util.List<Transaction> txns,
Address refundAddr,
java.lang.String memo)
Generates a Payment message based on the information in the PaymentRequest.
|
Protos.PaymentDetails |
getPaymentDetails()
Returns the protobuf that describes the payment to be made.
|
Protos.PaymentRequest |
getPaymentRequest()
Returns the protobuf that this object was instantiated with.
|
java.lang.String |
getPaymentUrl()
Returns the payment url where the Payment message should be sent.
|
SendRequest |
getSendRequest()
Returns a
SendRequest suitable for broadcasting to the network. |
Coin |
getValue()
Returns the total amount of bitcoins requested.
|
boolean |
isExpired()
This should always be called before attempting to call sendPayment.
|
com.google.common.util.concurrent.ListenableFuture<PaymentProtocol.Ack> |
sendPayment(java.util.List<Transaction> txns,
Address refundAddr,
java.lang.String memo)
Generates a Payment message and sends the payment to the merchant who sent the PaymentRequest.
|
protected com.google.common.util.concurrent.ListenableFuture<PaymentProtocol.Ack> |
sendPayment(java.net.URL url,
Protos.Payment payment) |
PaymentProtocol.PkiVerificationData |
verifyPki()
Returns the value of pkiVerificationData or null if it wasn't verified at construction time.
|
@Nullable public final PaymentProtocol.PkiVerificationData pkiVerificationData
public PaymentSession(Protos.PaymentRequest request) throws PaymentProtocolException
Protos.PaymentRequest
.
Verifies PKI by default.PaymentProtocolException
public PaymentSession(Protos.PaymentRequest request, boolean verifyPki) throws PaymentProtocolException
Protos.PaymentRequest
.
If verifyPki is true, also validates the signature and throws an exception if it fails.PaymentProtocolException
public PaymentSession(Protos.PaymentRequest request, boolean verifyPki, @Nullable TrustStoreLoader trustStoreLoader) throws PaymentProtocolException
Protos.PaymentRequest
.
If verifyPki is true, also validates the signature and throws an exception if it fails.
If trustStoreLoader is null, the system default trust store is used.PaymentProtocolException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromBitcoinUri(BitcoinURI uri) throws PaymentProtocolException
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
uri is a BIP-72-style BitcoinURI object that specifies where the Protos.PaymentRequest
object may
be fetched in the r= parameter.
If the payment request object specifies a PKI method, then the system trust store will be used to verify the signature provided by the payment request. An exception is thrown by the future if the signature cannot be verified.
PaymentProtocolException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromBitcoinUri(BitcoinURI uri, boolean verifyPki) throws PaymentProtocolException
Protos.PaymentRequest
object may
be fetched in the r= parameter.
If verifyPki is specified and the payment request object specifies a PKI method, then the system trust store will
be used to verify the signature provided by the payment request. An exception is thrown by the future if the
signature cannot be verified.PaymentProtocolException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromBitcoinUri(BitcoinURI uri, boolean verifyPki, @Nullable TrustStoreLoader trustStoreLoader) throws PaymentProtocolException
Protos.PaymentRequest
object may
be fetched in the r= parameter.
If verifyPki is specified and the payment request object specifies a PKI method, then the system trust store will
be used to verify the signature provided by the payment request. An exception is thrown by the future if the
signature cannot be verified.
If trustStoreLoader is null, the system default trust store is used.PaymentProtocolException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromUrl(java.lang.String url) throws PaymentProtocolException
Protos.PaymentRequest
object may be fetched.
If verifyPki is specified and the payment request object specifies a PKI method, then the system trust store will
be used to verify the signature provided by the payment request. An exception is thrown by the future if the
signature cannot be verified.PaymentProtocolException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromUrl(java.lang.String url, boolean verifyPki) throws PaymentProtocolException
Protos.PaymentRequest
object may be fetched.
If the payment request object specifies a PKI method, then the system trust store will
be used to verify the signature provided by the payment request. An exception is thrown by the future if the
signature cannot be verified.PaymentProtocolException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromUrl(java.lang.String url, boolean verifyPki, @Nullable TrustStoreLoader trustStoreLoader) throws PaymentProtocolException
Protos.PaymentRequest
object may be fetched.
If the payment request object specifies a PKI method, then the system trust store will
be used to verify the signature provided by the payment request. An exception is thrown by the future if the
signature cannot be verified.
If trustStoreLoader is null, the system default trust store is used.PaymentProtocolException
public java.util.List<PaymentProtocol.Output> getOutputs()
@Nullable public java.lang.String getMemo()
public Coin getValue()
public java.util.Date getDate()
@Nullable public java.util.Date getExpires()
public boolean isExpired()
@Nullable public java.lang.String getPaymentUrl()
@Nullable public byte[] getMerchantData()
public SendRequest getSendRequest()
SendRequest
suitable for broadcasting to the network.@Nullable public com.google.common.util.concurrent.ListenableFuture<PaymentProtocol.Ack> sendPayment(java.util.List<Transaction> txns, @Nullable Address refundAddr, @Nullable java.lang.String memo) throws PaymentProtocolException, VerificationException, java.io.IOException
txns
- list of transactions to be included with the Payment message.refundAddr
- will be used by the merchant to send money back if there was a problem.memo
- is a message to include in the payment message sent to the merchant.PaymentProtocolException
VerificationException
java.io.IOException
@Nullable public Protos.Payment getPayment(java.util.List<Transaction> txns, @Nullable Address refundAddr, @Nullable java.lang.String memo) throws java.io.IOException, PaymentProtocolException.InvalidNetwork
txns
- list of transactions to be included with the Payment message.refundAddr
- will be used by the merchant to send money back if there was a problem.memo
- is a message to include in the payment message sent to the merchant.java.io.IOException
PaymentProtocolException.InvalidNetwork
protected com.google.common.util.concurrent.ListenableFuture<PaymentProtocol.Ack> sendPayment(java.net.URL url, Protos.Payment payment)
@Nullable public PaymentProtocol.PkiVerificationData verifyPki()
public NetworkParameters getNetworkParameters()
public Protos.PaymentRequest getPaymentRequest()
public Protos.PaymentDetails getPaymentDetails()