Files

File: src/main/java/com/paymentlink/service/ShippingService.java

1 package com.paymentlink.service;
2
3 import org.springframework.stereotype.Service;
4
5 @Service
6 public class ShippingService {
7
8 /**
9 * Calculate shipping cost based on method and country
10 */
11 public long calculateShippingCost(String method, String country) {
12 if (method == null || method.isEmpty()) {
13 method = "standard";
14 }
15
16 // Base rates in cents
17 long baseRate = switch (method.toLowerCase()) {
18 case "express" -> 2000; // $20
19 case "overnight" -> 3500; // $35
20 default -> 1000; // $10 for standard
21 };
22
23 // International shipping surcharge
24 if (country != null && !country.equals("US")) {
25 baseRate += 1500; // $15 surcharge
26 }
27
28 return baseRate;
29 }
30
31 /**
32 * Get available shipping methods
33 */
34 public String[] getAvailableShippingMethods() {
35 return new String[]{"standard", "express", "overnight"};
36 }
37
38 /**
39 * Validate shipping method
40 */
41 public boolean isValidShippingMethod(String method) {
42 if (method == null) return false;
43 String lower = method.toLowerCase();
44 return lower.equals("standard") || lower.equals("express") || lower.equals("overnight");
45 }
46 }
47
48