From dfd63386ba367f442b11379776a56cd8290a5153 Mon Sep 17 00:00:00 2001
From: Lukas <35193662+NixNotCastey@users.noreply.github.com>
Date: Fri, 8 Oct 2021 09:11:13 +0200
Subject: [PATCH] Make PromoSMS actually working

Make PromoSMS actually working and inform on success only when API return 0
---
 server/notification-providers/promosms.js | 24 +++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/server/notification-providers/promosms.js b/server/notification-providers/promosms.js
index 97d04691..23d6a450 100644
--- a/server/notification-providers/promosms.js
+++ b/server/notification-providers/promosms.js
@@ -9,28 +9,28 @@ class PromoSMS extends NotificationProvider {
         let okMsg = "Sent Successfully.";
 
         try {
-            let buffer = new Buffer(notification.promosmsLogin + ":" + notification.promosmsPassword);
-            let promosmsAuth = buffer.toString('base64');
             let config = {
                 headers: {
-                    "Authorization": "Basic" + promosmsAuth,
-                    "Content-Type": "application/x-www-form-urlencoded",
-                    "Accept": "text/json"
+                    "Content-Type": "application/json",
+                    "Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString('base64'),
+                    "Accept": "text/json",
                 }
             };
             let data = {
-                "recipients": [
-                    {
-                        "recipients": notification.promosmsPhoneNumber
-                    }
-                ],
+                "recipients": [ notification.promosmsPhoneNumber ],
                 //Lets remove non ascii char
                 "text": msg.replace(/[^\x00-\x7F]/g, ""),
-                "type": notification.promosmsSMSType,
+                "type": Number(notification.promosmsSMSType),
                 "sender": notification.promosmsSenderName
             };
-            await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config)
 
+            await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config).then(resp => {
+                if (resp.data.response.status !== 0) {
+                    let error = "Something gone wrong. Api returned " + resp.data.response.status + ".";
+                    this.throwGeneralAxiosError(error);
+                }
+            });
+            
             return okMsg;
         } catch (error) {
             this.throwGeneralAxiosError(error);