forked from kevinowino869/mitrobill
Payment Gateway Tripay done
This commit is contained in:
43
system/autoload/Http.php
Normal file
43
system/autoload/Http.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
|
||||
class Http
|
||||
{
|
||||
public static function getData($url, $headers)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 0);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $server_output;
|
||||
}
|
||||
|
||||
public static function postJsonData($url, $array_post, $headers = [], $basic = null)
|
||||
{
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array_post));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
if (!empty($basic)) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $basic);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $server_output;
|
||||
}
|
||||
}
|
123
system/autoload/PGTripay.php
Normal file
123
system/autoload/PGTripay.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
*
|
||||
* Payment Gateway Tripay
|
||||
**/
|
||||
|
||||
class PGTripay
|
||||
{
|
||||
protected $user;
|
||||
protected $trx;
|
||||
|
||||
public function __construct($trx, $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->trx = $trx;
|
||||
}
|
||||
|
||||
function getSignature()
|
||||
{
|
||||
global $_c;
|
||||
return hash_hmac('sha256', $_c['tripay_merchant'] . $this->trx['id'] . $this->trx['price'], $_c['tripay_secret_key']);
|
||||
}
|
||||
|
||||
function createTransaction($channel) //$trxID, $channel, $amount, $user, $description)
|
||||
{
|
||||
global $_c;
|
||||
$json = [
|
||||
'method' => $channel,
|
||||
'amount' => $this->trx['price'],
|
||||
'merchant_ref' => $this->trx['id'],
|
||||
'customer_name' => $this->user['fullname'],
|
||||
'customer_email' => (empty($this->user['email'])) ? $this->user['username'] . '@' . $_SERVER['HTTP_HOST'] : $this->user['email'],
|
||||
'customer_phone' => $this->user['phonenumber'],
|
||||
'order_items' => [
|
||||
[
|
||||
'name' => $this->trx['plan_name'],
|
||||
'price' => $this->trx['price'],
|
||||
'quantity' => 1
|
||||
]
|
||||
],
|
||||
'return_url' => U . 'order/view/' . $this->trx['id'] . '/check',
|
||||
'signature' => $this->getSignature()
|
||||
];
|
||||
return json_decode(Http::postJsonData($this->getServer() . 'transaction/create', $json, ['Authorization: Bearer ' . $_c['tripay_api_key']]), true);
|
||||
/*
|
||||
{
|
||||
"success": true,
|
||||
"message": "",
|
||||
"data": {
|
||||
"reference": "T0001000000000000006",
|
||||
"merchant_ref": "INV345675",
|
||||
"payment_selection_type": "static",
|
||||
"payment_method": "BRIVA",
|
||||
"payment_name": "BRI Virtual Account",
|
||||
"customer_name": "Nama Pelanggan",
|
||||
"customer_email": "emailpelanggan@domain.com",
|
||||
"customer_phone": "081234567890",
|
||||
"callback_url": "https://domainanda.com/callback",
|
||||
"return_url": "https://domainanda.com/redirect",
|
||||
"amount": 1000000,
|
||||
"fee_merchant": 1500,
|
||||
"fee_customer": 0,
|
||||
"total_fee": 1500,
|
||||
"amount_received": 998500,
|
||||
"pay_code": "57585748548596587",
|
||||
"pay_url": null,
|
||||
"checkout_url": "https://tripay.co.id/checkout/T0001000000000000006",
|
||||
"status": "UNPAID",
|
||||
"expired_time": 1582855837,
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function getStatus($trxID)
|
||||
{
|
||||
global $_c;
|
||||
return json_decode(Http::getData($this->getServer() . 'transaction/detail?'.http_build_query(['reference'=>$trxID]), [
|
||||
'Authorization: Bearer ' . $_c['tripay_api_key']
|
||||
]), true);
|
||||
/*
|
||||
{
|
||||
"success": true,
|
||||
"message": "",
|
||||
"data": {
|
||||
"reference": "T0001000000000000006",
|
||||
"merchant_ref": "INV345675",
|
||||
"payment_selection_type": "static",
|
||||
"payment_method": "BRIVA",
|
||||
"payment_name": "BRI Virtual Account",
|
||||
"customer_name": "Nama Pelanggan",
|
||||
"customer_email": "emailpelanggan@domain.com",
|
||||
"customer_phone": "081234567890",
|
||||
"callback_url": "https://domainanda.com/callback",
|
||||
"return_url": "https://domainanda.com/redirect",
|
||||
"amount": 1000000,
|
||||
"fee_merchant": 1500,
|
||||
"fee_customer": 0,
|
||||
"total_fee": 1500,
|
||||
"amount_received": 998500,
|
||||
"pay_code": "57585748548596587",
|
||||
"pay_url": null,
|
||||
"checkout_url": "https://tripay.co.id/checkout/T0001000000000000006",
|
||||
"status": "PAID",
|
||||
"expired_time": 1582855837,
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private function getServer()
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'Live') {
|
||||
return 'https://tripay.co.id/api/';
|
||||
} else {
|
||||
return 'https://tripay.co.id/api-sandbox/';
|
||||
}
|
||||
}
|
||||
}
|
93
system/autoload/PGXendit.php
Normal file
93
system/autoload/PGXendit.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
*
|
||||
* Payment Gateway Xendit
|
||||
**/
|
||||
|
||||
class PGTripay {
|
||||
protected $user;
|
||||
protected $trx;
|
||||
protected $channel;
|
||||
|
||||
public function __construct($trx,$user) {
|
||||
$this->user = $user;
|
||||
$this->trx = $trx;
|
||||
return $this;
|
||||
}
|
||||
|
||||
function createInvoice()
|
||||
{
|
||||
global $_c;
|
||||
$json = [
|
||||
'external_id' => $this->trx['id'],
|
||||
'amount' => $this->trx['price'],
|
||||
'description' => $this->trx['plan_name'],
|
||||
'customer' => [
|
||||
'mobile_number' => $this->user['phonenumber'],
|
||||
],
|
||||
'customer_notification_preference' => [
|
||||
'invoice_created' => ['whatsapp', 'sms'],
|
||||
'invoice_reminder' => ['whatsapp', 'sms'],
|
||||
'invoice_paid' => ['whatsapp', 'sms'],
|
||||
'invoice_expired' => ['whatsapp', 'sms']
|
||||
],
|
||||
'payment_methods ' => explode(',', $_c['xendit_channel']),
|
||||
'success_redirect_url' => U . 'order/view/' . $this->trx['id'] . '/check',
|
||||
'failure_redirect_url' => U . 'order/view/' . $this->trx['id'] . '/check'
|
||||
];
|
||||
|
||||
return json_decode(Http::postJsonData($this->getServer() . 'invoices', $json, ['Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')]), true);
|
||||
/*
|
||||
{
|
||||
"id": "631597513897510bace2459d", #gateway_trx_id
|
||||
"external_id": "test-va-success-1662359375",
|
||||
"user_id": "599bd7f1ccab55b020bb1147",
|
||||
"status": "PENDING",
|
||||
"merchant_name": "Xendit",
|
||||
"merchant_profile_picture_url": "https://xnd-companies.s3.amazonaws.com/prod/1538466380522_868.png",
|
||||
"amount": 3000000,
|
||||
"description": "Test - VA Successful invoice payment",
|
||||
"expiry_date": "2022-09-06T06:29:37.251Z",
|
||||
"invoice_url": "https://checkout-staging.xendit.co/web/631597513897510bace2459d"
|
||||
"created": "2022-09-05T06:29:37.954Z",
|
||||
"updated": "2022-09-05T06:29:37.954Z"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function getInvoice($xendittrxID)
|
||||
{
|
||||
global $_c;
|
||||
return json_decode(Http::getData($this->getServer() . 'invoices/' . $xendittrxID, [
|
||||
'Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')
|
||||
]), true);
|
||||
/*
|
||||
{
|
||||
"id": "631597513897510bace2459d", #gateway_trx_id
|
||||
"external_id": "test-va-success-1662359375",
|
||||
"user_id": "599bd7f1ccab55b020bb1147",
|
||||
"status": "PENDING", // CHECK THIS
|
||||
"merchant_name": "Xendit",
|
||||
"merchant_profile_picture_url": "https://xnd-companies.s3.amazonaws.com/prod/1538466380522_868.png",
|
||||
"amount": 3000000,
|
||||
"description": "Test - VA Successful invoice payment",
|
||||
"expiry_date": "2022-09-06T06:29:37.251Z",
|
||||
"invoice_url": "https://checkout-staging.xendit.co/web/631597513897510bace2459d"
|
||||
"created": "2022-09-05T06:29:37.954Z",
|
||||
"updated": "2022-09-05T06:29:37.954Z"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private function getServer(){
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'Live') {
|
||||
return 'https://api.xendit.co/v2/';
|
||||
} else {
|
||||
return 'https://api.xendit.co/v2/';
|
||||
}
|
||||
}
|
||||
}
|
378
system/autoload/Package.php
Normal file
378
system/autoload/Package.php
Normal file
@ -0,0 +1,378 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
|
||||
class Package
|
||||
{
|
||||
public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel)
|
||||
{
|
||||
global $_c, $_L;
|
||||
$date_now = date("Y-m-d H:i:s");
|
||||
$date_only = date("Y-m-d");
|
||||
$time = date("H:i:s");
|
||||
|
||||
if ($id_customer == '' or $router_name == '' or $plan_id == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one();
|
||||
$b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one();
|
||||
|
||||
$mikrotik = Router::_info($router_name);
|
||||
if ($p['validity_unit'] == 'Months') {
|
||||
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month'));
|
||||
} else if ($p['validity_unit'] == 'Days') {
|
||||
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' day'));
|
||||
} else if ($p['validity_unit'] == 'Hrs') {
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' hour')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
} else if ($p['validity_unit'] == 'Mins') {
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' minute')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
}
|
||||
|
||||
if ($p['type'] == 'Hotspot') {
|
||||
if ($b) {
|
||||
if (!$_c['radius_mode']) {
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>" . $e->getMessage());
|
||||
}
|
||||
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user print .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/remove');
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
/* iBNuX Added:
|
||||
* Time limit to Mikrotik
|
||||
* 'Time_Limit', 'Data_Limit', 'Both_Limit'
|
||||
*/
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
if ($p['typebp'] == "Limited") {
|
||||
if ($p['limit_type'] == "Time_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Data_Limit") {
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Both_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan_id;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
$b->method = "$gateway - $channel";
|
||||
$b->routers = $router_name;
|
||||
$b->type = "Hotspot";
|
||||
$b->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "Hotspot";
|
||||
$t->save();
|
||||
} else {
|
||||
if (!$_c['radius_mode']) {
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>" . $e->getMessage());
|
||||
}
|
||||
|
||||
/* iBNuX Added:
|
||||
* Time limit to Mikrotik
|
||||
* 'Time_Limit', 'Data_Limit', 'Both_Limit'
|
||||
*/
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
if ($p['typebp'] == "Limited") {
|
||||
if ($p['limit_type'] == "Time_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Data_Limit") {
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Both_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_user_recharges')->create();
|
||||
$d->customer_id = $id_customer;
|
||||
$d->username = $c['username'];
|
||||
$d->plan_id = $plan_id;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
$d->method = "$gateway - $channel";
|
||||
$d->routers = $router_name;
|
||||
$d->type = "Hotspot";
|
||||
$d->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "Hotspot";
|
||||
$t->save();
|
||||
}
|
||||
sendTelegram("#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
|
||||
"\nRouter: " . $router_name .
|
||||
"\nGateway: " . $gateway .
|
||||
"\nChannel: " . $channel .
|
||||
"\nPrice: " . $p['price']);
|
||||
} else {
|
||||
|
||||
if ($b) {
|
||||
if (!$_c['radius_mode']) {
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>" . $e->getMessage());
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ppp secret print .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
|
||||
$addRequest = new RouterOS\Request('/ppp/secret/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('service', 'pppoe')
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan_id;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
$b->method = "$gateway - $channel";
|
||||
$b->routers = $router_name;
|
||||
$b->type = "PPPOE";
|
||||
$b->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "PPPOE";
|
||||
$t->save();
|
||||
} else {
|
||||
if (!$_c['radius_mode']) {
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>" . $e->getMessage());
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ppp/secret/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('service', 'pppoe')
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_user_recharges')->create();
|
||||
$d->customer_id = $id_customer;
|
||||
$d->username = $c['username'];
|
||||
$d->plan_id = $plan_id;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
$d->method = "$gateway - $channel";
|
||||
$d->routers = $router_name;
|
||||
$d->type = "PPPOE";
|
||||
$d->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "PPPOE";
|
||||
$t->save();
|
||||
}
|
||||
sendTelegram("#u$c[username] #buy #PPPOE \n" . $p['name_plan'] .
|
||||
"\nRouter: " . $router_name .
|
||||
"\nGateway: " . $gateway .
|
||||
"\nChannel: " . $channel .
|
||||
"\nPrice: " . $p['price']);
|
||||
}
|
||||
|
||||
$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();
|
||||
|
||||
sendWhatsapp($c['username'], "*$_c[CompanyName]*\n" .
|
||||
"$_c[address]\n" .
|
||||
"$_c[phone]\n" .
|
||||
"\n\n" .
|
||||
"INVOICE: *$in[invoice]*\n" .
|
||||
"$_L[Date] : $date_now\n" .
|
||||
"$gateway $channel\n" .
|
||||
"\n\n" .
|
||||
"$_L[Type] : *$in[type]*\n" .
|
||||
"$_L[Plan_Name] : *$in[plan_name]*\n" .
|
||||
"$_L[Plan_Price] : *$_c[currency_code] " . number_format($in['price'], 2, $_c['dec_point'], $_c['thousands_sep']) . "*\n\n" .
|
||||
"$_L[Username] : *$in[username]*\n" .
|
||||
"$_L[Password] : **********\n\n" .
|
||||
"$_L[Created_On] :\n*" . date($_c['date_format'], strtotime($in['recharged_on'])) . " $in[time]*\n" .
|
||||
"$_L[Expires_On] :\n*" . date($_c['date_format'], strtotime($in['expiration'])) . " $in[time]*\n" .
|
||||
"\n\n" .
|
||||
"$_c[note]");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,189 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
|
||||
|
||||
// Payment Gateway Server
|
||||
if ($_app_stage == 'Live') {
|
||||
$xendit_server = 'https://api.xendit.co/v2/';
|
||||
$midtrans_server = 'https://api.midtrans.com/';
|
||||
$tripay_server = 'https://tripay.co.id/api/';
|
||||
} else {
|
||||
$xendit_server = 'https://api.xendit.co/v2/';
|
||||
$midtrans_server = 'https://api.sandbox.midtrans.com/';
|
||||
$tripay_server = 'https://tripay.co.id/api-sandbox/';
|
||||
}
|
||||
|
||||
|
||||
function xendit_create_invoice($trxID, $amount, $phone, $description)
|
||||
{
|
||||
global $xendit_server, $_c;
|
||||
$json = [
|
||||
'external_id' => $trxID,
|
||||
'amount' => $amount,
|
||||
'description' => $description,
|
||||
'customer' => [
|
||||
'mobile_number' => $phone,
|
||||
],
|
||||
'customer_notification_preference' => [
|
||||
'invoice_created' => ['whatsapp', 'sms'],
|
||||
'invoice_reminder' => ['whatsapp', 'sms'],
|
||||
'invoice_paid' => ['whatsapp', 'sms'],
|
||||
'invoice_expired' => ['whatsapp', 'sms']
|
||||
],
|
||||
'payment_methods ' => explode(',', $_c['xendit_channel']),
|
||||
'success_redirect_url' => U . 'order/view/' . $trxID . '/check',
|
||||
'failure_redirect_url' => U . 'order/view/' . $trxID . '/check'
|
||||
];
|
||||
|
||||
return json_decode(postJsonData($xendit_server . 'invoices', $json, ['Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')]), true);
|
||||
/*
|
||||
{
|
||||
"id": "631597513897510bace2459d", #gateway_trx_id
|
||||
"external_id": "test-va-success-1662359375",
|
||||
"user_id": "599bd7f1ccab55b020bb1147",
|
||||
"status": "PENDING",
|
||||
"merchant_name": "Xendit",
|
||||
"merchant_profile_picture_url": "https://xnd-companies.s3.amazonaws.com/prod/1538466380522_868.png",
|
||||
"amount": 3000000,
|
||||
"description": "Test - VA Successful invoice payment",
|
||||
"expiry_date": "2022-09-06T06:29:37.251Z",
|
||||
"invoice_url": "https://checkout-staging.xendit.co/web/631597513897510bace2459d"
|
||||
"created": "2022-09-05T06:29:37.954Z",
|
||||
"updated": "2022-09-05T06:29:37.954Z"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function xendit_get_invoice($xendittrxID)
|
||||
{
|
||||
global $xendit_server, $_c;
|
||||
return json_decode(getData($xendit_server . 'invoices/' . $xendittrxID, [
|
||||
'Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')
|
||||
]), true);
|
||||
/*
|
||||
{
|
||||
"id": "631597513897510bace2459d", #gateway_trx_id
|
||||
"external_id": "test-va-success-1662359375",
|
||||
"user_id": "599bd7f1ccab55b020bb1147",
|
||||
"status": "PENDING", // CHECK THIS
|
||||
"merchant_name": "Xendit",
|
||||
"merchant_profile_picture_url": "https://xnd-companies.s3.amazonaws.com/prod/1538466380522_868.png",
|
||||
"amount": 3000000,
|
||||
"description": "Test - VA Successful invoice payment",
|
||||
"expiry_date": "2022-09-06T06:29:37.251Z",
|
||||
"invoice_url": "https://checkout-staging.xendit.co/web/631597513897510bace2459d"
|
||||
"created": "2022-09-05T06:29:37.954Z",
|
||||
"updated": "2022-09-05T06:29:37.954Z"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/** MIDTRANS */
|
||||
|
||||
|
||||
function midtrans_create_payment($trxID, $invoiceID, $amount, $description)
|
||||
{
|
||||
global $midtrans_server, $_c;
|
||||
$json = [
|
||||
'transaction_details' => [
|
||||
'order_id' => $trxID,
|
||||
'gross_amount' => intval($amount),
|
||||
"payment_link_id" => $invoiceID
|
||||
],
|
||||
"item_details" => [
|
||||
[
|
||||
"name" => $description,
|
||||
"price" => intval($amount),
|
||||
"quantity" => 1
|
||||
]
|
||||
],
|
||||
'enabled_payments' => explode(',', $_c['midtrans_channel']),
|
||||
"usage_limit" => 4,
|
||||
"expiry" => [
|
||||
"duration" => 24,
|
||||
"unit" => "hours"
|
||||
]
|
||||
];
|
||||
$data = postJsonData($midtrans_server . 'v1/payment-links', $json, ['Authorization: Basic ' . base64_encode($_c['midtrans_server_key'] . ':')]);
|
||||
$json = json_decode($data, true);
|
||||
if (!empty($json['error_messages'])) {
|
||||
sendTelegram(json_encode("Midtrans create Payment error:\n" . alphanumeric($_c['CompanyName']) . "_" . crc32($_c['CompanyName']) . "_" . $trxID . "\n" . $json['error_messages']));
|
||||
}
|
||||
return $json;
|
||||
/*
|
||||
{
|
||||
"order_id": "concert-ticket-05", //traxid
|
||||
"payment_url": "https://app.sandbox.midtrans.com/payment-links/amazing-ticket-payment-123"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function midtrans_check_payment($midtranstrxID)
|
||||
{
|
||||
global $midtrans_server, $_c;
|
||||
echo $midtrans_server . 'v2/' . $midtranstrxID . '/status';
|
||||
return json_decode(getData($midtrans_server . 'v2/' . $midtranstrxID . '/status', [
|
||||
'Authorization: Basic ' . base64_encode($_c['midtrans_server_key'] . ':')
|
||||
]), true);
|
||||
/*
|
||||
{
|
||||
"masked_card": "41111111-1111",
|
||||
"approval_code": "1599493766402",
|
||||
"bank": "bni",
|
||||
"channel_response_code": "00",
|
||||
"channel_response_message": "Approved",
|
||||
"transaction_time": "2020-09-07 22:49:26",
|
||||
"gross_amount": "10000.00",
|
||||
"currency": "IDR",
|
||||
"order_id": "SANDBOX-G710367688-806",
|
||||
"payment_type": "credit_card",
|
||||
"signature_key": "4d4abc70f5a88b09f48f3ab5cb91245feb0b3d89181117a677767b42f8cbe477f5a0d38af078487071311f97da646c1eb9542c1bbf0b19fa9f12e64605ac405e",
|
||||
"status_code": "200",
|
||||
"transaction_id": "3853c491-ca9b-4bcc-ac20-3512ff72a5d0",
|
||||
"transaction_status": "cancel",
|
||||
"fraud_status": "challenge",
|
||||
"status_message": "Success, transaction is found",
|
||||
"merchant_id": "G710367688",
|
||||
"card_type": "credit"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function getData($url, $headers)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 0);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $server_output;
|
||||
}
|
||||
|
||||
|
||||
function postJsonData($url, $array_post, $headers = [], $basic = null)
|
||||
{
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array_post));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
if (!empty($basic)) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $basic);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $server_output;
|
||||
}
|
@ -1,374 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
|
||||
function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel){
|
||||
global $_c,$_L;
|
||||
$date_now = date("Y-m-d H:i:s");
|
||||
$date_only = date("Y-m-d");
|
||||
$time = date("H:i:s");
|
||||
|
||||
if ($id_customer == '' or $router_name == '' or $plan_id == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one();
|
||||
$b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one();
|
||||
|
||||
$mikrotik = Router::_info($router_name);
|
||||
if($p['validity_unit']=='Months'){
|
||||
$date_exp = date("Y-m-d", strtotime('+'.$p['validity'].' month'));
|
||||
}else if($p['validity_unit']=='Days'){
|
||||
$date_exp = date("Y-m-d", strtotime('+'.$p['validity'].' day'));
|
||||
}else if($p['validity_unit']=='Hrs'){
|
||||
$datetime = explode(' ',date("Y-m-d H:i:s", strtotime('+'.$p['validity'].' hour')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
}else if($p['validity_unit']=='Mins'){
|
||||
$datetime = explode(' ',date("Y-m-d H:i:s", strtotime('+'.$p['validity'].' minute')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
}
|
||||
|
||||
if ($p['type'] == 'Hotspot') {
|
||||
if ($b) {
|
||||
if(!$_c['radius_mode']){
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user print .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/remove');
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
/* iBNuX Added:
|
||||
* Time limit to Mikrotik
|
||||
* 'Time_Limit', 'Data_Limit', 'Both_Limit'
|
||||
*/
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
if ($p['typebp'] == "Limited") {
|
||||
if ($p['limit_type'] == "Time_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Data_Limit") {
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Both_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan_id;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
$b->method = "admin";
|
||||
$b->routers = $router_name;
|
||||
$b->type = "Hotspot";
|
||||
$b->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "admin";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "Hotspot";
|
||||
$t->save();
|
||||
} else {
|
||||
if(!$_c['radius_mode']){
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
|
||||
/* iBNuX Added:
|
||||
* Time limit to Mikrotik
|
||||
* 'Time_Limit', 'Data_Limit', 'Both_Limit'
|
||||
*/
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
if ($p['typebp'] == "Limited") {
|
||||
if ($p['limit_type'] == "Time_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Data_Limit") {
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
} else if ($p['limit_type'] == "Both_Limit") {
|
||||
if ($p['time_unit'] == 'Hrs')
|
||||
$timelimit = $p['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $p['time_limit'] . ":00";
|
||||
if ($p['data_unit'] == 'GB')
|
||||
$datalimit = $p['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $p['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_user_recharges')->create();
|
||||
$d->customer_id = $id_customer;
|
||||
$d->username = $c['username'];
|
||||
$d->plan_id = $plan_id;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
$d->method = "admin";
|
||||
$d->routers = $router_name;
|
||||
$d->type = "Hotspot";
|
||||
$d->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "admin";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "Hotspot";
|
||||
$t->save();
|
||||
}
|
||||
sendTelegram( "#$c[username] #buy #Hotspot \n".$p['name_plan'].
|
||||
"\nRouter: ".$router_name.
|
||||
"\nGateway: ".$gateway.
|
||||
"\nChannel: ".$channel.
|
||||
"\nPrice: ".$p['price']);
|
||||
} else {
|
||||
|
||||
if ($b) {
|
||||
if(!$_c['radius_mode']){
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ppp secret print .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
|
||||
$addRequest = new RouterOS\Request('/ppp/secret/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('service', 'pppoe')
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan_id;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
$b->method = "admin";
|
||||
$b->routers = $router_name;
|
||||
$b->type = "PPPOE";
|
||||
$b->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "admin";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "PPPOE";
|
||||
$t->save();
|
||||
} else {
|
||||
if(!$_c['radius_mode']){
|
||||
try {
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ppp/secret/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('service', 'pppoe')
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_user_recharges')->create();
|
||||
$d->customer_id = $id_customer;
|
||||
$d->username = $c['username'];
|
||||
$d->plan_id = $plan_id;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
$d->method = "admin";
|
||||
$d->routers = $router_name;
|
||||
$d->type = "PPPOE";
|
||||
$d->save();
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "admin";
|
||||
$t->routers = $router_name;
|
||||
$t->type = "PPPOE";
|
||||
$t->save();
|
||||
}
|
||||
sendTelegram( "#$c[username] #buy #PPPOE \n".$p['name_plan'].
|
||||
"\nRouter: ".$router_name.
|
||||
"\nGateway: ".$gateway.
|
||||
"\nChannel: ".$channel.
|
||||
"\nPrice: ".$p['price']);
|
||||
}
|
||||
|
||||
$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();
|
||||
|
||||
sendWhatsapp($c['username'], "*$_c[CompanyName]*\n".
|
||||
"$_c[address]\n".
|
||||
"$_c[phone]\n".
|
||||
"\n\n".
|
||||
"INVOICE: *$in[invoice]*\n".
|
||||
"$_L[Date] : $date_now\n".
|
||||
"$gateway $channel\n".
|
||||
"\n\n".
|
||||
"$_L[Type] : *$in[type]*\n".
|
||||
"$_L[Plan_Name] : *$in[plan_name]*\n".
|
||||
"$_L[Plan_Price] : *$_c[currency_code] ".number_format($in['price'],2,$_c['dec_point'],$_c['thousands_sep'])."*\n\n".
|
||||
"$_L[Username] : *$in[username]*\n".
|
||||
"$_L[Password] : **********\n\n".
|
||||
"$_L[Created_On] :\n*".date($_c['date_format'], strtotime($in['recharged_on']))." $in[time]*\n".
|
||||
"$_L[Expires_On] :\n*".date($_c['date_format'], strtotime($in['expiration']))." $in[time]*\n".
|
||||
"\n\n".
|
||||
"$_c[note]");
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user