Skip to content

Commit

Permalink
Merge pull request #229 from readyvery/test
Browse files Browse the repository at this point in the history
0327 배포
  • Loading branch information
marinesnow34 authored Mar 26, 2024
2 parents cb14a62 + aa09623 commit 522eba8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public class Constant {
public static final Integer MAX_FASTORDER_SIZE = 5;
public static final String TOSSPAYMENT_SUCCESS_MESSAGE = "결제 성공";
public static final String MEMBERSHIP_PAYMENT_METHOD = "membership";
public static final String TOSS_RESPONSE_FAIL_CANCELED = "ALREADY_CANCELED_PAYMENT";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
Expand Down Expand Up @@ -484,6 +485,22 @@ private TosspaymentDto requestTossPaymentCancel(String paymentKey) {
return restTemplate.postForObject(TossPaymentConfig.PAYMENT_URL + paymentKey + "/cancel",
new HttpEntity<>(params, headers),
TosspaymentDto.class);
} catch (HttpClientErrorException e) {
/*
* 취소 실패 시, 이미 취소된 거래라면 결제 정보 조회
* 취소된 정보 재적용
*/
if (e.getResponseBodyAs(FailDto.class).getCode()
.equals(TOSS_RESPONSE_FAIL_CANCELED)) {
return restTemplate.exchange(
TossPaymentConfig.PAYMENT_URL + paymentKey,
HttpMethod.GET,
new HttpEntity<>(headers),
TosspaymentDto.class)
.getBody();
}
throw new BusinessLogicException(ExceptionCode.TOSS_PAYMENT_SUCCESS_FAIL);

} catch (Exception e) {
log.error("e.getMessage() = " + e.getMessage());
throw new BusinessLogicException(ExceptionCode.TOSS_PAYMENT_SUCCESS_FAIL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.readyvery.readyverydemo.src.order.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@RequiredArgsConstructor
public class FailDto {
private String code;
private String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class VerificationService {

public String createVerificationCode(String phoneNumber, boolean someBooleanValue) {
String code = UUID.randomUUID().toString().substring(0, 6);
redisTemplate.opsForValue().set(phoneNumber + ":code", code, 5, TimeUnit.MINUTES);
redisTemplate.opsForValue().set(phoneNumber + ":flag", String.valueOf(someBooleanValue), 5, TimeUnit.MINUTES);
redisTemplate.opsForValue().set(phoneNumber + ":code", code, 3, TimeUnit.MINUTES);
redisTemplate.opsForValue().set(phoneNumber + ":flag", String.valueOf(someBooleanValue), 3, TimeUnit.MINUTES);
return code;
}

Expand All @@ -28,7 +28,7 @@ public boolean verifyCode(String phoneNumber, String code) {
String storedCode = redisTemplate.opsForValue().get(storedCodeKey);
if (storedCode != null && storedCode.equals(code)) {
// 인증 코드가 일치하면 플래그 값을 true로 설정
redisTemplate.opsForValue().set(flagKey, "true", 5, TimeUnit.MINUTES);
redisTemplate.opsForValue().set(flagKey, "true", 3, TimeUnit.MINUTES);
return true;
} else {
return false;
Expand Down

0 comments on commit 522eba8

Please sign in to comment.