Commit dfec2bc7 authored by Your Name's avatar Your Name

Fix payment gateway settings save/load issues

- Fix sandbox checkbox loading logic (use === true instead of !== false)
- Add console logging to debug save operations
- Add auto-reload after save to verify changes
- Fixes issue where sandbox mode always saved as true
parent e98d5a85
...@@ -930,7 +930,7 @@ function loadPaymentGateways() { ...@@ -930,7 +930,7 @@ function loadPaymentGateways() {
document.getElementById('paypalClientId').value = gateways.paypal.client_id || ''; document.getElementById('paypalClientId').value = gateways.paypal.client_id || '';
document.getElementById('paypalClientSecret').value = gateways.paypal.client_secret || ''; document.getElementById('paypalClientSecret').value = gateways.paypal.client_secret || '';
document.getElementById('paypalWebhookSecret').value = gateways.paypal.webhook_secret || ''; document.getElementById('paypalWebhookSecret').value = gateways.paypal.webhook_secret || '';
document.getElementById('paypalSandbox').checked = gateways.paypal.sandbox !== false; document.getElementById('paypalSandbox').checked = gateways.paypal.sandbox === true;
} }
if (gateways.stripe) { if (gateways.stripe) {
...@@ -938,7 +938,7 @@ function loadPaymentGateways() { ...@@ -938,7 +938,7 @@ function loadPaymentGateways() {
document.getElementById('stripePublishableKey').value = gateways.stripe.publishable_key || ''; document.getElementById('stripePublishableKey').value = gateways.stripe.publishable_key || '';
document.getElementById('stripeSecretKey').value = gateways.stripe.secret_key || ''; document.getElementById('stripeSecretKey').value = gateways.stripe.secret_key || '';
document.getElementById('stripeWebhookSecret').value = gateways.stripe.webhook_secret || ''; document.getElementById('stripeWebhookSecret').value = gateways.stripe.webhook_secret || '';
document.getElementById('stripeSandbox').checked = gateways.stripe.sandbox !== false; document.getElementById('stripeSandbox').checked = gateways.stripe.sandbox === true;
} }
if (gateways.bitcoin) { if (gateways.bitcoin) {
...@@ -1013,6 +1013,8 @@ function savePaymentGateways() { ...@@ -1013,6 +1013,8 @@ function savePaymentGateways() {
} }
}; };
console.log('Saving payment gateways:', gatewaysData);
fetch('{{ url_for(request, "/api/admin/settings/payment-gateways") }}', { fetch('{{ url_for(request, "/api/admin/settings/payment-gateways") }}', {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -1021,14 +1023,18 @@ function savePaymentGateways() { ...@@ -1021,14 +1023,18 @@ function savePaymentGateways() {
body: JSON.stringify(gatewaysData) body: JSON.stringify(gatewaysData)
}) })
.then(response => { .then(response => {
console.log('Response status:', response.status);
if (!response.ok) { if (!response.ok) {
throw new Error('Failed to save payment gateway configuration'); throw new Error('Failed to save payment gateway configuration');
} }
return response.json(); return response.json();
}) })
.then(result => { .then(result => {
console.log('Save result:', result);
if (result.success) { if (result.success) {
showToast('Payment gateway configuration saved successfully', 'success'); showToast('Payment gateway configuration saved successfully', 'success');
// Reload to verify
setTimeout(() => loadPaymentGateways(), 500);
} else { } else {
showToast(result.error || 'Error saving payment gateway configuration', 'danger'); showToast(result.error || 'Error saving payment gateway configuration', 'danger');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment