@@ -262,5 +262,46 @@ public Refund getRefund(String chargeId, String refundId) throws BaseException {
262262 prepareResponse (request , response , refundResponse );
263263 return refundResponse ;
264264 }
265+
266+ /**
267+ * Method to void a Charge
268+ *
269+ * @param chargeId
270+ * @param refund
271+ * @return
272+ * @throws BaseException
273+ */
274+ public Refund voidTransaction (String chargeRequestId ) throws BaseException {
275+
276+ logger .debug ("Enter ChargeService::refund" );
277+
278+ if (StringUtils .isBlank (chargeRequestId )) {
279+ logger .error ("IllegalArgumentException {}" , chargeRequestId );
280+ throw new IllegalArgumentException ("chargeRequestId cannot be empty or null" );
281+ }
282+
283+ // prepare API url
284+ String apiUrl = requestContext .getBaseUrl ()
285+ + "txn-requests/{id}/void" .replaceAll ("\\ {format\\ }" , "json" ).replaceAll ("\\ {" + "id" + "\\ }" , chargeRequestId );
286+ logger .info ("apiUrl - " + apiUrl );
287+
288+ // assign TypeReference for deserialization
289+ TypeReference <Refund > typeReference = new TypeReference <Refund >() {
290+ };
291+
292+ // prepare service request
293+ Request request = new Request .RequestBuilder (MethodType .POST , apiUrl )
294+ .typeReference (typeReference ).context (requestContext ).build ();
295+
296+ // make API call
297+ Response response = sendRequest (request );
298+
299+ // retrieve response
300+ Refund refundResponse = (Refund ) response .getResponseObject ();
301+
302+ // set additional attributes
303+ prepareResponse (request , response , refundResponse );
304+ return refundResponse ;
305+ }
265306
266307}
0 commit comments