1
i am making a store with paypal, pay and mercadopago, but at the time of purchase when I select the input, it always saves as mercadopago.
Controller
public function checkout()
{
if(!Security::ajax())
{
die();
}
$gateway = new Gateways();
$gatewayData = $gateway->data();
$gateway = $_POST['gateway'];
$reference = $this->references->register();
html
<form class="row" method="post" id="checkout">
<div class="col-md-12 form-group">
<label><input type="radio" name="gateway" id="gateway" value="mercadopago" checked> MercadoPago</label><br>
<label><input type="radio" name="gateway" id="gateway" value="pagseguro" > PagSeguro</label><br>
<label><input type="radio" name="gateway" id="gateway" value="paypal"> PayPal</label><br>
<br><br>
<label><input type="checkbox" name="terms" required> Eu aceito os <a href="#" data-toggle="modal" data-target="#termos">termos de compra</a></label>
</div>
js
$('.checkout').on('click', function(e) {
e.preventDefault();
var terms = $('input[name=terms]').is(':checked');
if (!terms) {
alert('Aceite os termos!');
return;
}
let gateway = $('input[name=gateway]').val();
$.ajax({
url: '/carrinho/checkout',
method: 'POST',
data: {
gateway: gateway
},
complete: function(result) {
var res = JSON.parse(result.responseText);
if (res.status) {
location.href = res.link
} else {
alert(res.message);
}
}
});
return false;
});
it always results in mercadopago, I can never put by paypal or pagseguro
But no matter what I put on, it’s always the same value. If I use paypal input, the result is paid market If I use pay, the result is pay market
– Matheus Ferreira
I managed to fix, the value was
var gateway = $('#gateway:checked').val();


– Matheus Ferreira
using your code and the change I made worked, so it was another problem, you were probably using the id that should be unique on a page, but if you got it right.
– Wees Smith