Skip to content

Commit

Permalink
YEL-155 [develop] 개발 서버 배포
Browse files Browse the repository at this point in the history
YEL-155 [develop] 개발 서버 배포
  • Loading branch information
hyeonjeongs authored Sep 12, 2023
2 parents 03093bf + 25bb580 commit ea6a9a0
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ void handleAppleTransactionError(ResponseEntity<TransactionInfoResponse> respons

void changeSubscriptionStatus(AppleNotificationPayloadVO payloadVO);

void refundAppleInApp(AppleNotificationPayloadVO payloadVO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import static com.yello.server.global.common.ErrorCode.APPLE_TOKEN_SERVER_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.GOOGLE_SUBSCRIPTIONS_SUBSCRIPTION_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.NOT_FOUND_TRANSACTION_EXCEPTION;
import static com.yello.server.global.common.util.ConstantUtil.REFUND_FIVE_TICKET;
import static com.yello.server.global.common.util.ConstantUtil.REFUND_ONE_TICKET;
import static com.yello.server.global.common.util.ConstantUtil.REFUND_TWO_TICKET;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yello.server.domain.purchase.dto.apple.AppleNotificationPayloadVO;
Expand Down Expand Up @@ -68,7 +71,7 @@ public void handleAppleTransactionError(ResponseEntity<TransactionInfoResponse>

@Override
public AppleNotificationPayloadVO decodeApplePayload(String signedPayload) {

Map<String, Object> jsonPayload = DecodeTokenFactory.decodeToken(signedPayload);
ObjectMapper objectMapper = new ObjectMapper();

Expand Down Expand Up @@ -117,5 +120,35 @@ public void changeSubscriptionStatus(AppleNotificationPayloadVO payloadVO) {
}
}

@Override
public void refundAppleInApp(AppleNotificationPayloadVO payloadVO) {
String transactionId =
decodeAppleNotificationData(payloadVO.data().signedTransactionInfo());
Purchase purchase = purchaseRepository.findByTransactionId(transactionId)
.orElseThrow(() -> new PurchaseNotFoundException(NOT_FOUND_TRANSACTION_EXCEPTION));
User user = purchase.getUser();

switch (purchase.getProductType()) {
case YELLO_PLUS -> {
user.setSubscribe(Subscribe.NORMAL);
}
case ONE_TICKET -> {
validateTicketCount(REFUND_ONE_TICKET, user);
}
case TWO_TICKET -> {
validateTicketCount(REFUND_TWO_TICKET, user);
}
case FIVE_TICKET -> {
validateTicketCount(REFUND_FIVE_TICKET, user);
}
}
}

public void validateTicketCount(int ticketCount, User user) {
if (user.getTicketCount() >= ticketCount) {
user.setTicketCount(-Math.abs(ticketCount));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void verifyAppleSubscriptionTransaction(Long userId,
}

purchaseManager.createSubscribe(user, Gateway.APPLE, request.transactionId());
user.addTicketCount(3);
user.setTicketCount(3);
}

@Transactional
Expand All @@ -126,17 +126,17 @@ public void verifyAppleTicketTransaction(Long userId, AppleTransaction request)
case ONE_TICKET_ID:
purchaseManager.createTicket(user, ProductType.ONE_TICKET, Gateway.APPLE,
request.transactionId());
user.addTicketCount(1);
user.setTicketCount(1);
break;
case TWO_TICKET_ID:
purchaseManager.createTicket(user, ProductType.TWO_TICKET, Gateway.APPLE,
request.transactionId());
user.addTicketCount(2);
user.setTicketCount(2);
break;
case FIVE_TICKET_ID:
purchaseManager.createTicket(user, ProductType.FIVE_TICKET, Gateway.APPLE,
request.transactionId());
user.addTicketCount(5);
user.setTicketCount(5);
break;
default:
throw new PurchaseException(NOT_FOUND_TRANSACTION_EXCEPTION);
Expand Down Expand Up @@ -206,7 +206,7 @@ public GoogleSubscriptionGetResponse verifyGoogleSubscriptionTransaction(Long us
case ConstantUtil.GOOGLE_PURCHASE_SUBSCRIPTION_ACTIVE -> {
final Purchase subscribe =
purchaseManager.createSubscribe(user, Gateway.GOOGLE, request.orderId());
user.addTicketCount(3);
user.setTicketCount(3);
subscribe.setTransactionId(request.orderId());
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public GoogleTicketGetResponse verifyGoogleTicketTransaction(Long userId,
Purchase ticket =
purchaseManager.createTicket(user, getProductType(request.productId()),
Gateway.GOOGLE, request.orderId());
user.addTicketCount(getTicketAmount(request.productId()) * request.quantity());
user.setTicketCount(getTicketAmount(request.productId()) * request.quantity());
ticket.setTransactionId(inAppResponse.getBody().orderId());
} else {
throw new GoogleBadRequestException(GOOGLE_INAPP_BAD_REQUEST_EXCEPTION);
Expand Down Expand Up @@ -304,7 +304,7 @@ public void appleNotification(AppleNotificationRequest request) {
purchaseManager.changeSubscriptionStatus(payloadVO);
break;
case APPLE_NOTIFICATION_REFUND:
System.out.println("dd");
purchaseManager.refundAppleInApp(payloadVO);
break;
case APPLE_NOTIFICATION_TEST:
return;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/yello/server/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public static User of(SignUpRequest signUpRequest, School group) {
.group(group)
.groupAdmissionYear(signUpRequest.groupAdmissionYear())
.email(signUpRequest.email())
.deviceToken(Objects.equals(signUpRequest.deviceToken(), "") ? null : signUpRequest.deviceToken())
.deviceToken(Objects.equals(signUpRequest.deviceToken(), "") ? null
: signUpRequest.deviceToken())
.subscribe(Subscribe.NORMAL)
.ticketCount(0)
.build();
Expand Down Expand Up @@ -167,7 +168,7 @@ public void increaseRecommendPoint() {
}

public void plusPoint(Integer point) {
if (this.getSubscribe() == Subscribe.NORMAL) {
if (this.getSubscribe()==Subscribe.NORMAL) {
this.point += point;
return;
}
Expand All @@ -194,7 +195,7 @@ public void setSubscribe(Subscribe subscribe) {
this.subscribe = subscribe;
}

public void addTicketCount(int ticketCount) {
public void setTicketCount(int ticketCount) {
this.ticketCount += ticketCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public RevealFullNameResponse revealFullName(Long userId, Long voteId) {
}

vote.checkNameIndexOf(CHECK_FULL_NAME);
sender.addTicketCount(MINUS_TICKET_COUNT);
sender.setTicketCount(MINUS_TICKET_COUNT);

return RevealFullNameResponse.of(vote.getSender());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class ConstantUtil {
public static final String APPLE_NOTIFICATION_TEST = "TEST";
public static final String APPLE_SUBTYPE_AUTO_RENEW_DISABLED = "AUTO_RENEW_DISABLED";
public static final String APPLE_SUBTYPE_VOLUNTARY = "VOLUNTARY";
public static final int REFUND_ONE_TICKET = 1;
public static final int REFUND_TWO_TICKET = 2;
public static final int REFUND_FIVE_TICKET = 5;


private ConstantUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public String decodeAppleNotificationData(String signedTransactionInfo) {
public void changeSubscriptionStatus(AppleNotificationPayloadVO payloadVO) {

}

@Override
public void refundAppleInApp(AppleNotificationPayloadVO payloadVO) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void init() {
assertThat(user.getTicketCount()).isZero();

// when
user.addTicketCount(10);
user.setTicketCount(10);

// then
assertThat(user.getTicketCount()).isEqualTo(10);
Expand Down

0 comments on commit ea6a9a0

Please sign in to comment.