{"action":"opened","issue":{"url":"https://api.github.com/repos/AuthorizeNet/sdk-java/issues/50","labels_url":"https://api.github.com/repos/AuthorizeNet/sdk-java/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/AuthorizeNet/sdk-java/issues/50/comments","events_url":"https://api.github.com/repos/AuthorizeNet/sdk-java/issues/50/events","html_url":"https://github.com/AuthorizeNet/sdk-java/issues/50","id":99864570,"number":50,"title":"createCustomerProfile: null cardCode results in invalid XML error","user":{"login":"alfredaday","id":54807,"avatar_url":"https://avatars.githubusercontent.com/u/54807?v=3","gravatar_id":"","url":"https://api.github.com/users/alfredaday","html_url":"https://github.com/alfredaday","followers_url":"https://api.github.com/users/alfredaday/followers","following_url":"https://api.github.com/users/alfredaday/following{/other_user}","gists_url":"https://api.github.com/users/alfredaday/gists{/gist_id}","starred_url":"https://api.github.com/users/alfredaday/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfredaday/subscriptions","organizations_url":"https://api.github.com/users/alfredaday/orgs","repos_url":"https://api.github.com/users/alfredaday/repos","events_url":"https://api.github.com/users/alfredaday/events{/privacy}","received_events_url":"https://api.github.com/users/alfredaday/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-09T05:03:22Z","updated_at":"2015-08-09T05:03:22Z","closed_at":null,"body":"Hi,\r\n\r\nI'm using the CIM API in your sdk.  I have a use case where I need to be able to create a customer profile with a payment profile that does not have a card code.  To do that, I set the card code to null and then call the API.  However, the SDK calls Authorize.net and receives an error message:\r\n\r\n[Error] E00003: The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:cardCode' element is invalid - The value '' is invalid according to its datatype 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:cardCode' - The Pattern constraint failed.\r\n\r\nThe reason it receives the error is because the SDK creates the cardCode element in the XML and it is left empty (Please notice the '<cardCode></cardCode>' in the request below):\r\n\r\n```\r\n<?xml version=\"1.0\"?>\r\n<createCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">\r\n  <merchantAuthentication>\r\n    <name>LOGIN_ID_MASKED</name>\r\n    <transactionKey>TRANSACTION_KEY_MASKED</transactionKey>\r\n  </merchantAuthentication>\r\n  <profile>\r\n    <merchantCustomerId>AAAAAA</merchantCustomerId>\r\n    <description>df98d979-0dd0-4f98-bc66-ed654b3f1388</description>\r\n    <email></email>\r\n    <paymentProfiles>\r\n      <customerType>individual</customerType>\r\n      <billTo>\r\n        <firstName></firstName>\r\n        <lastName></lastName>\r\n        <company></company>\r\n        <address></address>\r\n        <city></city>\r\n        <state></state>\r\n        <zip></zip>\r\n        <country></country>\r\n        <phoneNumber></phoneNumber>\r\n        <faxNumber></faxNumber>\r\n      </billTo>\r\n      <payment>\r\n        <creditCard>\r\n          <cardNumber>MASKED**0002</cardNumber>\r\n          <expirationDate>2029-07</expirationDate>\r\n          <cardCode></cardCode>\r\n        </creditCard>\r\n      </payment>\r\n    </paymentProfiles>\r\n  </profile>\r\n  <validationMode>testMode</validationMode>\r\n</createCustomerProfileRequest>\r\n```\r\n\r\nHere is a test case that you can use to reproduce this issue:\r\n\r\n```\r\n@Test\r\npublic void testCase() {\r\n    final String authorizeNetCardNotPresentApiLoginId = \"YOUR_API_LOGIN_ID\";\r\n    final String authorizeNetCardNotPresentTransactionKey = \"YOUR_TRANSACTION_KEY\";\r\n\r\n    final Merchant merchant = Merchant.createMerchant(Environment.SANDBOX, authorizeNetCardNotPresentApiLoginId, authorizeNetCardNotPresentTransactionKey);\r\n\r\n    final CreditCard creditCard = CreditCard.createCreditCard();\r\n    creditCard.setCreditCardNumber(\"370000000000002\");\r\n    creditCard.setExpirationDate(\"2029-07\");\r\n    creditCard.setCardCode(null);\r\n\r\n    final Address address = Address.createAddress();\r\n    address.setZipPostalCode(null);\r\n\r\n    final PaymentProfile paymentProfile = PaymentProfile.createPaymentProfile();\r\n    paymentProfile.addPayment(Payment.createPayment(creditCard));\r\n    paymentProfile.setCustomerType(CustomerType.INDIVIDUAL);\r\n    paymentProfile.setBillTo(address);\r\n\r\n    final CustomerProfile customerProfile = CustomerProfile.createCustomerProfile();\r\n    customerProfile.setMerchantCustomerId(\"AAAAAA\");\r\n    customerProfile.setDescription(UUID.randomUUID().toString());\r\n\r\n    final ValidationModeType validationMode = ValidationModeType.TEST_MODE;\r\n\r\n    // Create a new customer profile\r\n    final net.authorize.cim.Transaction transaction = merchant.createCIMTransaction(TransactionType.CREATE_CUSTOMER_PROFILE);\r\n    transaction.setCustomerProfile(customerProfile);\r\n    transaction.addPaymentProfile(paymentProfile);\r\n    transaction.setValidationMode(validationMode);\r\n\r\n    final net.authorize.cim.Result<Transaction> result = (net.authorize.cim.Result<Transaction>) merchant.postTransaction(transaction);\r\n\r\n    if (false == result.isOk()) {\r\n        final StringBuilder stringBuilder = new StringBuilder();\r\n\r\n        boolean isFirst = true;\r\n        for (final Message message : result.getMessages()) {\r\n            final String code = message.getCode();\r\n            final String text = message.getText();\r\n\r\n            if (isFirst == false) {\r\n                stringBuilder.append(\", \");\r\n            }\r\n            stringBuilder.append(code+\": \"+text);\r\n\r\n            isFirst = false;\r\n        }\r\n\r\n        throw new RuntimeException(\"[\"+result.getResultCode()+\"] \"+stringBuilder.toString());\r\n    }\r\n\r\n}\r\n```\r\n\r\nLuckily, the fix for this is very simple.  In your net.authorize.cim.Transaction.java file, in the addPayment method you need to modify the following lines:\r\n\r\n```\r\nElement card_code_el = document.createElement(AuthNetField.ELEMENT_CARD_CODE.getFieldName());\r\ncard_code_el.appendChild(document.getDocument().createTextNode(credit_card.getCardCode()));\r\ncc_el.appendChild(card_code_el);\r\n```\r\nAll you need to do is wrap an if statement around it, like so:\r\n```\r\nif (StringUtils.isNotEmpty(credit_card.getCardCode())) {\r\n    Element card_code_el = document.createElement(AuthNetField.ELEMENT_CARD_CODE.getFieldName());\r\n    card_code_el.appendChild(document.getDocument().createTextNode(credit_card.getCardCode()));\r\n    cc_el.appendChild(card_code_el);\r\n}\r\n```"}}