I'm working on an API and i'm doing some validtions (on request) so i creat my own validations errors (validation.php) and all works fine, but i can't capture those responses to store them in my db. This is my code:
public function NullRequest(Request $request)
{
// $request->validate([
$validator = Validator::make($request->all(), [
'merchant_id' =>'required', //101
'api_user' =>'required', //102
'barcode' =>'required', //103
'reader_name' =>'required', //104
'branch' =>'required', //105
'trx_type' =>'required', //106
'secret_key' =>'required', //107
'timestamp' =>'required', //108
'reader_ip' =>'required', //109
'access_token' =>'required', //110
]);
if ($validator->fails()) {
$trx_data = $validator->errors()->toArray();
$regTrx = array(
'reader_name' => $request->reader_name,
'barcode' => $request->barcode,
'product_description' => 'VACIO',
'product_currency' => $currency[0]['iso_4712'],
'product_price' => 'VACIO',
'merchant_id' => $request->merchant_id,
'transaction_type' => $request->trx_type,
'trx_result' => $trx_data['data'][1]['Result']['Main Response: '],
'trx_result_extended' => $trx_data['data'][1]['Result']['Response Extended:']['Response Code: '],
'branch_name' => $request->branch,
'sector_name' => $sector[0]['sector_name'],
'trx_user' => $request->api_user,
'reader_ip' => $request->reader_ip,
'trx_ip' => \Request::ip(),
'created_at' => $timestamp,
'updated_at' => $timestamp
);
$this->saveTrx($regTrx);
}
$trx_data contains the correct rejection message
array:1 [
"merchant_id" => array:1 [
0 => array:2 [
"Main Response: " => "Transaction Result Code: 1 => Conexion Rechazada - Error en la estructura del Requerimiento"
"Response Extended:" => array:1 [
"Response Code: " => "101 - El Campo Merchant_ID es obligatorio para este requerimiento"
]
]
]
]
i need to know if there is any way to dynamically access to the attribute error (merchant_id in this case) so this attribute is gonna change depending the null field in request if anyone could help me ... i'll be very thankful.. thanks in advance !
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire