Skip to content

Commit

Permalink
[REFACTOR] 토스페이 결제 redirect 설정 추가 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyukong authored Mar 10, 2024
1 parent fc1d16f commit 72749b9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.oya.kr.payment.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.oya.kr.payment.service.TossPayService;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

/**
* @author 김유빈
* @since 2024.03.10
*/
@Controller
@RequestMapping("/api/v1/payments/toss")
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class TossPayCallbackController {

private final TossPayService tossPayService;

@Value("${payment.toss.success-callback}")
private String successCallback;

@Value("${payment.toss.fail-callback}")
private String failCallback;

/**
* 토스페이 결제 승인 시 성공 콜백
*
* @parameter String, String, String, Long
* @return String
* @author 김유빈
* @since 2024.02.29
*/
@GetMapping("/success")
public String success(
@RequestParam String orderId,
@RequestParam String paymentType,
@RequestParam String paymentKey,
@RequestParam Long amount
) {
tossPayService.success(orderId, paymentType, paymentKey, amount);
return String.format("redirect:%s", successCallback);
}

/**
* 토스페이 결제 에러 시 실패 콜백
*
* @return String
* @author 김유빈
* @since 2024.02.29
*/
@GetMapping("/fail")
public String fail() {
tossPayService.fail();
return String.format("redirect:%s", failCallback);
}
}
34 changes: 0 additions & 34 deletions src/main/java/com/oya/kr/payment/controller/TossPayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import java.security.Principal;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -45,36 +43,4 @@ public ResponseEntity<ApplicationResponse<Void>> confirm(
tossPayService.confirm(principal.getName(), request, mainImage);
return ResponseEntity.ok(ApplicationResponse.success(null));
}

/**
* 토스페이 결제 승인 시 성공 콜백
*
* @parameter String, String, String, Long
* @return ResponseEntity<ApplicationResponse<Void>>
* @author 김유빈
* @since 2024.02.29
*/
@GetMapping("/success")
public ResponseEntity<ApplicationResponse<Void>> success(
@RequestParam String orderId,
@RequestParam String paymentType,
@RequestParam String paymentKey,
@RequestParam Long amount
) {
tossPayService.success(orderId, paymentType, paymentKey, amount);
return ResponseEntity.ok(ApplicationResponse.success(null));
}

/**
* 토스페이 결제 에러 시 실패 콜백
*
* @return ResponseEntity<ApplicationResponse<Void>>
* @author 김유빈
* @since 2024.02.29
*/
@GetMapping("/fail")
public ResponseEntity<ApplicationResponse<Void>> fail() {
tossPayService.fail();
return ResponseEntity.ok(ApplicationResponse.success(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public void success(String orderId, String paymentType, String paymentKey, Long
}
communityRepository.updateAdPaymentKey(orderId, paymentKey);
}
// todo: redirect
}

/**
Expand Down

0 comments on commit 72749b9

Please sign in to comment.