demo transaksi
This commit is contained in:
@@ -3,8 +3,9 @@ defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* FCM HTTP v1 API helper (Firebase Cloud Messaging).
|
||||
* Uses OAuth2 access token from service account credentials (env: FCM_CREDENTIALS_PATH or FCM_CREDENTIALS_JSON).
|
||||
* Requires FCM_PROJECT_ID. Optional: FCM_LIMIT_PER_HOUR, FCM_LIMIT_PER_DAY for quota (used by callers).
|
||||
* OAuth2 access token from service account: FCM_CREDENTIALS_PATH or FCM_CREDENTIALS_JSON
|
||||
* and FCM_PROJECT_ID (set in application/config/config.php).
|
||||
* Optional: FCM_LIMIT_PER_HOUR, FCM_LIMIT_PER_DAY for quota (used by callers).
|
||||
*/
|
||||
|
||||
if (!function_exists('fcm_v1_get_credentials')) {
|
||||
@@ -264,3 +265,80 @@ if (!function_exists('fcm_v1_send')) {
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('fcm_v1_device_token_from_request')) {
|
||||
/**
|
||||
* FCM device registration token from API JSON body (mobile APK).
|
||||
* First non-empty among: firebase_token, fcm_token, reg_id, token.
|
||||
*
|
||||
* @param object|null $decoded_data json_decode() result
|
||||
* @return string Trimmed token or empty string
|
||||
*/
|
||||
function fcm_v1_device_token_from_request($decoded_data)
|
||||
{
|
||||
if (!$decoded_data || !is_object($decoded_data)) {
|
||||
return '';
|
||||
}
|
||||
foreach (array('firebase_token', 'fcm_token', 'reg_id', 'token') as $key) {
|
||||
if (!isset($decoded_data->$key)) {
|
||||
continue;
|
||||
}
|
||||
$v = trim((string) $decoded_data->$key);
|
||||
if ($v !== '') {
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('fcm_v1_login_allow_missing_device_token')) {
|
||||
/**
|
||||
* When true, Pelanggan/Merchant/Driver login skips FCM token presence validation (e.g. Postman / legacy).
|
||||
* Controlled by FCM_LOGIN_ALLOW_NO_DEVICE_TOKEN in application/config/config.php.
|
||||
*/
|
||||
function fcm_v1_login_allow_missing_device_token()
|
||||
{
|
||||
if (defined('FCM_LOGIN_ALLOW_NO_DEVICE_TOKEN')) {
|
||||
return (bool) FCM_LOGIN_ALLOW_NO_DEVICE_TOKEN;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('fcm_v1_validate_login_device_token_from_app')) {
|
||||
/**
|
||||
* Enforces that the APK sent a Firebase-generated device token on login.
|
||||
* Token is produced only on-device (FirebaseMessaging.getToken); backend never mints it.
|
||||
*
|
||||
* @param object|null $decoded_data json_decode body
|
||||
* @return array|null Null if OK or enforcement disabled; else array with keys code, message for API response
|
||||
*/
|
||||
function fcm_v1_validate_login_device_token_from_app($decoded_data)
|
||||
{
|
||||
if (fcm_v1_login_allow_missing_device_token()) {
|
||||
return null;
|
||||
}
|
||||
if (!function_exists('fcm_v1_device_token_from_request')) {
|
||||
return null;
|
||||
}
|
||||
$raw = fcm_v1_device_token_from_request($decoded_data);
|
||||
if ($raw === '') {
|
||||
return array(
|
||||
'code' => '400',
|
||||
'message' =>
|
||||
'Wajib kirim token FCM dari aplikasi (firebase_token, fcm_token, token, atau reg_id). '
|
||||
. 'Token dibuat oleh Firebase di perangkat setelah Firebase.initializeApp dan izin notifikasi.',
|
||||
);
|
||||
}
|
||||
if (!function_exists('fcm_v1_is_valid_device_token') || !fcm_v1_is_valid_device_token($raw)) {
|
||||
return array(
|
||||
'code' => '400',
|
||||
'message' =>
|
||||
'Token FCM tidak valid. Pastikan aplikasi berhasil memanggil Firebase Messaging getToken() '
|
||||
. 'di perangkat (bukan string buatan server).',
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user