Skip to content

Commit

Permalink
fix: payment fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 6, 2024
1 parent 48a7231 commit 0627276
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Map<LocalDate, List<OrderInfo>> findAllOrdersByDate(String accessToken) {
Integer price = 0;
for (OrderItem o : orderItems) {
Menu singleMenu = menuQueryService.findMenuById(o.getMenu().getId());
price += singleMenu.getPrice();
price += singleMenu.getPrice() * o.getQuantity();
}

OrderInfo orderInfo = new OrderInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
Expand All @@ -49,18 +51,21 @@ public void approval(String accessToken, ApprovalRequest request) {
User user = userQueryService.findByEmail(email);

List<Menu> menuList = new ArrayList<>();
Map<Long, Integer> menuQuantityMap = new HashMap<>();

for (Long id : request.cartIds()) {
Cart cart = cartQueryService.findCartById(id);
Menu menu = menuQueryService.findMenuById(cart.getMenu().getId());
menuList.add(menu);
menuQuantityMap.put(menu.getId(), cart.getQuantity());

cartQueryService.deleteCartByUserIdAndCartId(user.getUserId(), id);
}

Store store = storeQueryService.findStoreById(menuList.get(0).getId());

// 토스 페이 결제 승인
// TossPaymentResponse tossPaymentResponse = paymentClient.confirmPayment(request);
// TossPaymentResponse tossPaymentResponse = paymentClient.confirmPayment(request);

// 방문 리스트 결제 완료로 저장 + 주문 테이블 저장
marketQueryService.saveVisitListToPayment(store.getId(), user.getEmail());
Expand All @@ -71,17 +76,16 @@ public void approval(String accessToken, ApprovalRequest request) {
orderQueryService.saveOrder(order);

for (Menu value : menuList) {

Long m = value.getId();
Menu menu = menuQueryService.findMenuById(m);
Cart cart = cartQueryService.findCartByMenuId(menu.getId());
int quantity = cart.getQuantity();
Long menuId = value.getId();
Menu menu = menuQueryService.findMenuById(menuId);
int quantity = menuQuantityMap.get(menuId);

final OrderItem orderItem = OrderItem.builder().order(order).menu(menu).quantity(quantity).build();
orderQueryService.saveOrderItem(orderItem);
}
}


public String generateOrderNumber(LocalDateTime createdAt) {
String datePart = createdAt.format(ORDER_NUMBER_DATE_FORMAT);
String randomAlphaNumeric = generateRandomAlphaNumeric();
Expand Down

0 comments on commit 0627276

Please sign in to comment.