_crystalwebtechs_username = get_option( 'ywsn_crystalwebtechs_username' ); $this->_crystalwebtechs_password = get_option( 'ywsn_crystalwebtechs_pass' ); $this->_crystalwebtechs_sender = get_option( 'ywsn_crystalwebtechs_sender' ); $this->_crystalwebtechs_channel = get_option( 'ywsn_crystalwebtechs_sender_channel_type' ); $this->_crystalwebtechs_route_id = get_option( 'ywsn_crystalwebtechs_route_id' ); parent::__construct(); } /** * Send SMS * * @since 1.1.1 * * @param $to_phone * @param $message * @param $country_code * * @return void * @throws Exception for crystalwebtechs Error code * @author Alberto Ruggiero */ public function send( $to_phone, $message, $country_code ) { $dcs = empty( apply_filters( 'ywsn_additional_charsets', array() ) ) ? '0' : '8'; $args = array( 'user' => $this->_crystalwebtechs_username, 'password' => $this->_crystalwebtechs_password, 'senderid' => $this->_crystalwebtechs_sender, 'channel' => $this->_crystalwebtechs_channel, 'DCS' => $dcs, 'flashsms' => '0', 'number' => $to_phone, 'text' => urlencode( $message ), 'route' => $this->_crystalwebtechs_route_id, ); $endpoint = 'http://websms.mysmsshop.com/api/mt/SendSMS'; $url = add_query_arg( $args, $endpoint ); // perform HTTP request with endpoint / args $response = wp_remote_get( $url ); // WP HTTP API error like network timeout, etc if ( is_wp_error( $response ) ) { throw new Exception( $response->get_error_message() ); } $this->_log[] = $response; // Check for proper body if ( ! isset( $response['body'] ) ) { throw new Exception( __( 'No answer', 'yith-woocommerce-sms-notifications' ) ); } $result = json_decode( $response['body'], true ); if ( $result['ErrorCode'] != '0' ) { throw new Exception( sprintf( __( 'An error has occurred: %s', 'yith-woocommerce-sms-notifications' ), $result['ErrorMessage'] ) ); } return; } } }