Skip to content

Commit

Permalink
change from json_decode to response->json()
Browse files Browse the repository at this point in the history
  • Loading branch information
Iankumu committed May 17, 2024
1 parent 3a24143 commit c9c4015
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/MPESAB2CController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public function simulate(Request $request)

$response = Mpesa::b2c($phoneno, $command, $amount, $remarks);

$result = json_decode((string)$response);
// $result = json_decode((string)$response);

/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();

return Inertia::render('Payments/Partials/B2C', [
'response' => $result,
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/MPESAC2BController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function registerURLS(Request $request)
{
$shortcode = $request->input('shortcode');
$response = Mpesa::c2bregisterURLS($shortcode);
$result = json_decode((string)$response, true);
// $result = json_decode((string)$response, true);

/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();

return Inertia::render('Payments/Partials/C2B', [
'response' => $result,
Expand Down
33 changes: 21 additions & 12 deletions app/Http/Controllers/MpesaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ public function simulate_balance(Request $request)
$shortcode = $request->input('shortcode');
$identifier = $request->input('identiertype');
$remarks = $request->input('remarks');
$response=Mpesa::accountBalance($shortcode,$identifier,$remarks);
$response = Mpesa::accountBalance($shortcode, $identifier, $remarks);

$result = json_decode((string)$response);
// $result = json_decode((string)$response);

return Inertia::render('Payments/Partials/AccountBalance',[
'response'=>$result
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();

return Inertia::render('Payments/Partials/AccountBalance', [
'response' => $result
]);
}
public function simulate_status(Request $request)
Expand All @@ -59,12 +62,15 @@ public function simulate_status(Request $request)
$identifier = $request->input('identiertype');
$transactionid = $request->input('transactionid');
$remarks = $request->input('remarks');
$response=Mpesa::transactionStatus($shortcode,$transactionid,$identifier,$remarks);
$response = Mpesa::transactionStatus($shortcode, $transactionid, $identifier, $remarks);

// $result = json_decode((string)$response);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();

return Inertia::render('Payments/Partials/TransactionStatus',[
'response'=>$result
return Inertia::render('Payments/Partials/TransactionStatus', [
'response' => $result
]);
}
public function simulate_reversals(Request $request)
Expand All @@ -73,12 +79,15 @@ public function simulate_reversals(Request $request)
$transactionid = $request->input('transactionid');
$amount = $request->input('amount');
$remarks = $request->input('remarks');
$response=Mpesa::reversal($shortcode,$transactionid,$amount,$remarks);
$response = Mpesa::reversal($shortcode, $transactionid, $amount, $remarks);

// $result = json_decode((string)$response);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();

return Inertia::render('Payments/Partials/Reversals',[
'response'=>$result
return Inertia::render('Payments/Partials/Reversals', [
'response' => $result
]);
}

Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/MpesaSTKPUSHController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public function STKPush(Request $request)


$response = Mpesa::stkpush($phoneno, $amount, $account_number);
$result = json_decode((string)$response, true);
// $result = json_decode((string)$response, true);

/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();

if (!is_null($result)) {
MpesaSTK::create([
Expand Down

0 comments on commit c9c4015

Please sign in to comment.