Skip to content

Commit

Permalink
Fix issue can;t update payment status for order service (#1238)
Browse files Browse the repository at this point in the history
Co-authored-by: Danh Nguyen Van <danh.nguyenvan@hermes-europe.co.uk>
  • Loading branch information
danhnguyenv1 and Danh Nguyen Van authored Oct 28, 2024
1 parent 9576d76 commit da72516
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ResponseEntity<OrderVm> getOrderWithItemsById(@PathVariable long id) {
return ResponseEntity.ok(orderService.getOrderWithItemsById(id));
}

@GetMapping("/backoffice/orders/checkout/{id}")
@GetMapping("/storefront/orders/checkout/{id}")
public ResponseEntity<OrderGetVm> getOrderWithCheckoutId(@PathVariable String id) {
return ResponseEntity.ok(orderService.findOrderVmByCheckoutId(id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public OrderVm getOrderByCheckoutId(String checkoutId) {
((Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getTokenValue();
final URI url = UriComponentsBuilder
.fromHttpUrl(serviceUrlConfig.order())
.path("/backoffice/orders/checkout/" + checkoutId)
.path("/storefront/orders/checkout/" + checkoutId)
.buildAndExpand()
.toUri();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import org.springframework.web.util.UriComponentsBuilder;
Expand All @@ -22,15 +24,18 @@ public class PaymentService extends AbstractCircuitBreakFallbackHandler {
@Retry(name = "restApi")
@CircuitBreaker(name = "restCircuitBreaker", fallbackMethod = "handleBodilessFallback")
public void capturePayment(CapturedPaymentVm completedPayment) {
final String jwt =
((Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getTokenValue();
final URI url = UriComponentsBuilder
.fromHttpUrl(serviceUrlConfig.payment())
.path("/storefront/payments/capture")
.buildAndExpand()
.toUri();
.fromHttpUrl(serviceUrlConfig.payment())
.path("/storefront/payments/capture")
.buildAndExpand()
.toUri();

restClient.post()
.uri(url)
.body(completedPayment)
.retrieve();
.uri(url)
.headers(h -> h.setBearerAuth(jwt))
.body(completedPayment)
.retrieve();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void testGetOrderByCheckoutId_ifNormalCase_returnOrderVm() {

final URI url = UriComponentsBuilder
.fromHttpUrl(serviceUrlConfig.order())
.path("/backoffice/orders/checkout/" + checkoutId)
.path("/storefront/orders/checkout/" + checkoutId)
.buildAndExpand()
.toUri();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yas.paymentpaypal.service;

import static com.yas.paymentpaypal.utils.SecurityContextUtils.setUpSecurityContext;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -61,7 +62,7 @@ void testCapturePayment_ifNormalCase_returnAddressDetailVm() {
RestClient.RequestBodyUriSpec requestBodyUriSpec = mock(RestClient.RequestBodyUriSpec.class);
when(restClient.post()).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.uri(url)).thenReturn(requestBodyUriSpec);

when(requestBodyUriSpec.headers(any())).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.body(payment)).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.retrieve()).thenReturn(responseSpec);

Expand All @@ -70,4 +71,4 @@ void testCapturePayment_ifNormalCase_returnAddressDetailVm() {
verify(restClient, times(1)).post();
}

}
}

0 comments on commit da72516

Please sign in to comment.