I'm having a problem when creating my payment preference, such a problem is a
"Params Error" 400.
Form with which I send the products of the cart to my controller:
<form class="form-horizontal" action="{!! route('payment.process') !!}" method="post">
{{ csrf_field() }}
<input type="hidden" name="ctoken" id="ctoken" value="{!! $cart_token !!}">
<input type="submit" name="pagar" value="Pagar" class="btn btn-success btn-block btn-sm">
</form>
Controller in question:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Models\Cart;
use Exception;
use MP;
class PaymentController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function process(Request $request)
{
$mp = new MP (env('OCULTO'), env('OCULTO'));
$user = auth()->user();
$preferenceData = [
'external_reference' => $request->ctoken,
'payer' => [
'name' => $user->name,
'email' => $user->email,
'date_created' => $user->created_at
]
];
$entries = Cart::where('session_id', '=', $request->ctoken)->get();
foreach ($entries as $e):
$preferenceData['items'][] = [
'id' => $e->product_id,
'category_id' => 'zapato',
'title' => $e->product_name,
'description' => 'esta es la descripción del zapato',
'picture_url' => 'https://placehold.it/600x600',
'quantity' => $e->qty,
'currency_id' => 'VEF',
'unit_price' => $e->price,
];
endforeach;
$preference = $mp->create_preference($preferenceData);
// return init point to be redirected
//return $preference['response']['init_point'];
return dd($preferenceData);
}
}
In the hidden parameters I have the credentials provided by mercadopago.