1010import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
1111import com .maxmind .minfraud .exception .*;
1212import com .maxmind .minfraud .request .Transaction ;
13+ import com .maxmind .minfraud .request .TransactionReport ;
1314import com .maxmind .minfraud .response .FactorsResponse ;
1415import com .maxmind .minfraud .response .InsightsResponse ;
1516import com .maxmind .minfraud .response .ScoreResponse ;
@@ -282,7 +283,39 @@ public ScoreResponse score(Transaction transaction) throws IOException,
282283 return responseFor ("score" , transaction , ScoreResponse .class );
283284 }
284285
285- private <T > T responseFor (String service , Transaction transaction , Class <T > cls )
286+ /**
287+ * Make a Report Transaction request to the web service using the TransactionReport
288+ * request object passed to the method.
289+ *
290+ * @param transaction A TransactionReport request object.
291+ * @throws InsufficientFundsException when there are insufficient funds on
292+ * the account.
293+ * @throws AuthenticationException when there is a problem authenticating.
294+ * @throws InvalidRequestException when the request is invalid for some
295+ * other reason.
296+ * @throws PermissionRequiredException when permission is required to use the
297+ * service.
298+ * @throws MinFraudException when the web service returns unexpected
299+ * content.
300+ * @throws HttpException when the web service returns an unexpected
301+ * response.
302+ * @throws IOException when some other IO error occurs.
303+ */
304+ public void reportTransaction (TransactionReport transaction ) throws IOException ,
305+ MinFraudException , InsufficientFundsException , InvalidRequestException ,
306+ AuthenticationException , PermissionRequiredException , HttpException {
307+ if (transaction == null ) {
308+ throw new IllegalArgumentException ("transaction report must not be null" );
309+ }
310+ URL url = createUrl (WebServiceClient .pathBase + "transactions/report" );
311+ HttpPost request = requestFor (transaction , url );
312+
313+ try (CloseableHttpResponse response = httpClient .execute (request )) {
314+ maybeThrowException (response , url );
315+ }
316+ }
317+
318+ private <T > T responseFor (String service , AbstractModel transaction , Class <T > cls )
286319 throws IOException , MinFraudException {
287320 if (transaction == null ) {
288321 throw new IllegalArgumentException ("transaction must not be null" );
@@ -295,7 +328,7 @@ private <T> T responseFor(String service, Transaction transaction, Class<T> cls)
295328 }
296329 }
297330
298- private HttpPost requestFor (Transaction transaction , URL url )
331+ private HttpPost requestFor (AbstractModel transaction , URL url )
299332 throws MinFraudException , IOException {
300333 Credentials credentials = new UsernamePasswordCredentials (Integer .toString (accountId ), licenseKey );
301334
@@ -321,18 +354,23 @@ private HttpPost requestFor(Transaction transaction, URL url)
321354 return request ;
322355 }
323356
324- private <T > T handleResponse (CloseableHttpResponse response , URL url , Class <T > cls )
325- throws MinFraudException , IOException {
357+ private void maybeThrowException (CloseableHttpResponse response , URL url ) throws IOException , MinFraudException {
326358 int status = response .getStatusLine ().getStatusCode ();
327359 if (status >= 400 && status < 500 ) {
328360 this .handle4xxStatus (response , url );
329361 } else if (status >= 500 && status < 600 ) {
330362 throw new HttpException ("Received a server error (" + status
331363 + ") for " + url , status , url );
332- } else if (status != 200 ) {
364+ } else if (status != 200 && status != 204 ) {
333365 throw new HttpException ("Received an unexpected HTTP status ("
334366 + status + ") for " + url , status , url );
335367 }
368+ }
369+
370+ private <T > T handleResponse (CloseableHttpResponse response , URL url , Class <T > cls )
371+ throws MinFraudException , IOException {
372+ maybeThrowException (response , url );
373+
336374 HttpEntity entity = response .getEntity ();
337375
338376 InjectableValues inject = new Std ().addValue (
0 commit comments