๊ฒฐ์ œ API

ย ์‚ฌ์šฉ๋ฒ•

ย ์„œ๋ฒ„์—์„œ ์„œ๋ฒ„๋กœ ์š”์ฒญํ•˜๋Š” ๊ตฌ์กฐ

๊ฒฐ์ œ๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์š”์ฒญํ•œ ์„œ๋ฒ„(์ž์‹ ์˜ ์„œ๋ฒ„)์— ๊ฒฐ์ œ ์™„๋ฃŒ ์‘๋‹ต์ด ๊ฐ€์„œ ์ž์‹ ์˜ ํด๋ผ์ด์–ธํŠธ์— ์‘๋‹ต
โ€ข
(๋‚ด ํด๋ผ์ด์–ธํŠธ) -๊ฒฐ์ œ ์š”์ฒญ(์ปค์Šคํ…€)โ†’ (๋‚ด ์„œ๋ฒ„) -๊ฒฐ์ œ ์š”์ฒญโ†’ (ํ”ผํ”ผ ๊ฒฐ์ œ ์„œ๋ฒ„)
โ€ข
(๋‚ด ํด๋ผ์ด์–ธํŠธ) โ†๊ฒฐ์ œ ์™„๋ฃŒ(์ปค์Šคํ…€)- (๋‚ด ์„œ๋ฒ„) โ†๊ฒฐ์ œ ์™„๋ฃŒโ† (ํ”ผํ”ผ ๊ฒฐ์ œ ์„œ๋ฒ„)

ย API ๋ช…์„ธ์„œ

URI
Method
Description
POST
๊ฒฐ์ œ ์š”์ฒญ
GET
์˜ค๋” ์•„์ด๋””๋กœ ๊ฒฐ์ œ ์ •๋ณด ๋ฐ›๊ธฐ

ย ์ฝ”๋“œ

ย OpenFeign

PlantifyPaymentServiceClient

@FeignClient(name = "plantify-payment-service", url = "${}") public interface PlantifyPaymentServiceClient { @PostMapping("/v1/pay/payment") ResponseEntity<String> payment(@RequestBody TransactionRequest request); @GetMapping("/v1/auth/users/seacrh") ResponseEntity<Long> getUserId(@RequestParam String username); @GetMapping("/v1/pay/settlements/external") ResponseEntity<ExternalSettlementResponse> getSettlementByOrderId(@RequestParam String orderId) }
Java
๋ณต์‚ฌ

ย DTO

TransactionRequest

public record TransactionRequest( Long userId, Long sellerId, String orderName, Long amount, String redirectUri ) { }
Java
๋ณต์‚ฌ

ExternalSettlementResponse

public record ExternalSettlementResponse( String orderId, String orderName, LocalDateTime createdAt, Long amount )
Java
๋ณต์‚ฌ

ย Controller

์˜ˆ์‹œ

@RestController @RequiredArgsConstructor @RequestMapping("/v1") public class MyFundingUserController { private final MyFundingUserService myFundingUserService; @PostMapping("/payment") public void payment(@RequestBody MyFundingUserRequest request, HttpServletResponse response) throws IOException { String redirectUrl = myFundingUserService.payment(request); response.sendRedirect(redirectUrl); } @GetMapping("/callback") public ResponseEntity<MyFundingUserResponse> getMyFundingUserCallback(@RequestParam String orderId) { MyFundingUserResponse response = myFundingUserService.callbackParticipate(orderId); return ResponseEntity.ok(response); } }
Java
๋ณต์‚ฌ

ย Service

๊ฒฐ์ œ ๋กœ์ง์ด ํ•„์š”ํ•œ ์„œ๋น„์Šค ๋กœ์ง์— ์ถ”๊ฐ€
private final PlantifyPaymentServiceClient plantifyPaymentServiceClient;
Java
๋ณต์‚ฌ
Long userId = plantifyAuthServiceClient.getUserId(์œ ์ €์ด๋ฆ„).getBody(); TransactionRequest transactionRequest = new TransactionRequest( userId, 2L, ๊ตฌ๋งคํ•˜๋Š” ์ƒํ’ˆ ์ด๋ฆ„, // ์ˆ˜์ • ๊ตฌ๋งคํ•˜๋Š” ์ƒํ’ˆ ๊ฐ€๊ฒฉ, // ์ˆ˜์ • "redirect Url" // ์ˆ˜์ • ); plantifyPaymentServiceClient.payment(transactionRequest);
Java
๋ณต์‚ฌ
์ˆ˜์ •์ด๋ผ๊ณ  ์ ํžŒ ๊ณณ์„ ์ œ์™ธํ•˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ๊ณ ์ •
ExternalSettlementResponse response = payServiceClient.getSettlementByOrderId(orderId).getBody();
Java
๋ณต์‚ฌ

์˜ˆ์‹œ

@Service @RequireArgsConstructor public class MyFundingServiceImpl implements MyFundingUserService { private final PlantifyPaymentServiceClient plantifyPaymentServiceClient; @Override @Transactional public MyFundingResponse participate(MyfundingUserRequest request) { ... TransactionRequest transactionRequest = new TransactionRequest( userId, 2L, funding.getTitle(), // ์ˆ˜์ • request.price(), // ์ˆ˜์ • "https://www.naver.com" ); plantifyPaymentServiceClient.payment(transactionRequest); ... } @Override public MyFundingUserResponse callbackParticipate(String orderId) { ExternalSettlementResponse response = payServiceClient.getSettlementByOrderId(orderId).getBody(); ... MyFundingUserRequest request = new MyFundingUserRequest(funding.getFundingId(), response.amount()); ... } }
Java
๋ณต์‚ฌ

ย ์ฃผ์˜

ย request์— userId(์œ ์ € ์•„์ด๋””)๋ฅผ ๋„ฃ์–ด์ค˜์•ผํ•จ

(ํ•„์ˆ˜) ์œ ์ € ์ด๋ฆ„์œผ๋กœ ๋จผ์ € ์œ ์ € ์•„์ด๋”” ๋ฐ›๊ธฐ

ย ํ”Œ๋žœํ‹ฐํŒŒ์ด ํŽ˜์ด๋กœ ๊ฒฐ์ œํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ

โ€ข
ํ”Œ๋žœํ‹ฐํŒŒ์ด ์œ ์ €๊ฐ€ ์•„๋‹˜
โ€ข
ํ”Œ๋žœํ‹ฐํŒŒ์ด ์œ ์ €์ธ๋ฐ ํŽ˜์ด๊ฐ€ ์—†๋Š” ์œ ์ €