Skip to content

Commit

Permalink
Merge pull request #164 from WE-ARE-RACCOONS/RAC-304
Browse files Browse the repository at this point in the history
RAC-304 fix : Payple결제 취소시 리다이렉트 수정
  • Loading branch information
ywj9811 authored Mar 10, 2024
2 parents 60d02c3 + 2396ead commit 56f96a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Optional;

import static com.postgraduate.domain.payment.application.usecase.PaymentParameter.*;
import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseCode.PAYMENT_FAIL;
import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseMessage.FAIL_PAYMENT;
import static org.springframework.http.CacheControl.noCache;

@Service
Expand Down Expand Up @@ -61,9 +63,12 @@ public class PaymentManageUseCase {
private final SalaryGetService salaryGetService;
private final WebClient webClient;

public void savePay(PaymentResultRequest request) {
if (!request.PCD_PAY_RST().equals(SUCCESS.getName()))
throw new PaymentFailException();
public boolean savePay(PaymentResultRequest request) {
if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) {
log.error("PayPle 결제 진행 취소 및 오류");
log.error("message : {} code : {}", FAIL_PAYMENT.getMessage(), request.PCD_PAY_CODE());
return false;
}
try {
String seniorNickName = request.PCD_PAY_GOODS();
long userId = Long.parseLong(request.PCD_PAYER_NO());
Expand All @@ -78,6 +83,7 @@ public void savePay(PaymentResultRequest request) {
paymentSaveService.save(payment);
refundPay(payment);
}
return true;
}

public void refundPayByUser(User user, String orderId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.postgraduate.domain.payment.application.dto.req.PaymentResultRequest;
import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase;
import com.postgraduate.domain.senior.application.usecase.SeniorInfoUseCase;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,21 +19,34 @@
@Tag(name = "PAYMENT Controller", description = "")
public class PaymentController {
private final PaymentManageUseCase paymentManageUseCase;
private final SeniorInfoUseCase seniorInfoUseCase;
@Value("${payple.redirect-uri}")
private String redirectUri;
@Value("${payple.redirect-uri-dev}")
private String redirectUriDev;
@Value("${payple.cancel-redirect-uri}")
private String cancelRedirectUri;
@Value("${payple.cancel-redirect-uri-dev}")
private String cancelRedirectUriDev;

@PostMapping("/payple/result")
public void resultGet(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException {
paymentManageUseCase.savePay(request);
response.sendRedirect(redirectUri + request.PCD_PAY_OID());
if (paymentManageUseCase.savePay(request)) {
response.sendRedirect(redirectUri + request.PCD_PAY_OID());
return;
}
Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS());
response.sendRedirect(cancelRedirectUri + seniorId);
}

@PostMapping("/payple/dev/result")
public void resultGetWithDev(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException {
paymentManageUseCase.savePay(request);
response.sendRedirect(redirectUriDev + request.PCD_PAY_OID());
if (paymentManageUseCase.savePay(request)) {
response.sendRedirect(redirectUriDev + request.PCD_PAY_OID());
return;
}
Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS());
response.sendRedirect(cancelRedirectUriDev + seniorId);
}

@PostMapping("/webhook")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ public AllSeniorIdResponse getAllSeniorId() {
.toList();
return new AllSeniorIdResponse(seniorIds);
}

public Long getSeniorId(String nickName) {
Senior senior = seniorGetService.bySeniorNickName(nickName);
return senior.getSeniorId();
}
}

0 comments on commit 56f96a1

Please sign in to comment.