<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>thread Re: Processing cards through rest on Java Servlet in Archived Discussions (Read Only)</title>
    <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Processing-cards-through-rest-on-Java-Servlet/m-p/47819#M98115</link>
    <description>&lt;P&gt;The whole issue turns out to be the idempotency key much be unique...is there a way to get more detailed error messages than just a 400 error, the documentation says it also sends a JSON error package back, however, I am not able to read this in, the stream is null.&lt;/P&gt;</description>
    <pubDate>Thu, 31 Aug 2017 15:14:10 GMT</pubDate>
    <dc:creator>JPP</dc:creator>
    <dc:date>2017-08-31T15:14:10Z</dc:date>
    <item>
      <title>Processing cards through rest on Java Servlet</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Processing-cards-through-rest-on-Java-Servlet/m-p/47811#M98114</link>
      <description>&lt;P&gt;I am implimenting a java servlet, running right now on localhost with connect v2. &amp;nbsp;I am succesfully able to enter a card number on my webpage, then receive the locationID using the nonce, however, when I request that the card be charged, I am getting a 400 error with no other inforamtion returned. &amp;nbsp;I should also note, that I am sending the exact JSON that the documentation suggests, with&amp;nbsp;the nonce being&amp;nbsp;updated.... &amp;nbsp;Any suggestion would be greatly appreciated...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;String JSONSample = "{\"idempotency_key\": \"74ae1696-b1e3-4328-af6d-f1e04d947a13\",\"shipping_address\": {\"address_line_1\": \"123 Main St\",\"locality\": \"San Francisco\",\"administrative_district_level_1\": \"CA\",\"postal_code\": \"94114\",\"country\": \"US\"},\"billing_address\": {\"address_line_1\": \"500 Electric Ave\",\"address_line_2\": \"Suite 600\",\"administrative_district_level_1\": \"NY\",\"locality\": \"New York\",\"postal_code\": \"10003\",\"country\": \"US\"},\"amount_money\": {\"amount\": 5000,\"currency\": \"USD\"},\"card_nonce\": \"" + nonce +"\",\"reference_id\": \"some optional reference id\",\"note\": \"some optional note\",\"delay_capture\": false}";
		
		String output = "";
		try {
			String charset = "UTF-8"; 
			String JSONString = chargeObject.toString();
			URL url = new URL("https://connect.squareup.com/v2/locations/" + LocationID + "/transactions");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setRequestMethod("POST");
			conn.setRequestProperty("Accept", "application/json");
			conn.setRequestProperty("Content-Type", "application/json");
			conn.setRequestProperty("Authorization", "Bearer sandbox-&amp;lt;...removed...&amp;gt;");

			OutputStream os = conn.getOutputStream();
            os.write(JSONSample.getBytes(charset));
            os.close();
			

			if (conn.getResponseCode() != 200) {
				throw new RuntimeException("Failed : HTTP error code : "
						+ conn.getResponseCode());
			}

			BufferedReader br = new BufferedReader(new InputStreamReader(
				(conn.getInputStream())));

			logger.info("Output from Server .... \n");
			
			String JSON = "";
			//System.out.println("Output from Server .... \n");
			while ((output = br.readLine()) != null) {
				logger.info(output);
				JSON += output;
			}

			conn.disconnect();
			
			return JSON;

		  } catch (MalformedURLException e) {

			e.printStackTrace();

		  } catch (IOException e) {

			e.printStackTrace();

		  }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:35:10 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Processing-cards-through-rest-on-Java-Servlet/m-p/47811#M98114</guid>
      <dc:creator>JPP</dc:creator>
      <dc:date>2017-08-31T14:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Processing cards through rest on Java Servlet</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Processing-cards-through-rest-on-Java-Servlet/m-p/47819#M98115</link>
      <description>&lt;P&gt;The whole issue turns out to be the idempotency key much be unique...is there a way to get more detailed error messages than just a 400 error, the documentation says it also sends a JSON error package back, however, I am not able to read this in, the stream is null.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 15:14:10 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Processing-cards-through-rest-on-Java-Servlet/m-p/47819#M98115</guid>
      <dc:creator>JPP</dc:creator>
      <dc:date>2017-08-31T15:14:10Z</dc:date>
    </item>
  </channel>
</rss>

