@Test public void createQuery_withCardData_createsProperQueryString() { Card card = new Card.Builder("4242424242424242", 8, 2019, "123").build(); Map<String, Object> cardMap = StripeNetworkUtils.hashMapFromCard( RuntimeEnvironment.application, card); String expectedValue = "product_usage=&card%5Bnumber%5D=4242424242424242&card%5B" + "cvc%5D=123&card%5Bexp_month%5D=8&card%5Bexp_year%5D=2019"; try { String query = StripeApiHandler.createQuery(cardMap); assertEquals(expectedValue, query); } catch (UnsupportedEncodingException unsupportedCodingException) { fail("Encoding error with card object"); } catch (InvalidRequestException invalidRequest) { fail("Invalid request error when encoding card query: " + invalidRequest.getLocalizedMessage()); } }
static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException { StringBuilder queryStringBuffer = new StringBuilder(); List<Parameter> flatParams = flattenParams(params); Iterator<Parameter> it = flatParams.iterator(); while (it.hasNext()) { if (queryStringBuffer.length() > 0) { queryStringBuffer.append("&"); } Parameter param = it.next(); queryStringBuffer.append(urlEncodePair(param.key, param.value)); } return queryStringBuffer.toString(); }
StripeApiHandler { static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException { StringBuilder queryStringBuffer = new StringBuilder(); List<Parameter> flatParams = flattenParams(params); Iterator<Parameter> it = flatParams.iterator(); while (it.hasNext()) { if (queryStringBuffer.length() > 0) { queryStringBuffer.append("&"); } Parameter param = it.next(); queryStringBuffer.append(urlEncodePair(param.key, param.value)); } return queryStringBuffer.toString(); } }
StripeApiHandler { static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException { StringBuilder queryStringBuffer = new StringBuilder(); List<Parameter> flatParams = flattenParams(params); Iterator<Parameter> it = flatParams.iterator(); while (it.hasNext()) { if (queryStringBuffer.length() > 0) { queryStringBuffer.append("&"); } Parameter param = it.next(); queryStringBuffer.append(urlEncodePair(param.key, param.value)); } return queryStringBuffer.toString(); }  }
StripeApiHandler { static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException { StringBuilder queryStringBuffer = new StringBuilder(); List<Parameter> flatParams = flattenParams(params); Iterator<Parameter> it = flatParams.iterator(); while (it.hasNext()) { if (queryStringBuffer.length() > 0) { queryStringBuffer.append("&"); } Parameter param = it.next(); queryStringBuffer.append(urlEncodePair(param.key, param.value)); } return queryStringBuffer.toString(); }   }
StripeApiHandler { static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException { StringBuilder queryStringBuffer = new StringBuilder(); List<Parameter> flatParams = flattenParams(params); Iterator<Parameter> it = flatParams.iterator(); while (it.hasNext()) { if (queryStringBuffer.length() > 0) { queryStringBuffer.append("&"); } Parameter param = it.next(); queryStringBuffer.append(urlEncodePair(param.key, param.value)); } return queryStringBuffer.toString(); }    }