igp-sep-example/delivery/html/payment.html

240 lines
6.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>پرداخت آنلاین - بانک سامان</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Tahoma, Arial, sans-serif;
}
body {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.payment-card {
background: white;
border-radius: 20px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
overflow: hidden;
max-width: 450px;
width: 100%;
}
.payment-header {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
color: white;
padding: 30px;
text-align: center;
}
.payment-icon {
font-size: 50px;
margin-bottom: 10px;
}
.payment-header h2 {
margin: 10px 0 5px;
font-size: 24px;
}
.payment-header p {
margin: 0;
font-size: 14px;
opacity: 0.9;
}
.payment-body {
padding: 30px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
color: #333;
font-weight: bold;
}
.form-group input {
width: 100%;
padding: 14px;
border: 2px solid #ddd;
border-radius: 10px;
font-size: 16px;
transition: border-color 0.3s;
}
.form-group input:focus {
outline: none;
border-color: #38ef7d;
}
.form-group .hint {
font-size: 12px;
color: #888;
margin-top: 5px;
}
.btn-pay {
width: 100%;
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
border: none;
color: white;
padding: 16px;
font-size: 18px;
font-weight: bold;
border-radius: 50px;
cursor: pointer;
transition: transform 0.3s, box-shadow 0.3s;
}
.btn-pay:hover:not(:disabled) {
transform: scale(1.02);
box-shadow: 0 5px 20px rgba(56, 239, 125, 0.4);
}
.btn-pay:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.alert {
padding: 15px;
border-radius: 10px;
margin-top: 20px;
display: none;
}
.alert-success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.alert-danger {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
margin-right: 10px;
vertical-align: middle;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="payment-card">
<div class="payment-header">
<div class="payment-icon">💳</div>
<h2>پرداخت آنلاین</h2>
<p>بانک سامان - IPG_SEP</p>
</div>
<div class="payment-body">
<form id="paymentForm">
<div class="form-group">
<label>مبلغ (تومان)</label>
<input type="number" id="amount" placeholder="مبلغ را وارد کنید" required min="1000">
<div class="hint">حداقل مبلغ: ۱۰۰۰ تومان</div>
</div>
<div class="form-group">
<label>شماره تلفن همراه</label>
<input type="tel" id="phone" placeholder="۰۹۱۲۳۴۵۶۷۸۹" required pattern="09[0-9]{9}">
</div>
<button type="submit" class="btn-pay" id="payBtn">
پرداخت امن 🔒
</button>
</form>
<div id="message" class="alert"></div>
</div>
</div>
<script>
document.getElementById('paymentForm').addEventListener('submit', async function (e) {
e.preventDefault();
const amount = document.getElementById('amount').value;
const phone = document.getElementById('phone').value;
const btn = document.getElementById('payBtn');
const message = document.getElementById('message');
if (parseInt(amount) < 1000) {
showMessage('حداقل مبلغ ۱۰۰۰ تومان است', 'danger');
return;
}
if (!phone.match(/^09[0-9]{9}$/)) {
showMessage('شماره تلفن معتبر وارد کنید', 'danger');
return;
}
btn.disabled = true;
btn.innerHTML = '<span class="spinner"></span>در حال انتقال به درگاه...';
try {
const response = await fetch('/api/init-payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: parseInt(amount),
phone: phone
})
});
const data = await response.json();
if (data.success && data.payment_url) {
window.location.href = data.payment_url;
} else {
showMessage(data.message || 'خطا در ایجاد پرداخت', 'danger');
resetButton();
}
} catch (error) {
showMessage('خطا در ارتباط با سرور', 'danger');
resetButton();
}
});
function resetButton() {
const btn = document.getElementById('payBtn');
btn.disabled = false;
btn.innerHTML = 'پرداخت امن 🔒';
}
function showMessage(text, type) {
const message = document.getElementById('message');
message.textContent = text;
message.className = 'alert alert-' + type;
message.style.display = 'block';
}
</script>
</body>
</html>