Skip to content

Commit d66c8d3

Browse files
committed
add void API
1 parent 9845540 commit d66c8d3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

payments-api/src/main/java/com/intuit/payment/http/HttpRequestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public Response makeRequest(Request serviceRequest) throws BadRequestException {
130130
}
131131

132132
MethodType method = serviceRequest.getMethod();
133-
if (method == MethodType.POST) {
133+
if (method == MethodType.POST && serviceRequest.getPostJson() != null) {
134134
// add post json
135135
HttpEntity entity = new StringEntity(serviceRequest.getPostJson(), "UTF-8");
136136
builder.setEntity(entity);

payments-api/src/main/java/com/intuit/payment/services/ChargeService.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)