Merge pull request #307 from RecentRunner/web-v2
merge web-v2
This commit was merged in pull request #307.
This commit is contained in:
@@ -75,6 +75,16 @@ public class CartController {
|
||||
return ResponseEntity.ok(cartService.applyCoupon(userId, storeId, request.getCouponCode()));
|
||||
}
|
||||
|
||||
@PostMapping("/apply-points")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public ResponseEntity<CartResponse> applyPoints(
|
||||
@RequestParam Long storeId,
|
||||
@RequestParam Boolean useLoyaltyPoints) {
|
||||
Long userId = AuthenticationHelper.getAuthenticatedUserId();
|
||||
|
||||
return ResponseEntity.ok(cartService.applyPoints(userId, storeId, useLoyaltyPoints));
|
||||
}
|
||||
|
||||
@DeleteMapping("/coupon")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public ResponseEntity<CartResponse> removeCoupon(@RequestParam Long storeId) {
|
||||
|
||||
@@ -257,6 +257,34 @@ public class CartService {
|
||||
.setScale(0, RoundingMode.HALF_UP)
|
||||
.longValue();
|
||||
|
||||
// Free checkout: total is $0.00, or points are applied and the remaining
|
||||
// amount is below Stripe's $0.50 minimum (cannot be charged via card)
|
||||
if (amountInCents == 0 || (amountInCents < 50 && Boolean.TRUE.equals(cart.getPointsApplied()))) {
|
||||
SaleRequest saleRequest = new SaleRequest();
|
||||
saleRequest.setStoreId(cart.getStore().getStoreId());
|
||||
saleRequest.setCustomerId(cart.getUser().getId());
|
||||
saleRequest.setCartId(cart.getCartId());
|
||||
saleRequest.setCouponId(cart.getCoupon() != null ? cart.getCoupon().getCouponId() : null);
|
||||
saleRequest.setPaymentMethod("Points");
|
||||
saleRequest.setChannel("WEBSITE");
|
||||
saleRequest.setItems(items.stream()
|
||||
.map(item -> {
|
||||
SaleItemRequest sir = new SaleItemRequest();
|
||||
sir.setProdId(item.getProduct().getProdId());
|
||||
sir.setQuantity(item.getQuantity());
|
||||
return sir;
|
||||
})
|
||||
.toList());
|
||||
|
||||
saleService.createSale(saleRequest);
|
||||
|
||||
cart.setCartStatus("CHECKED_OUT");
|
||||
cart.setCheckoutPending(false);
|
||||
cartRepository.save(cart);
|
||||
|
||||
return new CheckoutResponse(cart.getCartId(), null, BigDecimal.ZERO, "succeeded");
|
||||
}
|
||||
|
||||
if (amountInCents < 50) {
|
||||
throw new BusinessException("Order total is too low to process payment");
|
||||
}
|
||||
@@ -489,10 +517,12 @@ public class CartService {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
BigDecimal maxRedeemable = remainingAmount.setScale(0, RoundingMode.DOWN);
|
||||
return BigDecimal.valueOf(wholeDollars)
|
||||
.min(maxRedeemable)
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal maxDiscount = BigDecimal.valueOf(wholeDollars);
|
||||
// If points can fully cover the remaining amount, discount the entire total to $0.00
|
||||
if (maxDiscount.compareTo(remainingAmount) >= 0) {
|
||||
return remainingAmount.setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
return maxDiscount.setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private CartResponse toResponse(Cart cart) {
|
||||
|
||||
Reference in New Issue
Block a user