update send notification fcm

This commit is contained in:
2024-05-24 09:09:21 +07:00
parent 8ae6e44680
commit 8af376cd37
10 changed files with 253 additions and 24 deletions

View File

@@ -3,11 +3,14 @@
namespace Modules\Linksehat\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Notifications\SendNotification;
use App\Models\Organization;
use App\Models\Speciality;
use App\Models\Livechat;
use App\Models\Channel;
use App\Models\UserChannel;
use App\Models\User as UserAso;
use App\Models\OLDLMS\User;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
@@ -285,7 +288,7 @@ class DuitkuController extends Controller
'created_at' => date('Y-m-d H:i:s')
]);
if ($notif->resultCode == "00") {
if ($notif->resultCode == "00") { // berhasil melakukan pembayaran
// Action Success
$livechat = Livechat::where('uuid', $notif->merchantOrderId)->first();
// Update status pembayaran
@@ -329,6 +332,23 @@ class DuitkuController extends Controller
]
);
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$title = 'Payment Succes Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Succes Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'success-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
// Berikan respons yang sesuai ke klien
return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]);
@@ -340,6 +360,22 @@ class DuitkuController extends Controller
$livechat->status = 7; // failed payment
$livechat->save();
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$title = 'Payment Failed Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Failed Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'failed-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
return response()->json(['message' => 'User Gagal melakukan pembayaran']);
}