|
| 1 | +package com.braintreegateway; |
| 2 | + |
| 3 | +public class PartyRequest extends Request { |
| 4 | + private String accountReferenceNumber; |
| 5 | + private PartyAddressRequest address; |
| 6 | + private String firstName; |
| 7 | + private String lastName; |
| 8 | + private String taxId; |
| 9 | + private TransferRequest parent; |
| 10 | + private String tagName = "party"; |
| 11 | + |
| 12 | + public PartyRequest(TransferRequest parent, String tagName) { |
| 13 | + this.parent = parent; |
| 14 | + this.tagName = tagName; |
| 15 | + } |
| 16 | + |
| 17 | + public PartyRequest(TransferRequest parent) { |
| 18 | + this.parent = parent; |
| 19 | + } |
| 20 | + |
| 21 | + public PartyRequest accountReferenceNumber(String accountReferenceNumber) { |
| 22 | + this.accountReferenceNumber = accountReferenceNumber; |
| 23 | + return this; |
| 24 | + } |
| 25 | + |
| 26 | + public PartyAddressRequest address() { |
| 27 | + address = new PartyAddressRequest(this); |
| 28 | + return address; |
| 29 | + } |
| 30 | + |
| 31 | + public PartyRequest firstName(String firstName) { |
| 32 | + this.firstName = firstName; |
| 33 | + return this; |
| 34 | + } |
| 35 | + |
| 36 | + public PartyRequest lastName(String lastName) { |
| 37 | + this.lastName = lastName; |
| 38 | + return this; |
| 39 | + } |
| 40 | + |
| 41 | + public PartyRequest taxId(String taxId) { |
| 42 | + this.taxId = taxId; |
| 43 | + return this; |
| 44 | + } |
| 45 | + |
| 46 | + public TransferRequest done() { |
| 47 | + return parent; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public String toXML() { |
| 52 | + return buildRequest(tagName).toXML(); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public String toQueryString() { |
| 57 | + return toQueryString(tagName); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public String toQueryString(String root) { |
| 62 | + return buildRequest(root).toQueryString(); |
| 63 | + } |
| 64 | + |
| 65 | + protected RequestBuilder buildRequest(String root) { |
| 66 | + RequestBuilder builder = new RequestBuilder(root); |
| 67 | + if (accountReferenceNumber != null) { |
| 68 | + builder.addElement("accountReferenceNumber", accountReferenceNumber); |
| 69 | + } |
| 70 | + if (address != null) { |
| 71 | + builder.addElement("address", address); |
| 72 | + } |
| 73 | + if (firstName != null) { |
| 74 | + builder.addElement("firstName", firstName); |
| 75 | + } |
| 76 | + if (lastName != null) { |
| 77 | + builder.addElement("lastName", lastName); |
| 78 | + } |
| 79 | + if (taxId != null) { |
| 80 | + builder.addElement("taxId", taxId); |
| 81 | + } |
| 82 | + return builder; |
| 83 | + } |
| 84 | +} |
0 commit comments