Skip to content

Commit

Permalink
feat: calculate charge
Browse files Browse the repository at this point in the history
  • Loading branch information
Kang1221 committed Aug 20, 2024
1 parent a667d23 commit 53629ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/co/orange/ddanzi/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class OrderService {
@Autowired
TermService termService;
@Autowired
PaymentService paymentService;
@Autowired
OrderOptionDetailService orderOptionDetailService;


Expand All @@ -58,6 +60,8 @@ public ApiResponse<?> checkOrderProduct(String productId){
Discount discount = discountRepository.findById(productId).orElse(null);

User user = authUtils.getUser();
Integer salePrice = product.getOriginPrice() - discount.getDiscountPrice();
Integer charge = paymentService.calculateCharge(salePrice);

CheckProductResponseDto responseDto = CheckProductResponseDto.builder()
.itemId(item.getId())
Expand All @@ -67,8 +71,8 @@ public ApiResponse<?> checkOrderProduct(String productId){
.originPrice(product.getOriginPrice())
.addressInfo(addressService.setAddressInfo(user))
.discountPrice(discount.getDiscountPrice())
.charge(100)
.totalPrice(product.getOriginPrice() - discount.getDiscountPrice())
.charge(charge)
.totalPrice(salePrice+charge)
.build();
return ApiResponse.onSuccess(Success.GET_ORDER_PRODUCT_SUCCESS, responseDto);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/co/orange/ddanzi/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ public ApiResponse<?> endPayment(UpdatePaymentRequestDto requestDto){
return ApiResponse.onSuccess(Success.PATCH_PAYMENT_STATUS_SUCCESS, responseDto);
}

public Integer calculateCharge(Integer salePrice){
return (int) Math.floor(salePrice*0.032);
}

private boolean isAvailableToChangePayment(Payment payment){
User user = authUtils.getUser();
if(payment.getBuyer().equals(user) && payment.getPayStatus().equals(PayStatus.PENDING))
return true;
else
return false;
}

}

0 comments on commit 53629ef

Please sign in to comment.