/*
	Javascript for duitku payment gateway
*/

function duitku_requirement(){
	
	var html = '';
	
	$('.payment_gateway_fields').html(html);

	html += '<div class="flex flex-col col-md-6">\
		<div class="form-group flex-1 w-80 my-2">\
			<label for="input text" class="virt-label form-label">{{Firstname}} :</label>\
			<input type="text" name="firstname" class="virt-input form-control" size="10" />\
		</div>\
		<div class="form-group flex-1 w-80 my-2">\
			<label for="input text" class="virt-label form-label d-inline-block">{{Phone Number}} :</label>\
			<input type="text" name="phone" class="form-control virt-input" size="10"  />\
		</div>\
		<div class="form-group flex-1 w-80 my-2">\
			<label for="input text" class="form-label d-inline-block virt-label">{{Bill Payment Method}} :</label>\
			<select name="payment_method" id="payment_method" class="form-control virt-select" width="10" ></select>\
		</div>\
	</div>';

	var uri = $('#make_payment_form').attr('action') + '&api=json&gateway=duitku&get_extra_config=1';
	var data = [];
	data["get_extra_conf"] = 1;

	$.ajax({
		url: uri,
		data: data,
		method: 'POST',
		success: function(res){
			var finalData = JSON.parse(res);
			var option = "";
			var finalData1 = JSON.parse(finalData['extra_config']);
			//alert(finalData1);
			$.each(finalData1['paymentFee'], function( index, value ) {
				if(value.paymentMethod != undefined){
					option += "<option value='"+value.paymentMethod+"' "+(value.paymentMethod == 'VC' ? "selected='selected'" : '')+">"+value.paymentName+"</option>";
				}
			});
			//alert(option)
			$("#payment_method").html(option);
		}
	});
	
	$('.payment_gateway_fields').html(html);
};

function duitku_process(){
	
	var data = $('#make_payment_form').serializeArray();
	var uri = $('#make_payment_form').attr('action') + '&api=json';
	$.ajax({
		url: uri,
		data: data,
		method: 'POST',
		success: function(res){
			var finalData = JSON.parse(res);
			$('#make_payment_form').attr('action',finalData.paymentUrl);
			$('#make_payment_form').submit();
		}
	});
};