Example #1
0
 /**
  * Data preprocessing before it can be saved. Enriching the message to be saved and forwarded.
  *
  * @param $data mixed data to be preprocessed
  * @return int array indicating the processing status and data after processing
  */
 protected function preProcess($data)
 {
     //check for required parameters
     if (!(isset($data['message']) && isset($data['sender_address']) && isset($data['dest_address']) && isset($data['service_id']))) {
         return array('result' => 13, 'resultDesc' => 'Expected parameters not found.', 'data' => $data);
     }
     //get the service data
     $response = $this->getService($data['service_id']);
     //print_r($response);
     if ($response['result'] != 0) {
         //retrieving service failed
         $this->logger->debug('{class_mame}|{method_name}|error-loading-service|{result}|{result_desc}', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'request_data' => implode('|', $data), 'result' => $response['result'], 'sdp_result_desc' => $response['resultDesc']));
         return $response;
     }
     //extract service data from
     $service = $response['data'];
     //service data
     // Check service status configuration 0 - OFF and 1 - ON
     if ($service->status != 1) {
         return array('result' => 15, 'resultDesc' => 'Service with id ' . $data['service_id'] . ' is OFF or is not configured correctly.', 'data' => $data);
     }
     //resolve the end point
     $data['notify_endpoint'] = $service->delivery_notification_endpoint;
     if (!isset($data['notify_endpoint']) || empty($data['notify_endpoint'])) {
         //use default enmd point
         $data['notify_endpoint'] = Config::get('SEND_SMS_DEFAULT_DELIVERY_NOTIFICATION_ENDPOINT');
     }
     //check whether short code exists as part of the request data, if not, load service configuration file
     if (!isset($data['sender_address']) || empty($data['sender_address'])) {
         $data['sender_address'] = $service->short_code;
     }
     //send request to external server
     $send_response = SDP::sendSms($this->logger, $data['service_id'], $data['dest_address'], $data['correlator'], $data['sender_address'], $data['message'], $data['link_id']);
     //log the event
     $this->logger->debug('{class_mame}|{method_name}|sdp-result|{request_data}|{sdp_result}|{sdp_result_desc}', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'request_data' => implode('|', $data), 'sdp_result' => $send_response['ResultCode'], 'sdp_result_desc' => $send_response['ResultDesc']));
     $data['sdp_sendsms_result'] = $send_response;
     //check send sms response code
     if ($send_response['ResultCode'] == 0) {
         // success
         //send the message to external system
         $data['send_ref_id'] = $send_response['ResultDetails']['result'];
         //ref id of SDP to be changed with API change
         $data['status'] = 2;
         //send sms successful
         $data['status_desc'] = 'SENT[Message sent]';
         //message sent
     } else {
         $data['status'] = 4;
         //sending failed
         $data['status_desc'] = 'FAIED[Sending failed. ' . $send_response['ResultCode'] . ' - ' . $send_response['ResultDesc'] . ': ' . $send_response['ResultDetails'] . ']';
         //message send failed
     }
     return array('result' => "0", 'resultDesc' => 'Preprocessing successful', 'data' => $data);
 }
Example #2
0
 /**
  * sendStopSmsNotification to SDP
  *
  * @param array $service_data service data to be used in sending request
  * @return bool TRUE if successful an FALSE if it fails
  */
 private function sendStopSmsNotification($service_data)
 {
     //send the request to SDP
     $response = SDP::stopSmsNotification($this->logger, $service_data->service_id, $service_data->correlator);
     //check response
     if ($response['ResultCode'] == 0) {
         return array('result' => 0, 'resultDesc' => 'Successful.', 'service' => $service_data, 'sdp_data' => $response);
     }
     //return
     return array('result' => 1, 'resultDesc' => 'Stop sms failed(' . $response['ResultCode'] . ' - ' . $response['ResultDesc'] . ' - ' . $response['ResultDetails'] . ').', 'service' => $service_data, 'sdp_data' => $response);
 }