Exemplo n.º 1
0
 /**
  * Constructor
  */
 function __construct($data)
 {
     // If not array
     if (!is_array($data)) {
         // Set message
         $data = ['message' => $data];
     }
     // Set attributes
     $this->setAttributes(Utilities::arrayExtract(['message_id', 'id', 'message_type', 'type', 'mobile_number', 'mobile', 'shortcode', 'request_id', 'request_cost', 'cost', 'message', 'timestamp'], $data));
 }
Exemplo n.º 2
0
 /**
  * When setting shortcode
  */
 protected function setShortcodeAttribute($value)
 {
     // Extract numerics only
     $shortcode = Utilities::extractNumerics($value);
     // If shortcode doesn't begin with 29290
     if (substr($shortcode, 0, 5) != '29290') {
         // Throw error
         throw new InvalidConfig('Shortcode must start with `29290`. `' . $shortcode . '` is given');
     }
     // Set shortcode
     return $shortcode;
 }
Exemplo n.º 3
0
 /**
  * Constructor
  */
 function __construct($number)
 {
     // Parse mobile number
     $mobileNumber = Utilities::parseMobileNumber($number);
     // If country code is 0
     if ($mobileNumber['countryCode'] == $this->getLocalCode() || empty($mobileNumber['countryCode'])) {
         // Use default
         $mobileNumber['countryCode'] = $this->getDefaultCountryCode();
     }
     // If country code is invalid
     if (!in_array($mobileNumber['countryCode'], $this->getSupportedCountryCodes())) {
         // Throw error
         throw new UnknownCountry('Unknown country code: ' . $mobileNumber['countryCode']);
     }
     // Set country
     $this->country = Loader::country($mobileNumber['countryCode']);
     // Set carrier
     $this->carrier = Loader::carrier($mobileNumber['carrierCode']);
     // Set number
     $this->number = $mobileNumber['number'];
 }
Exemplo n.º 4
0
 /**
  * Constructor
  */
 function __construct(array $data)
 {
     // Set attributes
     $this->setAttributes(Utilities::arrayExtract(['message_type', 'type', 'shortcode', 'message_id', 'id', 'status', 'credits_cost', 'credits', 'rb_cost', 'cost', 'timestamp'], $data));
 }
Exemplo n.º 5
0
 /**
  * Check if POST received is a notification
  */
 public function isNotification(array $post)
 {
     // Message keys
     $keys = ['message_type', 'shortcode', 'message_id', 'status', 'credits_cost', 'timestamp'];
     // Return
     return Utilities::arrayKeysExist($keys, $post);
 }
Exemplo n.º 6
0
 /**
  * Create message
  */
 protected function createMessage($message)
 {
     // If instance of message
     if ($message instanceof Message) {
         // Return immediately
         return $message;
     } elseif (is_array($message)) {
         // If there's message instance in message
         if (isset($message['message']) && $message['message'] instanceof Message) {
             // Get message and set attributes
             return $message['message']->setAttributes(Utilities::arrayExcept(['message'], $message));
         }
     }
     // Return
     return Loader::message($message);
 }
Exemplo n.º 7
0
 /**
  * Cleanup number
  */
 protected function cleanAmount($amount)
 {
     // Extract amount
     return (double) Utilities::extractNumerics($amount, ['.']);
 }