public class PaymentSession extends 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
objectProtos.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.
sendPayment 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.Modifier and Type | Class and Description |
---|---|
class |
PaymentSession.Ack
Message returned by the merchant in response to a Payment message.
|
static class |
PaymentSession.PkiVerificationData
Information about the X509 signature's issuer and subject.
|
Modifier and Type | Field and Description |
---|---|
PaymentSession.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,
String trustStorePath)
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,
String trustStorePath)
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(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(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(String url,
boolean verifyPki,
String trustStorePath)
Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
|
Date |
getDate()
Returns the date that the payment request was generated.
|
String |
getMemo()
Returns the memo included by the merchant in the payment request, or null if not found.
|
Protos.Payment |
getPayment(List<Transaction> txns,
Address refundAddr,
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.
|
String |
getPaymentUrl()
Returns the payment url where the Payment message should be sent.
|
Wallet.SendRequest |
getSendRequest()
Returns a
Wallet.SendRequest suitable for broadcasting to the network. |
BigInteger |
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<PaymentSession.Ack> |
sendPayment(List<Transaction> txns,
Address refundAddr,
String memo)
Generates a Payment message and sends the payment to the merchant who sent the PaymentRequest.
|
protected com.google.common.util.concurrent.ListenableFuture<PaymentSession.Ack> |
sendPayment(URL url,
Protos.Payment payment) |
PaymentSession.PkiVerificationData |
verifyPki()
Uses the provided PKI method to find the corresponding public key and verify the provided signature.
|
public PaymentSession.PkiVerificationData pkiVerificationData
public PaymentSession(Protos.PaymentRequest request) throws PaymentRequestException
Protos.PaymentRequest
.
Verifies PKI by default.PaymentRequestException
public PaymentSession(Protos.PaymentRequest request, boolean verifyPki) throws PaymentRequestException
Protos.PaymentRequest
.
If verifyPki is true, also validates the signature and throws an exception if it fails.PaymentRequestException
public PaymentSession(Protos.PaymentRequest request, boolean verifyPki, @Nullable String trustStorePath) throws PaymentRequestException
Protos.PaymentRequest
.
If verifyPki is true, also validates the signature and throws an exception if it fails.
If trustStorePath is not null, the trust store used for PKI verification will be loaded from the given location
instead of using the system default trust store location.PaymentRequestException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromBitcoinUri(BitcoinURI uri) throws PaymentRequestException
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.PaymentRequestException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromBitcoinUri(BitcoinURI uri, boolean verifyPki) throws PaymentRequestException
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.PaymentRequestException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromBitcoinUri(BitcoinURI uri, boolean verifyPki, @Nullable String trustStorePath) throws PaymentRequestException
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 trustStorePath is not null, the trust store used for PKI verification will be loaded from the given location
instead of using the system default trust store location.PaymentRequestException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromUrl(String url) throws PaymentRequestException
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.PaymentRequestException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromUrl(String url, boolean verifyPki) throws PaymentRequestException
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.PaymentRequestException
public static com.google.common.util.concurrent.ListenableFuture<PaymentSession> createFromUrl(String url, boolean verifyPki, @Nullable String trustStorePath) throws PaymentRequestException
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 trustStorePath is not null, the trust store used for PKI verification will be loaded from the given location
instead of using the system default trust store location.PaymentRequestException
@Nullable public String getMemo()
public BigInteger getValue()
public Date getDate()
public boolean isExpired()
@Nullable public String getPaymentUrl()
public Wallet.SendRequest getSendRequest()
Wallet.SendRequest
suitable for broadcasting to the network.@Nullable public com.google.common.util.concurrent.ListenableFuture<PaymentSession.Ack> sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo) throws PaymentRequestException, VerificationException, 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.PaymentRequestException
VerificationException
IOException
@Nullable public Protos.Payment getPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo) throws 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.IOException
protected com.google.common.util.concurrent.ListenableFuture<PaymentSession.Ack> sendPayment(URL url, Protos.Payment payment)
@Nullable public PaymentSession.PkiVerificationData verifyPki() throws PaymentRequestException
Protos.PaymentRequest
.PaymentRequestException
public Protos.PaymentRequest getPaymentRequest()
public Protos.PaymentDetails getPaymentDetails()
Copyright © 2014. All rights reserved.