Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#199, #198] 환불 API 작성, Payment 도메인 수정 #200

Merged
merged 29 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c55af3b
refactor: PaymentSaveResponse -> PaymentPendingResponse 네이밍 변경, Payme…
Joyykim Jul 29, 2021
78efff0
feat: Payment 환불 도메인 로직 작성
Joyykim Jul 29, 2021
5bc76ae
feat: Payment 환불 컨트롤러,서비스 로직 작성
Joyykim Jul 29, 2021
dd89c27
feat: 환불API js코드예시 작성
Joyykim Jul 29, 2021
4f191a1
Merge branch 'develop-server' of https://github.com/woowacourse-teams…
Joyykim Jul 29, 2021
d0a756b
refactor: PaymentService#cancelPayment의 불필요한 로직 정리
Joyykim Jul 29, 2021
1f48d36
refactor: PaymentCancelRequest의 환불금액 필드 제거
Joyykim Jul 29, 2021
6e3d048
test: Payment 도메인 테스트 작성
Joyykim Jul 29, 2021
8b397ce
feat: Payment의 id 타입을 UUID로 변경
Joyykim Jul 29, 2021
6611c32
feat: Payment 관련 DTO의 merchantUid 타입을 UUID로 변경, 더이상 사용되지 않는 DonationR…
Joyykim Jul 29, 2021
e79a835
Merge branch 'develop-server' of https://github.com/woowacourse-teams…
Joyykim Jul 29, 2021
fe9121f
fix: request dto에서 UUID를 받지 못하는 이슈 해결
Joyykim Jul 29, 2021
8c57263
fix: PaymentNotFoundException 메시지/에러코드 수정, 사용되지 않는 PaymentRequestExce…
Joyykim Jul 30, 2021
6c4c108
refactor: IllegalPaymentInfoException 예외메시지 수정
Joyykim Jul 30, 2021
a3f1bcc
fix: 환불요청dto 유효성검사 실패시 PaymentCancelRequestException 발생하도록 변경
Joyykim Jul 30, 2021
b83ca46
test: Payment 컨트롤러 테스트케이스 추가
Joyykim Jul 30, 2021
049e8e1
refactor: convertToPaymentInfo 수정
Joyykim Jul 30, 2021
50f6f00
feat: Payment id타입 Long으로 변경, merchantUid UUID타입 컬럼 추가
Joyykim Jul 30, 2021
625bb3a
Merge branch 'develop-server' into feature/iamport-cancel-payment-api
DWL5 Jul 30, 2021
3847a07
Merge branch 'develop-server' of https://github.com/woowacourse-teams…
Joyykim Jul 30, 2021
2a674e2
Merge remote-tracking branch 'origin/feature/iamport-cancel-payment-a…
Joyykim Jul 30, 2021
155311f
style: 리포매팅
Joyykim Jul 30, 2021
a9ad935
refactor: PaymentRequest -> PaymentCompleteRequest 리네임
Joyykim Jul 30, 2021
8242c01
refactor: 사용되지 않는 클래스 제거
Joyykim Jul 30, 2021
2638b42
refactor: 환불요청 dto의 merchantUid 타입 UUID로 변경
Joyykim Jul 30, 2021
f31567f
feat: Payment의 merchantUid 컬럼 nullable=false 추가
Joyykim Jul 30, 2021
8e94396
feat: UUID 커스텀 Validator 생성, DTO의 merchantUid를 String타입으로 변경
Joyykim Jul 30, 2021
05a161b
refactor: 스네이크케이스 -> 카멜케이스로 변경
Joyykim Jul 31, 2021
49fcdac
feat: UUIDValidator null 검증 추가, 테스트작성
Joyykim Jul 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/securityKey
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.tyfserver.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.util.Base64;
import com.example.tyfserver.common.exception.S3FileNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.example.tyfserver.donation.exception.DonationMessageRequestException;
import com.example.tyfserver.donation.exception.DonationRequestException;
import com.example.tyfserver.donation.service.DonationService;
import com.example.tyfserver.payment.dto.PaymentRequest;
import com.example.tyfserver.payment.dto.PaymentCompleteRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
Expand All @@ -25,11 +25,11 @@ public class DonationController {
private final DonationService donationService;

@PostMapping
public ResponseEntity<DonationResponse> createDonation(@Valid @RequestBody PaymentRequest paymentRequest, BindingResult result) {
public ResponseEntity<DonationResponse> createDonation(@Valid @RequestBody PaymentCompleteRequest paymentCompleteRequest, BindingResult result) {
if (result.hasErrors()) {
throw new DonationRequestException();
}
return ResponseEntity.status(HttpStatus.CREATED).body(donationService.createDonation(paymentRequest));
return ResponseEntity.status(HttpStatus.CREATED).body(donationService.createDonation(paymentCompleteRequest));
}

@PostMapping("/{donationId}/messages")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.example.tyfserver.member.exception.MemberNotFoundException;
import com.example.tyfserver.member.repository.MemberRepository;
import com.example.tyfserver.payment.domain.Payment;
import com.example.tyfserver.payment.dto.PaymentRequest;
import com.example.tyfserver.payment.dto.PaymentCompleteRequest;
import com.example.tyfserver.payment.service.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
Expand All @@ -28,8 +28,8 @@ public class DonationService {
private final MemberRepository memberRepository;
private final PaymentService paymentService;

public DonationResponse createDonation(PaymentRequest paymentRequest) {
Payment payment = paymentService.completePayment(paymentRequest);
public DonationResponse createDonation(PaymentCompleteRequest paymentCompleteRequest) {
Payment payment = paymentService.completePayment(paymentCompleteRequest);
Donation donation = new Donation(payment);
Member member = memberRepository.findByPageName(payment.getPageName())
.orElseThrow(MemberNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.example.tyfserver.member.exception.PageNameValidationRequestException;
import com.example.tyfserver.member.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void updateNickName(LoginMember loginMember, String nickName) {

private Member findMember(Long id) {
return memberRepository.findById(id)
.orElseThrow(MemberNotFoundException::new);
.orElseThrow(MemberNotFoundException::new);
}

private void deleteProfile(Member member) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.tyfserver.payment.controller;

import com.example.tyfserver.payment.dto.PaymentSaveRequest;
import com.example.tyfserver.payment.dto.PaymentSaveResponse;
import com.example.tyfserver.payment.exception.PaymentRequestException;
import com.example.tyfserver.payment.exception.PaymentSaveRequestException;
import com.example.tyfserver.payment.dto.PaymentCancelRequest;
import com.example.tyfserver.payment.dto.PaymentCancelResponse;
import com.example.tyfserver.payment.dto.PaymentPendingRequest;
import com.example.tyfserver.payment.dto.PaymentPendingResponse;
import com.example.tyfserver.payment.exception.PaymentCancelRequestException;
import com.example.tyfserver.payment.exception.PaymentPendingRequestException;
import com.example.tyfserver.payment.service.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -23,13 +25,23 @@ public class PaymentController {
private final PaymentService paymentService;

@PostMapping
public ResponseEntity<PaymentSaveResponse> payment(@Valid @RequestBody PaymentSaveRequest paymentSaveRequest, BindingResult result) {
public ResponseEntity<PaymentPendingResponse> payment(@Valid @RequestBody PaymentPendingRequest paymentPendingRequest, BindingResult result) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PayementStatus에 Pending 상태로 저장되니까
PayemntPendingRequest 좋은것 같아!

if (result.hasErrors()) {
throw new PaymentPendingRequestException();
}

PaymentPendingResponse response = paymentService.createPayment(paymentPendingRequest);
return ResponseEntity.ok(response);
}

// todo 환불시 이메일 인증 필요
@PostMapping("/cancel")
public ResponseEntity<PaymentCancelResponse> cancelPayment(@Valid @RequestBody PaymentCancelRequest paymentCancelRequest, BindingResult result) {
if (result.hasErrors()) {
throw new PaymentSaveRequestException();
throw new PaymentCancelRequestException();
}

PaymentSaveResponse response = paymentService.createPayment(paymentSaveRequest);
PaymentCancelResponse response = paymentService.cancelPayment(paymentCancelRequest);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.example.tyfserver.common.domain.BaseTimeEntity;
import com.example.tyfserver.payment.exception.IllegalPaymentInfoException;
import com.example.tyfserver.payment.exception.PaymentRequestException;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.UUID;

import static com.example.tyfserver.payment.exception.PaymentRequestException.*;
import static com.example.tyfserver.payment.exception.IllegalPaymentInfoException.*;

@Entity
@Getter
Expand All @@ -33,15 +33,36 @@ public class Payment extends BaseTimeEntity {

private String impUid;

public Payment(Long id, Long amount, String email, String pageName) {
@Column(nullable = false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿!! merchantUid는 null이 아니어야 하지

private UUID merchantUid;

@PrePersist
protected void onCreate() {
merchantUid = UUID.randomUUID();
}

public Payment(Long id, Long amount, String email, String pageName, UUID merchantUid) {
this.id = id;
this.amount = amount;
this.email = email;
this.pageName = pageName;
this.merchantUid = merchantUid;
}

public Payment(Long amount, String email, String pageName, UUID merchantUid) {
this(null, amount, email, pageName, merchantUid);
}

public Payment(Long id, Long amount, String email, String pageName) {
this(id, amount, email, pageName, null);
}

public Payment(Long amount, String email, String pageName) {
this(null, amount, email, pageName);
this(null, amount, email, pageName, null);
}

public void updateStatus(PaymentStatus paymentStatus) {
this.status = paymentStatus;
}

public void complete(PaymentInfo paymentInfo) {
Expand All @@ -50,21 +71,32 @@ public void complete(PaymentInfo paymentInfo) {
this.status = PaymentStatus.PAID;
}

public void updateStatus(PaymentStatus paymentStatus) {
this.status = paymentStatus;
}

private void validatePaymentComplete(PaymentInfo paymentInfo) {
if (!PaymentStatus.isPaid(paymentInfo.getStatus())) {
updateStatus(paymentInfo.getStatus());
throw IllegalPaymentInfoException.from(IllegalPaymentInfoException.ERROR_CODE_NOT_PAID, paymentInfo.getModule());
throw IllegalPaymentInfoException.from(ERROR_CODE_NOT_PAID, paymentInfo.getModule());
}

validatePaymentInfo(paymentInfo);
}

public void cancel(PaymentInfo paymentInfo) {
validatePaymentCancel(paymentInfo);
this.impUid = paymentInfo.getImpUid();
this.status = PaymentStatus.CANCELLED;
}
Comment on lines +83 to +87
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancel 메서드 내부에서 호출되는 private 메서드 validatePaymentCancel이 cancel() 메서드보다 상단에 위치하는 것 같은데, 이 위치를 바꾸는게 어떨까?

관련자료: 클린코드5 형식 맞추기 - 종속 함수 부분

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엥 이미 하단인데? 혹시 커밋별로 보느라 옛날걸 보고있어서 그런건가!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 이부분은 내가 이전껄 봤나봐 👀


private void validatePaymentCancel(PaymentInfo paymentInfo) {
if (!PaymentStatus.isCancelled(paymentInfo.getStatus())) {
updateStatus(paymentInfo.getStatus());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancel이 아니라면 그냥 그대로 결제된 상태일테지만 확실히 하기위해서 update 해주는거야?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아 혹시몰라서 다시 동기화를 시켜주려고

throw IllegalPaymentInfoException.from(ERROR_CODE_NOT_CANCELLED, paymentInfo.getModule());
}

validatePaymentInfo(paymentInfo);
}

private void validatePaymentInfo(PaymentInfo paymentInfo) {
if (!id.equals(paymentInfo.getMerchantId())) {
if (!merchantUid.equals(paymentInfo.getMerchantUid())) {
updateStatus(PaymentStatus.INVALID);
throw IllegalPaymentInfoException.from(ERROR_CODE_INVALID_MERCHANT_ID, paymentInfo.getModule());
}
Expand All @@ -76,7 +108,7 @@ private void validatePaymentInfo(PaymentInfo paymentInfo) {

if (!pageName.equals(paymentInfo.getPageName())) {
updateStatus(PaymentStatus.INVALID);
throw IllegalPaymentInfoException.from(ERROR_INVALID_CREATOR, paymentInfo.getModule());
throw IllegalPaymentInfoException.from(ERROR_CODE_INVALID_CREATOR, paymentInfo.getModule());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.example.tyfserver.payment.domain;

import com.example.tyfserver.payment.util.IamPortPaymentServiceConnector;
import lombok.Getter;

import java.util.UUID;

@Getter
public class PaymentInfo {
private Long merchantId;
private UUID merchantUid;
private PaymentStatus status;
private Long amount;
private String pageName;
private String impUid;
private String module;

public PaymentInfo(Long merchantId, PaymentStatus status, Long amount, String pageName, String impUid, String module) {
this.merchantId = merchantId;
public PaymentInfo(UUID merchantUid, PaymentStatus status, Long amount, String pageName, String impUid, String module) {
this.merchantUid = merchantUid;
this.status = status;
this.amount = amount;
this.pageName = pageName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.tyfserver.payment.domain;

import com.example.tyfserver.payment.dto.PaymentRequest;
import java.util.UUID;

public interface PaymentServiceConnector {
PaymentInfo requestPaymentInfo(PaymentRequest paymentRequest);

PaymentInfo requestPaymentInfo(UUID merchantUid);

PaymentInfo requestPaymentCancel(UUID merchantUid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public enum PaymentStatus {
}

public static boolean isPaid(PaymentStatus paymentStatus) {
if (paymentStatus.equals(PAID)) {
return true;
}
return false;
return paymentStatus.equals(PAID);
}

public static boolean isCancelled(PaymentStatus paymentStatus) {
return paymentStatus.equals(CANCELLED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public class IamPortPaymentInfo {
public IamPortPaymentInfo(Response response) {
this.response = response;
}

@NoArgsConstructor
@Getter
public class Response {
public static class Response {
String status;
String merchant_uid;
String merchantUid;
String amount;
String name;
String imp_uid;
String impUid;

public Response(String status, String merchant_uid, String amount, String name, String imp_uid) {
public Response(String status, String merchantUid, String amount, String name, String impUid) {
this.status = status;
this.merchant_uid = merchant_uid;
this.merchantUid = merchantUid;
this.amount = amount;
this.name = name;
this.imp_uid = imp_uid;
this.impUid = impUid;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.tyfserver.payment.dto;

import com.example.tyfserver.payment.util.UUID;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PaymentCancelRequest {

@UUID
private String merchantUid;

public PaymentCancelRequest(String merchantUid) {
this.merchantUid = merchantUid;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 UUID로 다시 바꾸었구나!

UUID를 사용할때, UUID아닌 형식이 오면 org.springframework.http.converter.HttpMessageNotReadableException 이렇게 와서 우리가 커스텀 예외로 처리가 불가능 하니

String 으로 변경해서 Validator를 만든다는 거지??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 프론트에서 String으로 보낼 것 같은뒤

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게... 프론트에서는 String라고 생각하고 보낼거 같은데 🤔 (아임포트에 String으로 명시돼 있었으니까..?)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.tyfserver.payment.dto;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PaymentCancelResponse {

private UUID merchantUid;

public PaymentCancelResponse(UUID merchantUid) {
this.merchantUid = merchantUid;
}
}