-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #140 [FEAT] 결제하기 api: 결제 금액 검증 로직 추가
#140 [FEAT] 결제하기 api: 결제 금액 검증 로직 추가
- Loading branch information
Showing
5 changed files
with
75 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
server/src/main/java/org/tattour/server/domain/order/model/OrderAmount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.tattour.server.domain.order.model; | ||
|
||
import lombok.Getter; | ||
import org.tattour.server.domain.sticker.provider.vo.StickerOrderInfo; | ||
import org.tattour.server.global.exception.BusinessException; | ||
import org.tattour.server.global.exception.ErrorType; | ||
|
||
@Getter | ||
public class OrderAmount { | ||
|
||
private final int productAmount; | ||
private final int shippingFee; | ||
private final int totalAmount; | ||
|
||
private OrderAmount(StickerOrderInfo stickerOrderInfo, int requestTotalAmount, | ||
int shippingFee) { | ||
int totalAmount = stickerOrderInfo.calculateTotalAmount(shippingFee); | ||
validate(requestTotalAmount, totalAmount); | ||
|
||
this.productAmount = stickerOrderInfo.calculateProductAmount(); | ||
this.shippingFee = shippingFee; | ||
this.totalAmount = totalAmount; | ||
} | ||
|
||
public static OrderAmount calculate(StickerOrderInfo stickerOrderInfo, int requestTotalAmount, | ||
int shippingFee) { | ||
return new OrderAmount(stickerOrderInfo, requestTotalAmount, shippingFee); | ||
} | ||
|
||
private void validate(int requestTotalAmount, int totalAmount) { | ||
if (isTotalAmountNotMatch(requestTotalAmount, totalAmount)) { | ||
throw new BusinessException(ErrorType.ORDER_AMOUNT_NOT_MATCH_EXCEPTION); | ||
} | ||
} | ||
|
||
private boolean isTotalAmountNotMatch(int requestTotalAmount, int totalAmount) { | ||
return requestTotalAmount != totalAmount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters