/** * Returns the expires time of the payment request, or null if none. */ @Nullable public Date getExpires() { if (paymentDetails.hasExpires()) return new Date(paymentDetails.getExpires() * 1000); else return null; }
/** * Returns the outputs of the payment request. */ public List<PaymentProtocol.Output> getOutputs() { List<PaymentProtocol.Output> outputs = new ArrayList<PaymentProtocol.Output>(paymentDetails.getOutputsCount()); for (Protos.Output output : paymentDetails.getOutputsList()) { Coin amount = output.hasAmount() ? Coin.valueOf(output.getAmount()) : null; outputs.add(new PaymentProtocol.Output(amount, output.getScript().toByteArray())); } return outputs; }
public Builder mergeFrom(org.bitcoin.protocols.payments.Protos.PaymentDetails other) { if (other == org.bitcoin.protocols.payments.Protos.PaymentDetails.getDefaultInstance()) return this; if (other.hasNetwork()) { bitField0_ |= 0x00000001; network_ = other.network_; if (other.hasTime()) { setTime(other.getTime()); if (other.hasExpires()) { setExpires(other.getExpires()); if (other.hasMemo()) { bitField0_ |= 0x00000010; memo_ = other.memo_; onChanged(); if (other.hasPaymentUrl()) { bitField0_ |= 0x00000020; paymentUrl_ = other.paymentUrl_; onChanged(); if (other.hasMerchantData()) { setMerchantData(other.getMerchantData()); this.mergeUnknownFields(other.getUnknownFields()); return this;
public Builder mergeFrom(org.bitcoin.protocols.payments.Protos.PaymentDetails other) { if (other == org.bitcoin.protocols.payments.Protos.PaymentDetails.getDefaultInstance()) return this; if (other.hasNetwork()) { bitField0_ |= 0x00000001; network_ = other.network_; if (other.hasTime()) { setTime(other.getTime()); if (other.hasExpires()) { setExpires(other.getExpires()); if (other.hasMemo()) { bitField0_ |= 0x00000010; memo_ = other.memo_; onChanged(); if (other.hasPaymentUrl()) { bitField0_ |= 0x00000020; paymentUrl_ = other.paymentUrl_; onChanged(); if (other.hasMerchantData()) { setMerchantData(other.getMerchantData()); this.mergeUnknownFields(other.getUnknownFields()); return this;
public Builder mergeFrom(org.bitcoin.protocols.payments.Protos.PaymentDetails other) { if (other == org.bitcoin.protocols.payments.Protos.PaymentDetails.getDefaultInstance()) return this; if (other.hasNetwork()) { bitField0_ |= 0x00000001; network_ = other.network_; if (other.hasTime()) { setTime(other.getTime()); if (other.hasExpires()) { setExpires(other.getExpires()); if (other.hasMemo()) { bitField0_ |= 0x00000010; memo_ = other.memo_; onChanged(); if (other.hasPaymentUrl()) { bitField0_ |= 0x00000020; paymentUrl_ = other.paymentUrl_; onChanged(); if (other.hasMerchantData()) { setMerchantData(other.getMerchantData()); this.mergeUnknownFields(other.getUnknownFields()); return this;
public Builder mergeFrom(org.bitcoin.protocols.payments.Protos.PaymentDetails other) { if (other == org.bitcoin.protocols.payments.Protos.PaymentDetails.getDefaultInstance()) return this; if (other.hasNetwork()) { bitField0_ |= 0x00000001; network_ = other.network_; if (other.hasTime()) { setTime(other.getTime()); if (other.hasExpires()) { setExpires(other.getExpires()); if (other.hasMemo()) { bitField0_ |= 0x00000010; memo_ = other.memo_; onChanged(); if (other.hasPaymentUrl()) { bitField0_ |= 0x00000020; paymentUrl_ = other.paymentUrl_; onChanged(); if (other.hasMerchantData()) { setMerchantData(other.getMerchantData()); this.mergeUnknownFields(other.getUnknownFields()); return this;
public Builder mergeFrom(org.bitcoin.protocols.payments.Protos.PaymentDetails other) { if (other == org.bitcoin.protocols.payments.Protos.PaymentDetails.getDefaultInstance()) return this; if (other.hasNetwork()) { bitField0_ |= 0x00000001; network_ = other.network_; if (other.hasTime()) { setTime(other.getTime()); if (other.hasExpires()) { setExpires(other.getExpires()); if (other.hasMemo()) { bitField0_ |= 0x00000010; memo_ = other.memo_; onChanged(); if (other.hasPaymentUrl()) { bitField0_ |= 0x00000020; paymentUrl_ = other.paymentUrl_; onChanged(); if (other.hasMerchantData()) { setMerchantData(other.getMerchantData()); this.mergeUnknownFields(other.getUnknownFields()); return this;
if (!paymentDetails.hasPaymentUrl()) return null; if (!txns.get(0).getParams().equals(params)) throw new PaymentRequestException.InvalidNetwork(params.getPaymentProtocolId()); Protos.Payment.Builder payment = Protos.Payment.newBuilder(); if (paymentDetails.hasMerchantData()) payment.setMerchantData(paymentDetails.getMerchantData()); if (refundAddr != null) { Protos.Output.Builder refundOutput = Protos.Output.newBuilder();
if (!request.hasSerializedPaymentDetails()) throw new PaymentProtocolException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build(); if (paymentDetails == null) throw new PaymentProtocolException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentProtocolException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
if (!request.hasSerializedPaymentDetails()) throw new PaymentProtocolException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build(); if (paymentDetails == null) throw new PaymentProtocolException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentProtocolException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
if (!request.hasSerializedPaymentDetails()) throw new PaymentProtocolException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build(); if (paymentDetails == null) throw new PaymentProtocolException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentProtocolException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
if (!request.hasSerializedPaymentDetails()) throw new PaymentProtocolException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build(); if (paymentDetails == null) throw new PaymentProtocolException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentProtocolException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
if (!request.hasSerializedPaymentDetails()) throw new PaymentProtocolException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build(); if (paymentDetails == null) throw new PaymentProtocolException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentProtocolException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
if (!request.hasSerializedPaymentDetails()) throw new PaymentRequestException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build(); if (paymentDetails == null) throw new PaymentRequestException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentRequestException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentRequestException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(BigInteger.valueOf(output.getAmount()));
/** * Generates a Payment message and sends the payment to the merchant who sent the PaymentRequest. * Provide transactions built by the wallet. * NOTE: This does not broadcast the transactions to the bitcoin network, it merely sends a Payment message to the * merchant confirming the payment. * Returns an object wrapping PaymentACK once received. * If the PaymentRequest did not specify a payment_url, returns null and does nothing. * @param txns list of transactions to be included with the Payment message. * @param refundAddr will be used by the merchant to send money back if there was a problem. * @param memo is a message to include in the payment message sent to the merchant. */ @Nullable public ListenableFuture<PaymentProtocol.Ack> sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo) throws PaymentProtocolException, VerificationException, IOException { Protos.Payment payment = getPayment(txns, refundAddr, memo); if (payment == null) return null; if (isExpired()) throw new PaymentProtocolException.Expired("PaymentRequest is expired"); URL url; try { url = new URL(paymentDetails.getPaymentUrl()); } catch (MalformedURLException e) { throw new PaymentProtocolException.InvalidPaymentURL(e); } return sendPayment(url, payment); }
/** * Generates a Payment message and sends the payment to the merchant who sent the PaymentRequest. * Provide transactions built by the wallet. * NOTE: This does not broadcast the transactions to the bitcoin network, it merely sends a Payment message to the * merchant confirming the payment. * Returns an object wrapping PaymentACK once received. * If the PaymentRequest did not specify a payment_url, returns null and does nothing. * @param txns list of transactions to be included with the Payment message. * @param refundAddr will be used by the merchant to send money back if there was a problem. * @param memo is a message to include in the payment message sent to the merchant. */ public @Nullable ListenableFuture<Ack> sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo) throws PaymentRequestException, VerificationException, IOException { Protos.Payment payment = getPayment(txns, refundAddr, memo); if (payment == null) return null; if (isExpired()) throw new PaymentRequestException.Expired("PaymentRequest is expired"); URL url; try { url = new URL(paymentDetails.getPaymentUrl()); } catch (MalformedURLException e) { throw new PaymentRequestException.InvalidPaymentURL(e); } return sendPayment(url, payment); }
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; if (!hasTime()) { memoizedIsInitialized = 0; return false; } for (int i = 0; i < getOutputsCount(); i++) { if (!getOutputs(i).isInitialized()) { memoizedIsInitialized = 0; return false; } } memoizedIsInitialized = 1; return true; }
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; if (!hasTime()) { memoizedIsInitialized = 0; return false; } for (int i = 0; i < getOutputsCount(); i++) { if (!getOutputs(i).isInitialized()) { memoizedIsInitialized = 0; return false; } } memoizedIsInitialized = 1; return true; }
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; if (!hasTime()) { memoizedIsInitialized = 0; return false; } for (int i = 0; i < getOutputsCount(); i++) { if (!getOutputs(i).isInitialized()) { memoizedIsInitialized = 0; return false; } } memoizedIsInitialized = 1; return true; }