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

Commit

Permalink
Fix webhook lookup (#32)
Browse files Browse the repository at this point in the history
* Lookup Order by ProviderReference instead of PublicReference

* Add separate methods for public and provider reference lookup

* Fix small html errors

* Nothing to see here.
  • Loading branch information
Sille Kamoen authored and TimvdLippe committed Mar 15, 2017
1 parent 253d9c5 commit 65e6940
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ch/wisv/payments/admin/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ String orders(Model model) {
@PostMapping("/update/{orderReference}")
String updateOrder(Model model, @PathVariable String orderReference, RedirectAttributes redirectAttributes) {
try {
Order order = paymentService.updateStatus(orderReference);
Order order = paymentService.updateStatusByPublicReference(orderReference);
redirectAttributes.addFlashAttribute("message", "Order " + order.getId() + " successfully updated!");
} catch (RuntimeException e) {
redirectAttributes.addFlashAttribute("error", e.getMessage());
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/ch/wisv/payments/rest/MolliePaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,20 @@ private void updateOrder(Order order, ResponseOrError<Payment> molliePayment) {
}

@Override
public Order updateStatus(String orderReference) {
Order order = orderRepository.findByPublicReference(orderReference)
.orElseThrow(() -> new RuntimeException("Order with providerReference " + orderReference + " not found"));
public Order updateStatusByPublicReference(String publicOrderReference) {
Order order = orderRepository.findByPublicReference(publicOrderReference)
.orElseThrow(() -> new RuntimeException("Order with publicReference " + publicOrderReference + " not found"));
return updateOrder(order);
}

@Override
public Order updateStatusByProviderReference(String providerOrderReference) {
Order order = orderRepository.findByProviderReference(providerOrderReference)
.orElseThrow(() -> new RuntimeException("Order with providerReference " + providerOrderReference + " not found"));
return updateOrder(order);
}

private Order updateOrder(Order order) {
// This try is for the Mollie API internal HttpClient
try {
// Request a payment from Mollie
Expand All @@ -116,7 +126,7 @@ public Order updateStatus(String orderReference) {
break;
}
case "paid": {
if(!order.getStatus().equals(OrderStatus.PAID)){
if (!order.getStatus().equals(OrderStatus.PAID)) {
mailService.sendOrderConfirmation(order);
}
order.setStatus(OrderStatus.PAID);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/ch/wisv/payments/rest/OrderRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ public ResponseEntity<?> getOrderStatus(@PathVariable String orderReference) {
return new ResponseEntity<>(new OrderResponse(order), HttpStatus.OK);
}

/**
* This endpoint is for the paymentprovider. Webhooks will arrive here.
*
* @param providerReference The provider Order Reference
* @return Status Message
*/
@RequestMapping(value = "/status", method = RequestMethod.POST)
public ResponseEntity<?> updateOrderStatus(@RequestParam(name = "id") String orderReference) {
paymentService.updateStatus(orderReference);
public ResponseEntity<?> updateOrderStatus(@RequestParam(name = "id") String providerReference) {
paymentService.updateStatusByProviderReference(providerReference);
return new ResponseEntity<>(HttpStatus.OK);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/wisv/payments/rest/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface PaymentService {

OrderResponse registerOrder(Order order);

Order updateStatus(String orderReference);
Order updateStatusByPublicReference(String publicOrderReference);

Order updateStatusByProviderReference(String providerOrderReference);

}
4 changes: 1 addition & 3 deletions src/main/resources/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ <h1>CH-Payments</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"
integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
<script th:src="@{/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js}"></script>
</body>
</html>

2 changes: 1 addition & 1 deletion src/main/resources/templates/products.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ <h3 class="panel-title">Add Product Group</h3>
<td th:text="${group.getCommittee().getName().getName()} + ' '+ ${group.getCommittee().getYear()}">
Row 1 Data 2
</td>
<td th:text="${group.getGroupLimit()}">Group limit</td>
<td th:text="${group.getName()}">Row 1 Data 1</td>
<td th:text="${group.getGroupLimit()}">Group limit</td>
<td th:text="${group.getDescription()}">Row 1 Data 3</td>
<td>
<ul th:each="product : ${group.getProducts()}">
Expand Down

0 comments on commit 65e6940

Please sign in to comment.