-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/nashtech-garage/yas into fe…
…ature/1003-payment-provider # Conflicts: # payment-paypal/src/main/java/com/yas/payment/paypal/service/OrderService.java # payment-paypal/src/main/java/com/yas/payment/paypal/service/PaypalService.java # payment-paypal/src/main/java/com/yas/payment/paypal/viewmodel/OrderVm.java # payment-paypal/src/main/java/com/yas/paymentpaypal/config/ServiceUrlConfig.java # payment-paypal/src/main/java/com/yas/paymentpaypal/service/PaymentService.java # payment-paypal/src/main/resources/application.properties # payment-paypal/src/test/java/com/yas/payment/paypal/service/OrderServiceTest.java # payment-paypal/src/test/java/com/yas/payment/paypal/service/PaypalServiceTest.java # payment-paypal/src/test/java/com/yas/paymentpaypal/service/PaymentServiceTest.java # payment/src/main/java/com/yas/payment/service/OrderService.java
- Loading branch information
Showing
14 changed files
with
159 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
payment-paypal/src/main/java/com/yas/payment/paypal/service/OrderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.yas.payment.paypal.service; | ||
|
||
import com.yas.paymentpaypal.config.ServiceUrlConfig; | ||
import com.yas.payment.paypal.viewmodel.OrderVm; | ||
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker; | ||
import io.github.resilience4j.retry.annotation.Retry; | ||
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; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class OrderService extends AbstractCircuitBreakFallbackHandler { | ||
private final RestClient restClient; | ||
private final ServiceUrlConfig serviceUrlConfig; | ||
|
||
@Retry(name = "restApi") | ||
@CircuitBreaker(name = "restCircuitBreaker", fallbackMethod = "handleBodilessFallback") | ||
public OrderVm getOrderByCheckoutId(String checkoutId) { | ||
final String jwt = | ||
((Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getTokenValue(); | ||
final URI url = UriComponentsBuilder | ||
.fromHttpUrl(serviceUrlConfig.order()) | ||
.path("/storefront/orders/checkout/" + checkoutId) | ||
.buildAndExpand() | ||
.toUri(); | ||
|
||
return restClient.get() | ||
.uri(url) | ||
.headers(h -> h.setBearerAuth(jwt)) | ||
.retrieve() | ||
.body(OrderVm.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
payment-paypal/src/main/java/com/yas/payment/paypal/viewmodel/OrderVm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.yas.payment.paypal.viewmodel; | ||
|
||
public record OrderVm(Long id) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
payment-paypal/src/test/java/com/yas/payment/paypal/service/OrderServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//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; | ||
//import static org.mockito.Mockito.when; | ||
// | ||
//import com.yas.paymentpaypal.config.ServiceUrlConfig; | ||
//import java.net.URI; | ||
//import java.util.UUID; | ||
//import org.junit.jupiter.api.BeforeEach; | ||
//import org.junit.jupiter.api.Test; | ||
//import org.mockito.Mockito; | ||
//import org.springframework.web.client.RestClient; | ||
//import org.springframework.web.util.UriComponentsBuilder; | ||
// | ||
//public class OrderServiceTest { | ||
// private RestClient restClient; | ||
// | ||
// private ServiceUrlConfig serviceUrlConfig; | ||
// | ||
// private OrderService orderService; | ||
// | ||
// private RestClient.ResponseSpec responseSpec; | ||
// | ||
// private static final String ORDER_URL = "http://api.yas.local/order"; | ||
// | ||
// @BeforeEach | ||
// void setUp() { | ||
// restClient = mock(RestClient.class); | ||
// serviceUrlConfig = mock(ServiceUrlConfig.class); | ||
// orderService = new OrderService(restClient, serviceUrlConfig); | ||
// responseSpec = Mockito.mock(RestClient.ResponseSpec.class); | ||
// setUpSecurityContext("test"); | ||
// when(serviceUrlConfig.order()).thenReturn(ORDER_URL); | ||
// } | ||
// | ||
// @Test | ||
// void testGetOrderByCheckoutId_ifNormalCase_returnOrderVm() { | ||
// String checkoutId = UUID.randomUUID().toString(); | ||
// | ||
// final URI url = UriComponentsBuilder | ||
// .fromHttpUrl(serviceUrlConfig.order()) | ||
// .path("/storefront/orders/checkout/" + checkoutId) | ||
// .buildAndExpand() | ||
// .toUri(); | ||
// | ||
// RestClient.RequestHeadersUriSpec requestBodyUriSpec = mock(RestClient.RequestHeadersUriSpec.class); | ||
// when(restClient.get()).thenReturn(requestBodyUriSpec); | ||
// when(requestBodyUriSpec.uri(url)).thenReturn(requestBodyUriSpec); | ||
// when(requestBodyUriSpec.headers(any())).thenReturn(requestBodyUriSpec); | ||
// when(requestBodyUriSpec.retrieve()).thenReturn(responseSpec); | ||
// | ||
// orderService.getOrderByCheckoutId(checkoutId); | ||
// | ||
// verify(restClient, times(1)).get(); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters