173 lines
6.5 KiB
JavaScript
173 lines
6.5 KiB
JavaScript
$(document).ready(function() {
|
|
|
|
$('#addNewMerchant').click(function() {
|
|
var org_id = $(this).siblings('.orgRowId').val();
|
|
console.log(org_id);
|
|
$('#selectedOrgId').val(org_id);
|
|
$('#createMerchantModal').modal('show');
|
|
});
|
|
|
|
$('.topUpMerchantBtn').click(function() {
|
|
var merchId = $(this).siblings('.orgRowId').val();
|
|
console.log(merchId);
|
|
$('.selectedMerchantId').val(merchId);
|
|
$('#topUpMerchantByIdModal').modal('show');
|
|
});
|
|
|
|
$('.topUpMerchantByIdBtn').click(function() {
|
|
var merchId = $(this).siblings('.rowMerchantId').val();
|
|
console.log(merchId);
|
|
$('.selectedMerchantId').val(merchId);
|
|
$('#topUpMerchantByIdModal').modal('show');
|
|
});
|
|
|
|
|
|
$('#newMerchantForm').submit(function(evt){
|
|
evt.preventDefault();
|
|
var formData = new FormData(this);
|
|
$('#topupSuccess').html('');
|
|
$('#topupError').html('');
|
|
$.ajax({
|
|
url: base_url + '/organisation/merchant',
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
beforeSend: function() {
|
|
$('#topupError').addClass('hidden');
|
|
console.log('Sending data...');
|
|
},
|
|
success: function(data) {
|
|
console.log('Success:', data);
|
|
$('#topupError').addClass('hidden');
|
|
$('#topupSuccess').removeClass('hidden');
|
|
$('#topupSuccess').html('<p>' + data.message + '</p>');
|
|
$('#newMerchantForm')[0].reset();
|
|
$('#orgTopUpModal').modal('hide');
|
|
// $('#topupSuccess').delay(5000).fadeOut();
|
|
// $('#topupSuccess').html('');
|
|
setTimeout(function() {
|
|
location.reload();
|
|
}, 3000);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error:', error);
|
|
if (xhr.status === 422) {
|
|
$('#topupError').removeClass('hidden');
|
|
//console.log(xhr.responseJSON.errors); // Display validation errors
|
|
$.each(xhr.responseJSON.errors, function(key, value) {
|
|
$('#topupError').append('<p>' + value[0] + '</p>');
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
// Handle the form submission
|
|
$('#otpButton').on('click', function(e) {
|
|
e.preventDefault();
|
|
$('#successArea').addClass('hidden');
|
|
$('#errorArea').addClass('hidden');
|
|
$('#topFormBtn').addClass('hidden');
|
|
$('#otpButton').removeClass('hidden');
|
|
$('#otpDivArea').addClass('hidden');
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: base_url + '/organisation/topupotp',
|
|
// data: $(this).serialize(),
|
|
success: function(response) {
|
|
console.log(response);
|
|
if (response.status == 'failed') {
|
|
$('#errorArea').removeClass('hidden');
|
|
$('#errorArea').html(response.message);
|
|
}
|
|
else{
|
|
$('#successArea').removeClass('hidden');
|
|
$('#successArea').html(response.message);
|
|
$('#topFormBtn').removeClass('hidden');
|
|
$('#otpButton').addClass('hidden');
|
|
$('#otpDivArea').removeClass('hidden');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
$('#errorArea').removeClass('hidden');
|
|
$('#errorArea').html(response.message);
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#dealerTopForm').on('submit', function(evt) {
|
|
evt.preventDefault();
|
|
|
|
// var formdata = $(this).formData();
|
|
$('#successArea').addClass('hidden');
|
|
$('#errorArea').addClass('hidden');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: base_url + '/organisation/topup',
|
|
data: $(this).serialize(),
|
|
success: function(response) {
|
|
console.log(response);
|
|
// $('#dealer_form')[0].reset();
|
|
if (response.status == 'failed') {
|
|
$('#errorArea').removeClass('hidden');
|
|
$('#errorArea').html(response.message);
|
|
}
|
|
else{
|
|
|
|
$('#successArea').removeClass('hidden');
|
|
$('#successArea').html(response.message);
|
|
location.reload();
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.log(xhr);
|
|
console.log(xhr.responseJSON.errors);
|
|
console.log(xhr.responseJSON.message);
|
|
$('#errorArea').removeClass('hidden');
|
|
xhr.responseJSON.errors.forEach(function(value, index) {
|
|
console.log(index + ': ' + value);
|
|
$('#errorArea').html(index + ': ' + value);
|
|
});
|
|
|
|
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#dealerTopFormById').on('submit', function(evt) {
|
|
evt.preventDefault();
|
|
$('#topupByIdSuccess').addClass('hidden');
|
|
$('#topupByIdError').addClass('hidden');
|
|
var merchID = $('.selectedMerchantId').val();
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: base_url + '/organisation/topup',
|
|
// data: formdata, //a $(this).serialize(),
|
|
data: { merchant_id: merchID, merchant: merchID, amount: $('#topUpAmountById').val() },
|
|
headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content") },
|
|
success: function(response) {
|
|
console.log(response);
|
|
if (response.status == 'failed') {
|
|
$('#topupByIdError').removeClass('hidden');
|
|
$('#topupByIdError').html(response.message);
|
|
}
|
|
else{
|
|
$('#topupByIdSuccess').removeClass('hidden');
|
|
$('#topupByIdSuccess').html(response.message);
|
|
setTimeout(function() {
|
|
location.reload();
|
|
}, 3000);
|
|
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
$('#topupByIdError').removeClass('hidden');
|
|
// $('#topupByIdError').html(response.message);
|
|
xhr.responseJSON.errors.forEach(function(value, index) {
|
|
console.log(index + ': ' + value);
|
|
$('#errorArea').html(index + ': ' + value);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}); |