import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/calculateFee")
public class PayPalFeeCalculator extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
double amount = Double.parseDouble(request.getParameter("amount"));
double feePercentage = 2.9;
double fixedFee = 0.30;
double fee = amount * (feePercentage / 100) + fixedFee;
double total = amount - fee;
response.setContentType("application/json");
PrintWriter out = response.getWriter();
out.println("{");
out.println("\"fee\": " + fee + ",");
out.println("\"total\": " + total);
out.println("}");
out.close();
}
}
PayPal Fee Calculator
body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #4facfe, #00f2fe);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.calculator-container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
text-align: center;
width: 300px;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
label {
font-size: 18px;
margin-bottom: 10px;
}
input[type="number"] {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 20px;
width: 100%;
}
button {
background-color: #4facfe;
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #00c3ff;
}
#result {
margin-top: 20px;
font-size: 18px;
}
document.getElementById('calculatorForm').addEventListener('submit', function(e) {
e.preventDefault();
const amount = parseFloat(document.getElementById('amount').value);
fetch('/calculateFee', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'amount=' + amount
})
.then(response => response.json())
.then(data => {
document.getElementById('fee').textContent = '$' + data.fee.toFixed(2);
document.getElementById('total').textContent = '$' + data.total.toFixed(2);
})
.catch(error => console.error('Error:', error));
});
PayPalFeeCalculator/
├── src/
│ └── PayPalFeeCalculator.java
├── web/
│ ├── index.html
│ ├── styles.css
│ └── scripts.js
└── WEB-INF/
└── web.xml
PayPalFeeCalculator
PayPalFeeCalculator
PayPalFeeCalculator
/calculateFee
No comments:
Post a Comment