-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from 9oormthon-univ/develop
Develop
- Loading branch information
Showing
4 changed files
with
143 additions
and
133 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
22 changes: 12 additions & 10 deletions
22
src/main/java/com/jangburich/domain/payment/application/PaymentProcessingService.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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
package com.jangburich.domain.payment.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.jangburich.domain.payment.application.strategy.PaymentServiceStrategy; | ||
import com.jangburich.domain.payment.dto.request.PayRequest; | ||
import com.jangburich.domain.payment.dto.response.ApproveResponse; | ||
import com.jangburich.domain.payment.dto.response.ReadyResponse; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PaymentProcessingService { | ||
|
||
private final PaymentServiceStrategy paymentServiceStrategy; | ||
private final PaymentServiceStrategy paymentServiceStrategy; | ||
|
||
public ReadyResponse processPayment(Long userId, PayRequest payRequest) { | ||
PaymentService paymentService = paymentServiceStrategy.getPaymentService(payRequest.paymentType()); | ||
return paymentService.payReady(userId, payRequest); | ||
} | ||
public ReadyResponse processPayment(Long userId, PayRequest payRequest) { | ||
PaymentService paymentService = paymentServiceStrategy.getPaymentService(payRequest.paymentType()); | ||
return paymentService.payReady(userId, payRequest); | ||
} | ||
|
||
public ApproveResponse processSuccess(Long userId, String tid, String pgToken) { | ||
PaymentService paymentService = paymentServiceStrategy.getPaymentService("kakao"); | ||
return paymentService.payApprove(userId, tid, pgToken); | ||
} | ||
public ApproveResponse processSuccess(String pgToken) { | ||
PaymentService paymentService = paymentServiceStrategy.getPaymentService("kakao"); | ||
return paymentService.payApprove(pgToken); | ||
} | ||
} |
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
75 changes: 36 additions & 39 deletions
75
src/main/java/com/jangburich/domain/payment/presentation/PaymentController.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 |
---|---|---|
@@ -1,60 +1,57 @@ | ||
package com.jangburich.domain.payment.presentation; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.jangburich.domain.payment.application.PaymentProcessingService; | ||
import com.jangburich.domain.payment.application.PaymentService; | ||
import com.jangburich.domain.payment.dto.request.PayRequest; | ||
import com.jangburich.domain.payment.dto.response.ApproveResponse; | ||
import com.jangburich.domain.payment.dto.response.ReadyResponse; | ||
import com.jangburich.domain.payment.exception.PaymentCancellationException; | ||
import com.jangburich.domain.payment.exception.PaymentFailedException; | ||
import com.jangburich.global.payload.ResponseCustom; | ||
import com.jangburich.utils.parser.AuthenticationParser; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Payment", description = "Payments API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/payments") | ||
public class PaymentController { | ||
|
||
private final PaymentProcessingService paymentProcessingService; | ||
|
||
@Operation(summary = "๊ฒฐ์ ์ค๋น", description = "์นด์นด์คํ์ด ๋ฑ ๊ฒฐ์ ์๋จ์ ์ค๋นํ๋ค.") | ||
@PostMapping("/ready") | ||
public ResponseCustom<ReadyResponse> payReady( | ||
Authentication authentication, | ||
@RequestBody PayRequest payRequest | ||
) { | ||
return ResponseCustom.OK(paymentProcessingService.processPayment(AuthenticationParser.parseUserId(authentication), payRequest)); | ||
} | ||
|
||
@Operation(summary = "๊ฒฐ์ ์ฑ๊ณต", description = "๊ฒฐ์ ์ฑ๊ณต") | ||
@PostMapping("/success") | ||
public ResponseCustom<ApproveResponse> afterPayRequest( | ||
Authentication authentication, | ||
@RequestParam("tid") String tid, | ||
@RequestParam("pg_token") String pgToken) { | ||
return ResponseCustom.OK(paymentProcessingService.processSuccess(AuthenticationParser.parseUserId(authentication), tid, pgToken)); | ||
} | ||
|
||
@Operation(summary = "๊ฒฐ์ ์ทจ์", description = "๊ฒฐ์ ์งํ ์ค์ ์ทจ์๋๋ ๊ฒฝ์ฐ") | ||
@GetMapping("/cancel") | ||
public void cancel() { | ||
throw new PaymentCancellationException(); | ||
} | ||
|
||
@Operation(summary = "๊ฒฐ์ ์คํจ", description = "๊ฒฐ์ ์ ์คํจํ๋ ๊ฒฝ์ฐ") | ||
@GetMapping("/fail") | ||
public void fail() { | ||
throw new PaymentFailedException(); | ||
} | ||
private final PaymentProcessingService paymentProcessingService; | ||
|
||
@Operation(summary = "๊ฒฐ์ ์ค๋น", description = "์นด์นด์คํ์ด ๋ฑ ๊ฒฐ์ ์๋จ์ ์ค๋นํ๋ค.") | ||
@PostMapping("/ready") | ||
public ResponseCustom<ReadyResponse> payReady(Authentication authentication, @RequestBody PayRequest payRequest) { | ||
return ResponseCustom.OK( | ||
paymentProcessingService.processPayment(AuthenticationParser.parseUserId(authentication), payRequest)); | ||
} | ||
|
||
@Operation(summary = "๊ฒฐ์ ์ฑ๊ณต", description = "๊ฒฐ์ ์ฑ๊ณต") | ||
@GetMapping("/success") | ||
public ResponseCustom<ApproveResponse> afterPayRequest(@RequestParam("pg_token") String pgToken) { | ||
return ResponseCustom.OK( | ||
paymentProcessingService.processSuccess(pgToken)); | ||
} | ||
|
||
@Operation(summary = "๊ฒฐ์ ์ทจ์", description = "๊ฒฐ์ ์งํ ์ค์ ์ทจ์๋๋ ๊ฒฝ์ฐ") | ||
@GetMapping("/cancel") | ||
public void cancel() { | ||
throw new PaymentCancellationException(); | ||
} | ||
|
||
@Operation(summary = "๊ฒฐ์ ์คํจ", description = "๊ฒฐ์ ์ ์คํจํ๋ ๊ฒฝ์ฐ") | ||
@GetMapping("/fail") | ||
public void fail() { | ||
throw new PaymentFailedException(); | ||
} | ||
} |