| Server IP : 162.214.74.102 / Your IP : 216.73.216.139 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_projetos/sopizzas/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Updatesubmerchant extends CI_Controller {
function __construct()
{
parent::__construct();
// this controller can only be called from the command line
//if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
$this->load->helper("url");
$this->load->helper('file');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('myemail');
$this->load->library('braintree_lib');
$this->load->model('frontend_model');
}
function index( $offset = 0 ) {
// $getJSON = file_get_contents('BraintreeSubMerchantUpdate.json');
// if (!empty(json_decode($getJSON, true))) {
// $putJSON = json_decode($getJSON, true);
// }
// print_r($putJSON);
// echo "<pre>";
// print_r($this->input->post());
// echo "</pre>";
// if ($_POST) {
// $data = $_POST;
// if (!file_exists('BraintreeSubMerchantUpdate.json')) {
// $putJSON[date('Y-m-d H:i:s')] = $data;
// file_put_contents('BraintreeSubMerchantUpdate.json', json_encode($putJSON));
// @chmod('BraintreeSubMerchantUpdate.json', 0777);
// }
// else {
// $getJSON = file_get_contents('BraintreeSubMerchantUpdate.json');
// if (!empty(json_decode($getJSON, true))) {
// $putJSON = json_decode($getJSON, true);
// }
// $putJSON[date('Y-m-d H:i:s')] = $data;
// $fp = fopen('BraintreeSubMerchantUpdate.json', 'w');
// fwrite($fp, json_encode($putJSON));
// fclose($fp);
// }
// }
if($_POST['bt_signature'] && $_POST['bt_payload']) {
try {
$webhookNotification = Braintree_WebhookNotification::parse(
$_POST['bt_signature'], $_POST['bt_payload']
);
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
$message =
"[Webhook Received " . $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] "
. "Kind: " . $webhookNotification->kind . " | ". "SubMerchantID: " . $webhookNotification->merchantAccount->id . " | ". "status: " . $webhookNotification->merchantAccount->status . " | ";
file_put_contents("BraintreeSubMerchantWebhook.log", $message, FILE_APPEND);
file_put_contents('BraintreeSubMerchantWebhook.txt', print_r($webhookNotification, true), FILE_APPEND);
if (isset($webhookNotification->merchantAccount->id) && isset($webhookNotification->merchantAccount->status)) {
$this->db->trans_start();
$webhookArray['braintree_sub_merchant_status'] = $webhookNotification->merchantAccount->status;
$this->db->where('braintree_sub_merchant_id', $webhookNotification->merchantAccount->id);
$this->db->update('rt_restaurant', $webhookArray);
$this->db->trans_complete();
// Inform Restaurant Owner
$this->db->trans_start();
$this->db->select('bt_email');
$this->db->from('rt_restaurant');
$this->db->where('braintree_sub_merchant_id', $webhookNotification->merchantAccount->id);
$query = $this->db->get();
$restaurant_data = $query->row();
$to = $restaurant_data->bt_email;
$this->db->trans_complete();
$logo = base_url().'assets/logo-main.png';
$image_path = base_url().'assets/';
$variables = array();
$only_link = base_url().'restaurantadmin/';
$variables['only_link'] = $only_link;
$variables['logo'] = $logo;
$variables['image_path'] = $image_path;
$variables['to_email'] = $to;
$variables['site_address'] = SITE_ADDRESS;
$variables['sender_name'] = SITENAME;
$variables['site_name'] = SITENAME;
$template_name = 'braintree_status';
$mail_data = $this->frontend_model->getEmailTemplate($template_name);
$mailcontent=htmlspecialchars_decode($mail_data->template);
$subject = $mail_data->subject;
foreach($variables as $key => $value) {
$mailcontent = str_replace('{{'.$key.'}}', $value, $mailcontent);
}
$this->send_my_mail($to, $subject, $mailcontent);
// $this->send_my_mail('earthtechnology7@gmail.com', $subject, $mailcontent);
}
}
}
function send_my_mail($mail_To,$mail_subject,$mail_Body,$mail_CC="") {
$mail_From = SITENAME;
$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = SMTP_HOST; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password It should be same as that of the SMTP user
$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = $mail_From;
$emailArr = explode(',',$mail_To);
foreach($emailArr AS $emailVal) {
$mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
}
/*$emailCCArr = explode(',',$mail_CC);
foreach($emailCCArr AS $emailCCVal) {
$mail->AddCC($emailCCVal, ""); //Email address where you wish to receive/collect those emails.
}*/
$mail->WordWrap = 100; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $mail_subject;
$message = $mail_Body;
$mail->Body = $message;
if(!$mail->Send())
{
/*echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;*/
}
else
{
//echo 'ok';
}
return true;
}
}