PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/buttonmanagersdk/src/main/java/urn/ebay/apis/eBLBaseComponents/PayerInfoType.java

https://gitlab.com/CORP-RESELLER/buttonmanager-sdk-java
Java | 395 lines | 234 code | 49 blank | 112 comment | 69 complexity | 3ed2ffa6e7eb4c47712ad0f47ff1e08e MD5 | raw file
  1. package urn.ebay.apis.eBLBaseComponents;
  2. import urn.ebay.apis.eBLBaseComponents.PayPalUserStatusCodeType;
  3. import urn.ebay.apis.eBLBaseComponents.PersonNameType;
  4. import urn.ebay.apis.eBLBaseComponents.CountryCodeType;
  5. import urn.ebay.apis.eBLBaseComponents.AddressType;
  6. import java.util.List;
  7. import java.util.ArrayList;
  8. import urn.ebay.apis.eBLBaseComponents.WalletItemsType;
  9. import urn.ebay.apis.eBLBaseComponents.TaxIdDetailsType;
  10. import urn.ebay.apis.EnhancedDataTypes.EnhancedPayerInfoType;
  11. import com.paypal.core.SDKUtil;
  12. import javax.xml.parsers.DocumentBuilder;
  13. import javax.xml.parsers.DocumentBuilderFactory;
  14. import javax.xml.parsers.ParserConfigurationException;
  15. import javax.xml.xpath.XPath;
  16. import javax.xml.xpath.XPathConstants;
  17. import javax.xml.xpath.XPathExpressionException;
  18. import javax.xml.xpath.XPathFactory;
  19. import org.w3c.dom.Document;
  20. import org.w3c.dom.Node;
  21. import org.w3c.dom.NodeList;
  22. import org.w3c.dom.NamedNodeMap;
  23. import java.io.FileInputStream;
  24. import java.io.StringReader;
  25. import java.io.IOException;
  26. import org.xml.sax.InputSource;
  27. import org.xml.sax.SAXException;
  28. /**
  29. * PayerInfoType Payer information
  30. */
  31. public class PayerInfoType{
  32. private static final String nameSpace="urn:ebay:apis:eBLBaseComponents";
  33. private static final String preferredPrefix="ebl";
  34. /**
  35. * Email address of payer Character length and limitations: 127
  36. * single-byte characters
  37. */
  38. private String payer;
  39. /**
  40. * Unique customer ID Character length and limitations: 17
  41. * single-byte characters
  42. */
  43. private String payerID;
  44. /**
  45. * Status of payer's email address
  46. */
  47. private PayPalUserStatusCodeType payerStatus;
  48. /**
  49. * Name of payer
  50. */
  51. private PersonNameType payerName;
  52. /**
  53. * Payment sender's country of residence using standard
  54. * two-character ISO 3166 country codes. Character length and
  55. * limitations: Two single-byte characters
  56. */
  57. private CountryCodeType payerCountry;
  58. /**
  59. * Payer's business name. Character length and limitations: 127
  60. * single-byte characters
  61. */
  62. private String payerBusiness;
  63. /**
  64. * Payer's business address
  65. */
  66. private AddressType address;
  67. /**
  68. * Business contact telephone number
  69. */
  70. private String contactPhone;
  71. /**
  72. * Items such as merchant coupons, loyalty cards, and
  73. * manufacturer coupons in the PayPal wallet.
  74. */
  75. private List<WalletItemsType> walletItems = new ArrayList<WalletItemsType>();
  76. /**
  77. * Details about payer's tax info. Refer to the
  78. * TaxIdDetailsType for more details.
  79. */
  80. private TaxIdDetailsType taxIdDetails;
  81. /**
  82. * Holds any enhanced information about the payer
  83. */
  84. private EnhancedPayerInfoType enhancedPayerInfo;
  85. /**
  86. * Default Constructor
  87. */
  88. public PayerInfoType (){
  89. }
  90. /**
  91. * Getter for payer
  92. */
  93. public String getPayer() {
  94. return payer;
  95. }
  96. /**
  97. * Setter for payer
  98. */
  99. public void setPayer(String payer) {
  100. this.payer = payer;
  101. }
  102. /**
  103. * Getter for payerID
  104. */
  105. public String getPayerID() {
  106. return payerID;
  107. }
  108. /**
  109. * Setter for payerID
  110. */
  111. public void setPayerID(String payerID) {
  112. this.payerID = payerID;
  113. }
  114. /**
  115. * Getter for payerStatus
  116. */
  117. public PayPalUserStatusCodeType getPayerStatus() {
  118. return payerStatus;
  119. }
  120. /**
  121. * Setter for payerStatus
  122. */
  123. public void setPayerStatus(PayPalUserStatusCodeType payerStatus) {
  124. this.payerStatus = payerStatus;
  125. }
  126. /**
  127. * Getter for payerName
  128. */
  129. public PersonNameType getPayerName() {
  130. return payerName;
  131. }
  132. /**
  133. * Setter for payerName
  134. */
  135. public void setPayerName(PersonNameType payerName) {
  136. this.payerName = payerName;
  137. }
  138. /**
  139. * Getter for payerCountry
  140. */
  141. public CountryCodeType getPayerCountry() {
  142. return payerCountry;
  143. }
  144. /**
  145. * Setter for payerCountry
  146. */
  147. public void setPayerCountry(CountryCodeType payerCountry) {
  148. this.payerCountry = payerCountry;
  149. }
  150. /**
  151. * Getter for payerBusiness
  152. */
  153. public String getPayerBusiness() {
  154. return payerBusiness;
  155. }
  156. /**
  157. * Setter for payerBusiness
  158. */
  159. public void setPayerBusiness(String payerBusiness) {
  160. this.payerBusiness = payerBusiness;
  161. }
  162. /**
  163. * Getter for address
  164. */
  165. public AddressType getAddress() {
  166. return address;
  167. }
  168. /**
  169. * Setter for address
  170. */
  171. public void setAddress(AddressType address) {
  172. this.address = address;
  173. }
  174. /**
  175. * Getter for contactPhone
  176. */
  177. public String getContactPhone() {
  178. return contactPhone;
  179. }
  180. /**
  181. * Setter for contactPhone
  182. */
  183. public void setContactPhone(String contactPhone) {
  184. this.contactPhone = contactPhone;
  185. }
  186. /**
  187. * Getter for walletItems
  188. */
  189. public List<WalletItemsType> getWalletItems() {
  190. return walletItems;
  191. }
  192. /**
  193. * Setter for walletItems
  194. */
  195. public void setWalletItems(List<WalletItemsType> walletItems) {
  196. this.walletItems = walletItems;
  197. }
  198. /**
  199. * Getter for taxIdDetails
  200. */
  201. public TaxIdDetailsType getTaxIdDetails() {
  202. return taxIdDetails;
  203. }
  204. /**
  205. * Setter for taxIdDetails
  206. */
  207. public void setTaxIdDetails(TaxIdDetailsType taxIdDetails) {
  208. this.taxIdDetails = taxIdDetails;
  209. }
  210. /**
  211. * Getter for enhancedPayerInfo
  212. */
  213. public EnhancedPayerInfoType getEnhancedPayerInfo() {
  214. return enhancedPayerInfo;
  215. }
  216. /**
  217. * Setter for enhancedPayerInfo
  218. */
  219. public void setEnhancedPayerInfo(EnhancedPayerInfoType enhancedPayerInfo) {
  220. this.enhancedPayerInfo = enhancedPayerInfo;
  221. }
  222. public String toXMLString(String prefix, String name) {
  223. StringBuilder sb = new StringBuilder();
  224. if(name!=null){
  225. if(prefix!=null){
  226. sb.append("<").append(prefix).append(":").append(name).append(">");
  227. }
  228. else{
  229. sb.append("<").append(preferredPrefix).append(":").append(name).append(">");
  230. }
  231. }
  232. if(payer != null) {
  233. sb.append("<").append(preferredPrefix).append(":Payer>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.payer));
  234. sb.append("</").append(preferredPrefix).append(":Payer>");
  235. }
  236. if(payerID != null) {
  237. sb.append("<").append(preferredPrefix).append(":PayerID>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.payerID));
  238. sb.append("</").append(preferredPrefix).append(":PayerID>");
  239. }
  240. if(payerStatus != null) {
  241. sb.append("<").append(preferredPrefix).append(":PayerStatus>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.payerStatus.getValue()));
  242. sb.append("</").append(preferredPrefix).append(":PayerStatus>");
  243. }
  244. if(payerName != null) {
  245. sb.append(payerName.toXMLString(preferredPrefix,"PayerName"));
  246. }
  247. if(payerCountry != null) {
  248. sb.append("<").append(preferredPrefix).append(":PayerCountry>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.payerCountry.getValue()));
  249. sb.append("</").append(preferredPrefix).append(":PayerCountry>");
  250. }
  251. if(payerBusiness != null) {
  252. sb.append("<").append(preferredPrefix).append(":PayerBusiness>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.payerBusiness));
  253. sb.append("</").append(preferredPrefix).append(":PayerBusiness>");
  254. }
  255. if(address != null) {
  256. sb.append(address.toXMLString(preferredPrefix,"Address"));
  257. }
  258. if(contactPhone != null) {
  259. sb.append("<").append(preferredPrefix).append(":ContactPhone>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.contactPhone));
  260. sb.append("</").append(preferredPrefix).append(":ContactPhone>");
  261. }
  262. if(walletItems != null) {
  263. for(int i=0; i < walletItems.size(); i++) {
  264. sb.append(walletItems.get(i).toXMLString(preferredPrefix,"WalletItems"));
  265. }
  266. }
  267. if(taxIdDetails != null) {
  268. sb.append(taxIdDetails.toXMLString(preferredPrefix,"TaxIdDetails"));
  269. }
  270. if(enhancedPayerInfo != null) {
  271. sb.append(enhancedPayerInfo.toXMLString(preferredPrefix,"EnhancedPayerInfo"));
  272. }
  273. if(name!=null){
  274. if(prefix!=null){
  275. sb.append("</").append(prefix).append(":").append(name).append(">");
  276. }
  277. else{
  278. sb.append("</").append(preferredPrefix).append(":").append(name).append(">");
  279. }
  280. }
  281. return sb.toString();
  282. }
  283. private boolean isWhitespaceNode(Node n) {
  284. if (n.getNodeType() == Node.TEXT_NODE) {
  285. String val = n.getNodeValue();
  286. return val.trim().length() == 0;
  287. } else if (n.getNodeType() == Node.ELEMENT_NODE ) {
  288. return (n.getChildNodes().getLength() == 0);
  289. } else {
  290. return false;
  291. }
  292. }
  293. public PayerInfoType(Node node) throws XPathExpressionException {
  294. XPathFactory factory = XPathFactory.newInstance();
  295. XPath xpath = factory.newXPath();
  296. Node childNode = null;
  297. NodeList nodeList = null;
  298. childNode = (Node) xpath.evaluate("Payer", node, XPathConstants.NODE);
  299. if (childNode != null && !isWhitespaceNode(childNode)) {
  300. this.payer = childNode.getTextContent();
  301. }
  302. childNode = (Node) xpath.evaluate("PayerID", node, XPathConstants.NODE);
  303. if (childNode != null && !isWhitespaceNode(childNode)) {
  304. this.payerID = childNode.getTextContent();
  305. }
  306. childNode = (Node) xpath.evaluate("PayerStatus", node, XPathConstants.NODE);
  307. if (childNode != null && !isWhitespaceNode(childNode)) {
  308. this.payerStatus = PayPalUserStatusCodeType.fromValue(childNode.getTextContent());
  309. }
  310. childNode = (Node) xpath.evaluate("PayerName", node, XPathConstants.NODE);
  311. if (childNode != null && !isWhitespaceNode(childNode)) {
  312. this.payerName = new PersonNameType(childNode);
  313. }
  314. childNode = (Node) xpath.evaluate("PayerCountry", node, XPathConstants.NODE);
  315. if (childNode != null && !isWhitespaceNode(childNode)) {
  316. this.payerCountry = CountryCodeType.fromValue(childNode.getTextContent());
  317. }
  318. childNode = (Node) xpath.evaluate("PayerBusiness", node, XPathConstants.NODE);
  319. if (childNode != null && !isWhitespaceNode(childNode)) {
  320. this.payerBusiness = childNode.getTextContent();
  321. }
  322. childNode = (Node) xpath.evaluate("Address", node, XPathConstants.NODE);
  323. if (childNode != null && !isWhitespaceNode(childNode)) {
  324. this.address = new AddressType(childNode);
  325. }
  326. childNode = (Node) xpath.evaluate("ContactPhone", node, XPathConstants.NODE);
  327. if (childNode != null && !isWhitespaceNode(childNode)) {
  328. this.contactPhone = childNode.getTextContent();
  329. }
  330. nodeList = (NodeList) xpath.evaluate("WalletItems", node, XPathConstants.NODESET);
  331. if (nodeList != null && nodeList.getLength() > 0) {
  332. for(int i=0; i < nodeList.getLength(); i++) {
  333. Node subNode = nodeList.item(i);
  334. this.walletItems.add(new WalletItemsType(subNode));
  335. }
  336. }
  337. childNode = (Node) xpath.evaluate("TaxIdDetails", node, XPathConstants.NODE);
  338. if (childNode != null && !isWhitespaceNode(childNode)) {
  339. this.taxIdDetails = new TaxIdDetailsType(childNode);
  340. }
  341. childNode = (Node) xpath.evaluate("EnhancedPayerInfo", node, XPathConstants.NODE);
  342. if (childNode != null && !isWhitespaceNode(childNode)) {
  343. this.enhancedPayerInfo = new EnhancedPayerInfoType(childNode);
  344. }
  345. }
  346. }