Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Improved payment errors
Browse files Browse the repository at this point in the history
- extended the payment response, with payment status message directly
  from the payment service
- switched some log lines from debug to info. The orders service was not
  having any output.
  • Loading branch information
nustiueudinastea committed Jan 20, 2017
1 parent 85d49de commit 4757c9f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ CustomerOrder newOrder(@RequestBody NewOrderResource item) {
cardFuture.get(timeout, TimeUnit.SECONDS).getContent(),
customerFuture.get(timeout, TimeUnit.SECONDS).getContent(),
amount);
LOG.debug("Sending payment request: " + paymentRequest);
LOG.info("Sending payment request: " + paymentRequest);
Future<PaymentResponse> paymentFuture = asyncGetService.postResource(
config.getPaymentUri(),
paymentRequest,
new ParameterizedTypeReference<PaymentResponse>() {
});
PaymentResponse paymentResponse = paymentFuture.get(timeout, TimeUnit.SECONDS);
LOG.debug("Received payment response: " + paymentResponse);
LOG.info("Received payment response: " + paymentResponse);
if (paymentResponse == null) {
throw new PaymentDeclinedException("Unable to parse authorisation packet");
}
if (!paymentResponse.isAuthorised()) {
throw new PaymentDeclinedException("Payment declined");
throw new PaymentDeclinedException(paymentResponse.getMessage());
}

// Ship
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

public class PaymentResponse {
private boolean authorised = false;
private String message;

// For jackson
public PaymentResponse() {
}

public PaymentResponse(boolean authorised) {
public PaymentResponse(boolean authorised, String message) {
this.authorised = authorised;
this.message = message;
}

@Override
public String toString() {
return "PaymentResponse{" +
"authorised=" + authorised +
", message=" + message +
'}';
}

Expand All @@ -25,4 +28,12 @@ public boolean isAuthorised() {
public void setAuthorised(boolean authorised) {
this.authorised = authorised;
}

public void setMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

public class PaymentResponse {
private boolean authorised = false;
private String message;

// For jackson
public PaymentResponse() {
}

public PaymentResponse(boolean authorised) {
public PaymentResponse(boolean authorised, String message) {
this.authorised = authorised;
this.message = message;
}

@Override
public String toString() {
return "PaymentResponse{" +
"authorised=" + authorised +
", message=" + message +
'}';
}

Expand All @@ -25,4 +28,12 @@ public boolean isAuthorised() {
public void setAuthorised(boolean authorised) {
this.authorised = authorised;
}

public void setMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}

0 comments on commit 4757c9f

Please sign in to comment.