_clockwork_api_key = get_option( 'ywsn_clockwork_api_key' ); parent::__construct(); } /** * Send SMS * * @since 1.0.0 * * @param $to_phone * @param $message * @param $country_code * * @return void * @throws Exception for Clockwork Error code * @author Alberto Ruggiero */ public function send( $to_phone, $message, $country_code ) { require_once( YWSN_DIR . 'includes/services/clockwork/class-Clockwork.php' ); try { if ( '' != $this->_from_asid ) { $from = $this->_from_asid; } else { $from = $this->_from_number; } $clockwork = new Clockwork( $this->_clockwork_api_key ); $message = array( 'from' => $from, 'to' => $to_phone, 'message' => $message ); $response = $clockwork->send( $message ); $this->_log[] = $response; if ( $response['success'] ) { return; } else { throw new Exception( sprintf( _x( 'Error %1$s: %2$s', '[ %1$s: error code - %2$s: error message; Ex. Error 10: Invalid Parameter ]', 'yith-woocommerce-sms-notifications' ), $response['error_code'], $response['error_message'] ) ); } } catch ( ClockworkException $e ) { throw new Exception( sprintf( __( 'An error has occurred: %s', 'yith-woocommerce-sms-notifications' ), $e->getMessage() ) ); } } } }