confirmOrder() async {
final serviceJson = {
"type": "service_account",
"project_id": "pabili-app-427909",
"private_key_id": "5c56be8dd22fcd317af9bc67cda9989c2010d07f",
"private_key":
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQClwlKdRQkxu/fB\nQoOgVcGo3s0CEgIPRgOs/qBXhRs62p9Jj4r2TRW2Q6x5+T+LsCldsKt398Z+af1+\neVyy8OuzQZEzG7kIlhzai0SjSqs5XsNZtSJ2fd9nHlyBPQW4YP/izmKLlV/Vciv7\naVwa35OID1dAl1DSvh2uUDId1u/o1LlQHUpYF4r4q6VuC4MB3KesAhwDnLaZEujr\nmoE4IzmxymrX1icD1k+qpcHMjXwLMgfbpbbO30id2VvLPNNrNUpJrCfe8ItFeqKW\nu5qXg6r4whfSl0QE1MI7nNo6XWQk6VD2P1vQ/hnZtxYZAOIkUAECNiYopGQEtweZ\ns7Fgy5ZzAgMBAAECggEALJnG5O5IdQtgtK2TATdR7oBUpTP3PejW4Ft7BVGZbBKb\nPY3UFEXVi79Vz1QTlyCFYOJCoPsYe7dFMByzpqpQoWEJErlo5jiN9vf2NgHHZJ5s\n7dxhM4TW8cYnmdazjVL8RyjFN02wBZy83N8Sm2CBL+EA1y5f3vSsw9RsR78nunvj\nrTsBoicqi35b8rPF8guds/EtCvw3ZfYba6wI0RjaCTudMeKHpGuTMsSyO3cgYyHd\n9Ic6YrOYkPTzf8b5HpwpU+fLFIw4dzj4kT8/RdAOlyv98wgZ1o7RGNcy1aztyEra\nND6pBLy+6srXJJ/ijoY6mWZZDiMTa82PNkIhRO93sQKBgQDPVsVz79mMzvfKLfVu\nuvuLolnLfR23QetHqiIeeVmZmv77h/vQj+J81szNp7UDjQt4qxhtR1Cq47sI9wUZ\n5MNJNPnXBmgMvrEWckx4J5yMacofLss3SLpghLJHJfWPJRfk9PYlld/Bu+035DmJ\nHw1UpH4wD485J+3EKpChsCgUhQKBgQDMqV8N/faOmf8BtMCP8FU5MfHuu9gDOoEu\nqJSwBP+kh7dWJWECEF/WryYkiumLmAvGAGyNPV+XIMrmX5P0jxuvQn9JjZq+EBJ0\n+CihZBhqJbV+iJc5CEfpzkGJ3OxpsqnPqma4zyulrNFNRal7mFbk7moVVRiDSizW\njmNSe9BMlwKBgEYq5GnG+wXXKS6H/S57IxPvXpop/nt9WIWJQ0Cy6qq8NJylOYgs\nmYaMHwVeQzkva3lr1blt0BP1O9/d0SEhNSG6Ru8JIP9nLYEeL1jedvFh/+ArsuRD\nvadaYQcJBqBp+jsm14KCxRXIZpBqsToBgz5o6LeVHHBIXgPsL8Q4XGgNAoGBAIQL\n01SHwwiGu00yfftgqNvaKapKcDjFCow8IJLg5sAVAGkIfOqD/hHZt9Zj+gMi+pWp\nuF/4dTBg7AhvKlrj6ozNbqraPjjazc3CPxTCLC5wXgVhw4/8k8l6VjbI34/iwkVG\nQDiFEjg2pGQiyhMAWzAh0zgoS0SKGxvjipmxYNfJAoGAfEFwUIYvDPs29TWsbtgi\n+fap0/WW1qd1hWKaImYgHwisco9+jovlQbkneSFD66hx1W4lhVUmsg2f1XegmGWZ\n3SJZTlXyZ/2WxCzIMi63DU3DDYEjxheWyzBWZkGJL/pFJnhKhPWue3qvjHdM2ACD\nOU5v/EJ/Rb/SMTpyF+g/PB0=\n-----END PRIVATE KEY-----\n",
"client_email": "pabili-app@pabili-app-427909.iam.gserviceaccount.com",
"client_id": "106230144645912114661",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/pabili-app%40pabili-app-427909.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
};
List<String> scopes = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/firebase.messaging",
];
var creds = auth.ServiceAccountCredentials.fromJson(serviceJson);
Dev.log.f("privateKey: ${creds.privateKey}");
try {
http.Client client = await auth.clientViaServiceAccount(creds, scopes);
auth.AccessCredentials credentials = await auth.obtainAccessCredentialsViaServiceAccount(
auth.ServiceAccountCredentials.fromJson(
serviceJson,
),
scopes,
client);
client.close();
Dev.log.f("accesstoken: ${credentials.accessToken.data}");
var endPoint = "https://fcm.googleapis.com/v1/projects/pabili-app-427909/messages:send";
Dev.log.f("state.clientFCM: ${state.clientFCM}");
var message = {
"message": {
"token": state.clientFCM,
"notification": {
"body": "This is an FCM notification message!",
"title": "FCM Message",
},
"data": {
"current_user_fcm_token": state.clientFCM,
}
}
};
http.Response response = await http.post(Uri.parse(endPoint),
headers: <String, String>{
"Content-Type": "application/json",
"Authorization": "Bearer ${credentials.accessToken.data}",
},
body: jsonEncode(message));
if (response.statusCode == 200) {
Dev.log.f("response:${response.body}");
}
} catch (e) {
Dev.log.f("error: $e");
}
}