Skip to content

Commit

Permalink
#1088 Twilio update
Browse files Browse the repository at this point in the history
  • Loading branch information
abolabo committed Apr 3, 2018
1 parent 76a01a4 commit c8fd549
Show file tree
Hide file tree
Showing 1,409 changed files with 151,404 additions and 5,852 deletions.
Expand Up @@ -17,63 +17,62 @@
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/
if ( !IS_ADMIN || !defined ( 'DIR_CORE' )) {
header ( 'Location: static_pages/' );
if ( ! IS_ADMIN || ! defined( 'DIR_CORE' ) ) {
header( 'Location: static_pages/' );
}

class ControllerResponsesExtensionDefaultTwilio extends AController {

public $data = array();

public function test() {
$this->registry->set('force_skip_errors', true);
$this->loadLanguage('default_twilio/default_twilio');
$this->loadModel('setting/setting');
include_once(DIR_EXT.'default_twilio/core/lib/Services/Twilio.php');


$cfg = $this->model_setting_setting->getSetting('default_twilio',(int)$this->session->data['current_store_id']);
$AccountSid = $cfg['default_twilio_username'];
$AuthToken = $cfg['default_twilio_token'];

$sender = new Services_Twilio($AccountSid, $AuthToken);

if ($this->config->get('default_twilio_test')){
//sandbox number without errors from api
$from = '+15005550006';
} else{
$from = $this->config->get('default_twilio_sender_phone');
$from = '+' . ltrim($from, '+');
}
$error_message = '';
try{
$sender->account->sms_messages->create(
$from,
"+15005550006",
'test message',
array ()
);

}catch(Exception $e){
$error_message = $e->getMessage();
}


$this->registry->set('force_skip_errors', false);
$json = array();

if(!$error_message){
$json['message'] = $this->language->get('text_connection_success');
$json['error'] = false;
}else{
$json['message'] = "Connection to Twilio server can not be established.<br>" . $error_message .".<br>Check your server configuration or contact your hosting provider.";
$json['error'] = true;
}

$this->load->library('json');
$this->response->setOutput(AJson::encode($json));

}

class ControllerResponsesExtensionDefaultTwilio extends AController
{

public $data = array();

public function test()
{
$this->registry->set( 'force_skip_errors', true );
$this->loadLanguage( 'default_twilio/default_twilio' );
$this->loadModel( 'setting/setting' );
require_once( DIR_EXT.'default_twilio/core/lib/Services/Twilio.php' );
require_once( DIR_EXT.'default_twilio/core/lib/Twilio/autoload.php' );

$cfg = $this->model_setting_setting->getSetting( 'default_twilio', (int)$this->session->data['current_store_id'] );
$AccountSid = $cfg['default_twilio_username'];
$AuthToken = $cfg['default_twilio_token'];

$sender = new \Twilio\Rest\Client( $AccountSid, $AuthToken );

if ( $this->config->get( 'default_twilio_test' ) ) {
//sandbox number without errors from api
$from = '+15005550006';
} else {
$from = $this->config->get( 'default_twilio_sender_phone' );
$from = '+'.ltrim( $from, '+' );
}
$error_message = '';
try {
$sender->messages->create(
"+15005550006",
array('from' => $from,
'body' => 'test message')
);

} catch ( Exception $e ) {
$error_message = $e->getMessage();
}

$this->registry->set( 'force_skip_errors', false );
$json = array();

if ( ! $error_message ) {
$json['message'] = $this->language->get( 'text_connection_success' );
$json['error'] = false;
} else {
$json['message'] = "Connection to Twilio server can not be established.<br>".$error_message.".<br>Check your server configuration or contact your hosting provider.";
$json['error'] = true;
}

$this->load->library( 'json' );
$this->response->setOutput( AJson::encode( $json ) );

}

}

0 comments on commit c8fd549

Please sign in to comment.