Segue o código da função a qual recebo o json para atualizar meu status do boleto e abaixo o codigo de login de autenticação
public function return(Request $request)
{
$itau = $request->all();
$request->request->add(['site' => 'bbr']);
$paymentController = new PaymentController();
if ($itau) {
$boleto = DB::connection('payment')
->table('itau_boleto')
->where('cod_boleto', $itau['idBoleto'])
->where('status', '!=', 'paid')
->first();
if ($boleto) {
if($itau['tipoLiquidacao'] == 95 || $itau['tipoLiquidacao'] == 06){
$invoice = DB::connection($paymentController->payment['amember_connection'])->table('invoice')->where('invoice_id', $boleto->invoice_id)->first();
}
} else {
$return = array(
'status' => '',
'msg' => 'Boleto já está pago!'
);
return response()->json($return)->header('Content-Type', 'application/json');
}
if (isset($invoice) and $invoice->comment) {
if ($boleto && $itau['tipoLiquidacao'] == 95 || $itau['tipoLiquidacao'] == 06) {
if ($itau['tipoLiquidacao'] == 95 || $itau['tipoLiquidacao'] == 06) {
$itauStatus = 'paid';
}
$emails = explode('| ', $invoice->comment);
$i = 0;
DB::connection('payment')->table('itau_boleto')->where('cod_boleto', $itau['idBoleto'])->update(['status' => $itauStatus, "updated_at" => \Carbon\Carbon::now()]);
AmemberController::registerPayment($boleto->invoice_id, 'Boleto: ' . $boleto->cod_boleto);
foreach ($emails as $key => $value) {
if ($i != 0) {
if ($value != '') {
$value = trim($value);
$user = DB::connection($paymentController->payment['amember_connection'])->table('user')->where('email', $value)->first();
$invoice_user = DB::connection($paymentController->payment['amember_connection'])->table('invoice')->where('user_id', $user->user_id)->orderBy('invoice_id', 'asc')->first();
$return = AmemberController::registerPayment($invoice_user->invoice_id, 'Boleto: ' . $boleto->cod_boleto);
}
}
$i++;
}
$user = DB::connection('payment')->table('itau_boleto')->where('cod_boleto', $itau['id'])->first();
$user2 = DB::connection($paymentController->payment['amember_connection'])->table('invoice')->where('invoice_id', $user->invoice_id)->first();
$user3 = DB::connection($paymentController->payment['amember_connection'])->table('user')->where('user_id', $user2->user_id)->first();
$this->check_product($user3->email);
return response()->json(['msg' => 'ok'])->header('Content-Type', 'application/json');
}
} else {
if ($itau['tipoLiquidacao'] == 95 || $itau['tipoLiquidacao'] == 06) {
$itauStatus = 'paid';
}
if ($boleto && $itau['tipoLiquidacao'] == 95|| $itau['tipoLiquidacao'] == 06) {
DB::connection('payment')->table('itau_boleto')->where('cod_boleto', $itau['idBoleto'])->update(['status' => $itauStatus, "updated_at" => \Carbon\Carbon::now()]);
AmemberController::registerPayment($boleto->invoice_id, 'Boleto: ' . $boleto->cod_boleto);
return response()->json(['msg' => 'ok'])->header('Content-Type', 'application/json');
} else {
//error
return response()->json(['msg' => 'error2'])->header('Content-Type', 'application/json');
}
}
} else {
$return = array(
'status' => 'error',
'msg' => 'Sem dados do boleto'
);
return response()->json($return)->header('Content-Type', 'application/json');
}
}
public function loginItau(Request $request)
{
$client_id = $request->client_id;
$client_secret = $request->client_secret;
if ($client_id) {
$preHash1 = json_encode(array('client_secret' => $client_secret, 'client_id' => $client_id, 'site' => 'bbr'), true);
$hash1 = (base64_encode(openssl_encrypt($preHash1, 'aes128', 'slakdh02183hn2fsa', OPENSSL_RAW_DATA, '1586244526987523')));
$retorno = ["status" => ['active' => 1, "msg" => "Token gerado com sucesso"], "data" => [
'access_token' => $hash1,
'token_type' => 'bearer',
]];
return response()->json($retorno)->header('Content-Type', 'application/json');
}
}
protected function respondWithTokenItau($token)
{
$retorno = ["status" => ['active' => 1, "msg" => "Loguin efetuado com sucesso"], "data" => [
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 120
]];
return response()->json($retorno);
}