228 lines
10 KiB
PHP
228 lines
10 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
|
|
<?php init_head(); ?>
|
|
<div id="wrapper">
|
|
<div class="content">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="panel_s">
|
|
<div class="panel-body">
|
|
<h4 class="no-margin">
|
|
<?php echo _l('paystack_test_mode'); ?>
|
|
<?php if(get_option('paystack_test_mode')): ?>
|
|
<span class="label label-warning"><?php echo _l('test_mode_enabled'); ?></span>
|
|
<?php endif; ?>
|
|
</h4>
|
|
<hr class="hr-panel-heading" />
|
|
|
|
<!-- Test Mode Warning -->
|
|
<div class="alert alert-warning">
|
|
<h4><i class="fa fa-warning"></i> <?php echo _l('test_mode_warning'); ?></h4>
|
|
<?php echo _l('test_mode_description'); ?>
|
|
</div>
|
|
|
|
<!-- Test Transaction -->
|
|
<div class="panel_s">
|
|
<div class="panel-body">
|
|
<h4 class="no-margin"><?php echo _l('test_transaction'); ?></h4>
|
|
<hr class="hr-panel-heading" />
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="test_amount"><?php echo _l('amount'); ?></label>
|
|
<input type="number" class="form-control" id="test_amount" value="1000">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="test_email"><?php echo _l('email'); ?></label>
|
|
<input type="email" class="form-control" id="test_email" value="test@example.com">
|
|
</div>
|
|
<button type="button" class="btn btn-info" onclick="initiate_test_payment()">
|
|
<?php echo _l('initiate_test_payment'); ?>
|
|
</button>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="alert alert-info">
|
|
<h4><?php echo _l('test_cards'); ?></h4>
|
|
<p><strong><?php echo _l('successful_payment'); ?>:</strong></p>
|
|
<pre>Card Number: 4084 0840 8408 4081
|
|
Expiry: 01/25
|
|
CVV: 408</pre>
|
|
<p><strong><?php echo _l('failed_payment'); ?>:</strong></p>
|
|
<pre>Card Number: 4084 0840 8408 4080
|
|
Expiry: 01/25
|
|
CVV: 408</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Test Webhook -->
|
|
<div class="panel_s">
|
|
<div class="panel-body">
|
|
<h4 class="no-margin"><?php echo _l('test_webhook'); ?></h4>
|
|
<hr class="hr-panel-heading" />
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<p><?php echo _l('webhook_url'); ?>:</p>
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" id="webhook_url" readonly
|
|
value="<?php echo site_url('paystack/webhook'); ?>">
|
|
<span class="input-group-btn">
|
|
<button class="btn btn-default" type="button" onclick="copy_webhook_url()">
|
|
<i class="fa fa-copy"></i>
|
|
</button>
|
|
</span>
|
|
</div>
|
|
<div class="mtop15">
|
|
<button type="button" class="btn btn-info" onclick="test_webhook()">
|
|
<?php echo _l('test_webhook_connection'); ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div id="webhook_test_result"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Debug Log -->
|
|
<div class="panel_s">
|
|
<div class="panel-body">
|
|
<h4 class="no-margin"><?php echo _l('debug_log'); ?></h4>
|
|
<hr class="hr-panel-heading" />
|
|
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<textarea class="form-control" id="debug_log" rows="10" readonly></textarea>
|
|
<div class="mtop15">
|
|
<button type="button" class="btn btn-danger" onclick="clear_debug_log()">
|
|
<?php echo _l('clear_log'); ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php init_tail(); ?>
|
|
<script>
|
|
// Initiate test payment
|
|
function initiate_test_payment() {
|
|
var amount = $('#test_amount').val();
|
|
var email = $('#test_email').val();
|
|
|
|
$.post(admin_url + 'paystack/admin/initiate_test_payment', {
|
|
amount: amount,
|
|
email: email
|
|
}).done(function(response) {
|
|
var data = JSON.parse(response);
|
|
if(data.success) {
|
|
// Open Paystack popup
|
|
let handler = PaystackPop.setup({
|
|
key: '<?php echo get_option("paystack_test_public_key"); ?>',
|
|
email: email,
|
|
amount: amount * 100,
|
|
ref: data.reference,
|
|
callback: function(response) {
|
|
log_debug('Test payment completed: ' + response.reference);
|
|
alert_float('success', '<?php echo _l("test_payment_successful"); ?>');
|
|
},
|
|
onClose: function() {
|
|
log_debug('Test payment cancelled');
|
|
alert_float('warning', '<?php echo _l("test_payment_cancelled"); ?>');
|
|
}
|
|
});
|
|
handler.openIframe();
|
|
} else {
|
|
alert_float('danger', data.message);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Test webhook
|
|
function test_webhook() {
|
|
$('#webhook_test_result').html('<div class="alert alert-info"><?php echo _l("testing_webhook"); ?></div>');
|
|
$.post(admin_url + 'paystack/admin/test_webhook')
|
|
.done(function(response) {
|
|
var data = JSON.parse(response);
|
|
if(data.success) {
|
|
$('#webhook_test_result').html(
|
|
'<div class="alert alert-success">' +
|
|
'<h4><i class="fa fa-check"></i> <?php echo _l("webhook_test_successful"); ?></h4>' +
|
|
'<p>' + data.message + '</p>' +
|
|
'</div>'
|
|
);
|
|
log_debug('Webhook test successful: ' + data.message);
|
|
} else {
|
|
$('#webhook_test_result').html(
|
|
'<div class="alert alert-danger">' +
|
|
'<h4><i class="fa fa-times"></i> <?php echo _l("webhook_test_failed"); ?></h4>' +
|
|
'<p>' + data.message + '</p>' +
|
|
'</div>'
|
|
);
|
|
log_debug('Webhook test failed: ' + data.message);
|
|
}
|
|
})
|
|
.fail(function(xhr) {
|
|
$('#webhook_test_result').html(
|
|
'<div class="alert alert-danger">' +
|
|
'<h4><i class="fa fa-times"></i> <?php echo _l("webhook_test_failed"); ?></h4>' +
|
|
'<p><?php echo _l("connection_failed"); ?></p>' +
|
|
'</div>'
|
|
);
|
|
log_debug('Webhook test failed: Connection error');
|
|
});
|
|
}
|
|
|
|
// Copy webhook URL
|
|
function copy_webhook_url() {
|
|
var copyText = document.getElementById("webhook_url");
|
|
copyText.select();
|
|
document.execCommand("copy");
|
|
alert_float('success', '<?php echo _l("webhook_url_copied"); ?>');
|
|
}
|
|
|
|
// Debug logging
|
|
function log_debug(message) {
|
|
var now = new Date().toISOString();
|
|
var current = $('#debug_log').val();
|
|
$('#debug_log').val(current + now + ': ' + message + "\n");
|
|
|
|
// Save to server
|
|
$.post(admin_url + 'paystack/admin/log_debug', {
|
|
message: message
|
|
});
|
|
}
|
|
|
|
// Clear debug log
|
|
function clear_debug_log() {
|
|
if(confirm('<?php echo _l("confirm_clear_log"); ?>')) {
|
|
$('#debug_log').val('');
|
|
$.post(admin_url + 'paystack/admin/clear_debug_log');
|
|
alert_float('success', '<?php echo _l("log_cleared"); ?>');
|
|
}
|
|
}
|
|
|
|
// Load initial debug log
|
|
function load_debug_log() {
|
|
$.get(admin_url + 'paystack/admin/get_debug_log', function(response) {
|
|
$('#debug_log').val(response);
|
|
});
|
|
}
|
|
|
|
// Initialize
|
|
$(function() {
|
|
load_debug_log();
|
|
|
|
// Refresh debug log every 30 seconds
|
|
setInterval(load_debug_log, 30000);
|
|
});
|
|
</script>
|