midtrans succes paid, but will be drop
This commit is contained in:
parent
dd46273a04
commit
71e8b8e22f
@ -1,22 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
|
||||
|
||||
// Payment Gateway Server
|
||||
if($_app_stage = 'Live'){
|
||||
if ($_app_stage == 'Live') {
|
||||
$xendit_server = 'https://api.xendit.co/v2/';
|
||||
$midtrans_server = 'https://api.midtrans.com';
|
||||
$tripay_server = 'https://tripay.co.id/api/transaction/create';
|
||||
$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/transaction/create';
|
||||
$midtrans_server = 'https://api.sandbox.midtrans.com/';
|
||||
$tripay_server = 'https://tripay.co.id/api-sandbox/';
|
||||
}
|
||||
|
||||
|
||||
function xendit_create_invoice($trxID, $amount, $phone, $description){
|
||||
function xendit_create_invoice($trxID, $amount, $phone, $description)
|
||||
{
|
||||
global $xendit_server, $_c;
|
||||
$json = [
|
||||
'external_id' => $trxID,
|
||||
@ -32,8 +34,8 @@ function xendit_create_invoice($trxID, $amount, $phone, $description){
|
||||
'invoice_expired' => ['whatsapp', 'sms']
|
||||
],
|
||||
'payment_methods ' => explode(',', $_c['xendit_channel']),
|
||||
'success_redirect_url' => U.'order/view/'.$trxID,
|
||||
'failure_redirect_url' => U.'order/view/'.$trxID
|
||||
'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);
|
||||
@ -55,7 +57,8 @@ function xendit_create_invoice($trxID, $amount, $phone, $description){
|
||||
*/
|
||||
}
|
||||
|
||||
function xendit_get_invoice($xendittrxID){
|
||||
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'] . ':')
|
||||
@ -81,22 +84,31 @@ function xendit_get_invoice($xendittrxID){
|
||||
/** MIDTRANS */
|
||||
|
||||
|
||||
function midtrans_create_payment($trxID, $amount){
|
||||
function midtrans_create_payment($trxID, $invoiceID, $amount, $description)
|
||||
{
|
||||
global $midtrans_server, $_c;
|
||||
$json = [
|
||||
'transaction_details' => [
|
||||
'order_id' => $trxID,
|
||||
'gross_amount' => $amount,
|
||||
"payment_link_id" => alphanumeric(ucwords($_c['CompanyName']))."_".crc32($_c['CompanyName'])."_".$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"=> 1,
|
||||
"usage_limit" => 4,
|
||||
"expiry" => [
|
||||
"duration" => 24,
|
||||
"unit" => "hour"
|
||||
"unit" => "hours"
|
||||
]
|
||||
];
|
||||
$json = json_decode(postJsonData($midtrans_server.'v1/payment-links', $json, ['Authorization: Basic '.base64_encode($_c['midtrans_server_key'].':')]),true);
|
||||
$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']));
|
||||
}
|
||||
@ -109,8 +121,10 @@ function midtrans_create_payment($trxID, $amount){
|
||||
*/
|
||||
}
|
||||
|
||||
function midtrans_check_payment($midtranstrxID){
|
||||
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);
|
||||
|
28
system/controllers/callback.php
Normal file
28
system/controllers/callback.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
_auth();
|
||||
$ui->assign('_system_menu', 'order');
|
||||
$action = $routes['1'];
|
||||
$user = User::_info();
|
||||
$ui->assign('_user', $user);
|
||||
|
||||
|
||||
require('system/autoload/Paymentgateway.php');
|
||||
require('system/autoload/Recharge.php');
|
||||
|
||||
switch ($action) {
|
||||
case 'xendit':
|
||||
echo "done";
|
||||
break;
|
||||
case 'midtrans':
|
||||
echo "done";
|
||||
break;
|
||||
case 'tripay':
|
||||
echo "done";
|
||||
break;
|
||||
default:
|
||||
echo "not found";
|
||||
}
|
@ -18,33 +18,43 @@ switch ($action) {
|
||||
$ui->assign('_title', $_L['Order_Voucher'] . ' - ' . $config['CompanyName']);
|
||||
$ui->display('user-order.tpl');
|
||||
break;
|
||||
case 'ppoe':
|
||||
case 'package':
|
||||
$ui->assign('_title', 'Order PPOE Internet - ' . $config['CompanyName']);
|
||||
$routers = ORM::for_table('tbl_routers')->find_many();
|
||||
$plans = ORM::for_table('tbl_plans')->where('type', 'PPPOE')->where('enabled', '1')->find_many();
|
||||
$plans = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
|
||||
$ui->assign('routers', $routers);
|
||||
$ui->assign('plans', $plans);
|
||||
$ui->display('user-orderPPOE.tpl');
|
||||
break;
|
||||
case 'hotspot':
|
||||
$ui->assign('_title', 'Order Hotspot Internet - ' . $config['CompanyName']);
|
||||
$routers = ORM::for_table('tbl_routers')->find_many();
|
||||
$plans = ORM::for_table('tbl_plans')->where('type', 'Hotspot')->where('enabled', '1')->find_many();
|
||||
$ui->assign('routers', $routers);
|
||||
$ui->assign('plans', $plans);
|
||||
$ui->display('user-orderHotspot.tpl');
|
||||
$ui->display('user-orderPackage.tpl');
|
||||
break;
|
||||
case 'unpaid':
|
||||
$d = ORM::for_table('tbl_payment_gateway')
|
||||
->where('username', $user['username'])
|
||||
->where('status', 1)
|
||||
->find_one();
|
||||
if($d){
|
||||
if (empty($d['pg_url_payment'])) {
|
||||
r2(U . "order/buy/" . $trx['routers_id'] .'/'.$trx['plan_id'], 'w', Lang::T("Checking payment"));
|
||||
}else{
|
||||
r2(U . "order/view/" . $d['id'].'/check/', 's', Lang::T("You have unpaid transaction"));
|
||||
}
|
||||
}else{
|
||||
r2(U . "order/package/", 's', Lang::T("You have no unpaid transaction"));
|
||||
}
|
||||
case 'view':
|
||||
$trxid = $routes['2'] * 1;
|
||||
$trx = ORM::for_table('tbl_payment_gateway')
|
||||
->where('username', $user['username'])
|
||||
->find_one($trxid);
|
||||
// jika url kosong, balikin ke buy
|
||||
if (empty($trx['pg_url_payment'])) {
|
||||
r2(U . "order/buy/" . $trx['routers_id'] .'/'.$trx['plan_id'], 'w', Lang::T("Checking payment"));
|
||||
}
|
||||
if ($routes['3'] == 'check') {
|
||||
if ($trx['gateway'] == 'xendit') {
|
||||
$result = xendit_get_invoice($trx['gateway_trx_id']);
|
||||
if ($result['status'] == 'PENDING') {
|
||||
r2(U . "order/view/" . $trxid, 'w', Lang::T("Transaction still unpaid."));
|
||||
} else if ($result['status'] == 'PAID' && $trx['status'] != 2) {
|
||||
} else if (in_array($result['status'],['PAID','SETTLED']) && $trx['status'] != 2) {
|
||||
|
||||
if (!rechargeUser($user['id'], $trx['routers'], $trx['plan_id'], 'xendit', $result['payment_method'] . ' ' . $result['payment_channel'])) {
|
||||
r2(U . "order/view/" . $trxid, 'd', Lang::T("Failed to activate your Package, try again later."));
|
||||
@ -66,17 +76,25 @@ switch ($action) {
|
||||
}else if($trx['status'] == 2){
|
||||
r2(U . "order/view/" . $trxid, 'd', Lang::T("Transaction has been paid.."));
|
||||
}
|
||||
print_r($result);
|
||||
die();
|
||||
r2(U . "order/view/" . $trxid, 'd', Lang::T("Unknown Command."));
|
||||
} else if ($trx['gateway'] == 'midtrans') {
|
||||
$result = midtrans_check_payment($trx['gateway_trx_id']);
|
||||
print_r($result);
|
||||
} else if ($trx['gateway'] == 'tripay') {
|
||||
}
|
||||
} else if ($routes['3'] == 'cancel') {
|
||||
$trx->pg_paid_response = json_encode($result);
|
||||
$trx->pg_paid_response = '{}';
|
||||
$trx->status = 4;
|
||||
$trx->paid_date = date('Y-m-d H:i:s');
|
||||
$trx->save();
|
||||
$trx = ORM::for_table('tbl_payment_gateway')
|
||||
->where('username', $user['username'])
|
||||
->find_one($trxid);
|
||||
if('midtrans'==$trx['gateway']){
|
||||
//Hapus invoice link
|
||||
}
|
||||
}
|
||||
if (empty($trx)) {
|
||||
r2(U . "home", 'e', Lang::T("Transaction Not found"));
|
||||
@ -91,9 +109,8 @@ switch ($action) {
|
||||
$ui->assign('_title', 'TRX #' . $trxid . ' - ' . $config['CompanyName']);
|
||||
$ui->display('user-orderView.tpl');
|
||||
break;
|
||||
case 'ppoe-buy':
|
||||
case 'hotspot-buy':
|
||||
$back = "order/".str_replace('-buy','',$action);
|
||||
case 'buy':
|
||||
$back = "order/package";
|
||||
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2'] * 1);
|
||||
$plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3'] * 1);
|
||||
if (empty($router) || empty($plan)) {
|
||||
@ -103,6 +120,7 @@ switch ($action) {
|
||||
->where('username', $user['username'])
|
||||
->where('status', 1)
|
||||
->find_one();
|
||||
if($d){
|
||||
if ($d['pg_url_payment']) {
|
||||
r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it."));
|
||||
}else{
|
||||
@ -113,6 +131,7 @@ switch ($action) {
|
||||
$d->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(empty($id)){
|
||||
$d = ORM::for_table('tbl_payment_gateway')->create();
|
||||
$d->username = $user['username'];
|
||||
@ -157,15 +176,17 @@ switch ($action) {
|
||||
r2(U . $back, 'e', Lang::T("Admin has not yet setup Midtrans payment gateway, please tell admin"));
|
||||
}
|
||||
if ($id) {
|
||||
$result = midtrans_create_payment($id, $plan['price']);
|
||||
$invoiceID = alphanumeric(strtolower($_c['CompanyName'])) . "-" . crc32($_c['CompanyName'] . $id) . "-" . $id;
|
||||
$result = midtrans_create_payment($id, $invoiceID, $plan['price'],$plan['name_plan']);
|
||||
if (!$result['payment_url']) {
|
||||
sendTelegram("Midtrans payment failed\n\n".json_encode($result, JSON_PRETTY_PRINT));
|
||||
r2(U . $back, 'e', Lang::T("Failed to create transaction."));
|
||||
}
|
||||
$d = ORM::for_table('tbl_payment_gateway')
|
||||
->where('username', $user['username'])
|
||||
->where('status', 1)
|
||||
->find_one();
|
||||
$d->gateway_trx_id = $result['order_id'];
|
||||
$d->gateway_trx_id = $invoiceID;
|
||||
$d->pg_url_payment = $result['payment_url'];
|
||||
$d->pg_request = json_encode($result);
|
||||
$d->expired_date = date('Y-m-d H:i:s', strtotime("+1 days"));
|
||||
|
@ -274,3 +274,10 @@ $_L['Transaction_has_been_paid'] = 'Transaction has been paid.';
|
||||
$_L['PAID'] = 'PAID';
|
||||
$_L['Buy_Hotspot_Plan'] = 'Buy Hotspot Plan';
|
||||
$_L['Buy_PPOE_Plan'] = 'Buy PPOE Plan';
|
||||
$_L['Package'] = 'Package';
|
||||
$_L['Package'] = 'Package';
|
||||
$_L['Order_Internet_Package'] = 'Order Internet Package';
|
||||
$_L['Unknown_Command'] = 'Unknown Command.';
|
||||
$_L['Checking_payment'] = 'Checking payment';
|
||||
$_L['Create_Transaction_Success'] = 'Create Transaction Success';
|
||||
$_L['You_have_unpaid_transaction'] = 'You have unpaid transaction';
|
||||
|
@ -38,7 +38,7 @@
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Finish Redirect URL</label>
|
||||
<div class="col-md-6">
|
||||
<input type="text" readonly class="form-control" onclick="this.select()" value="{$_url}accounts/transaction">
|
||||
<input type="text" readonly class="form-control" onclick="this.select()" value="{$_url}order/unpaid">
|
||||
<p class="help-block">{Lang::T('Finish Redirect URL, Unfinish Redirect URL, Error Redirect URL')}</p>
|
||||
<a href="https://dashboard.midtrans.com/settings/vtweb_configuration" target="_blank" class="help-block">https://dashboard.midtrans.com/settings/vtweb_configuration</a>
|
||||
</div>
|
||||
|
@ -138,8 +138,7 @@
|
||||
<ul class="inner-drop list-unstyled">
|
||||
<li {if $_system_menu eq 'order'}class="active"{/if}><a href="{$_url}order/voucher">Voucher</a></li>
|
||||
{if $_c['payment_gateway'] != 'none' or $_c['payment_gateway'] == '' }
|
||||
<li {if $_system_menu eq 'order'}class="active"{/if}><a href="{$_url}order/hotspot">Hotspot</a></li>
|
||||
<li {if $_system_menu eq 'order'}class="active"{/if}><a href="{$_url}order/ppoe">PPOE</a></li>
|
||||
<li {if $_system_menu eq 'order'}class="active"{/if}><a href="{$_url}order/package">{Lang::T('Package')}</a></li>
|
||||
{/if}
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -1,48 +0,0 @@
|
||||
{include file="sections/user-header.tpl"}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="panel mb20 panel-default panel-hovered">
|
||||
<div class="panel-heading">Order PPOE</div>
|
||||
</div>
|
||||
{foreach $routers as $router}
|
||||
<div class="panel mb20 panel-info panel-hovered">
|
||||
<div class="panel-heading">{$router['name']}</div>
|
||||
{if $router['description'] != ''}
|
||||
<div class="panel-body">
|
||||
{$router['description']}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="panel-body row">
|
||||
{foreach $plans as $plan}
|
||||
{if $router['name'] eq $plan['routers']}
|
||||
<div class="col-sm-3">
|
||||
<div class="panel mb10 panel-default panel-hovered">
|
||||
<div class="panel-heading"> {$plan['name_plan']}</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-striped">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Price</td>
|
||||
<td>{$plan['price']}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Validity</td>
|
||||
<td>{$plan['validity']} {$plan['validity_unit']}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<a href="{$_url}order/hotspot-buy/{$router['id']}/{$plan['id']}" onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')" class="btn btn-sm btn-block btn-primary">Buy</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
{include file="sections/user-footer.tpl"}
|
@ -2,7 +2,7 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="panel mb20 panel-default panel-hovered">
|
||||
<div class="panel-heading">Order Hotspot</div>
|
||||
<div class="panel-heading">{Lang::T('Order Internet Package')}</div>
|
||||
</div>
|
||||
{foreach $routers as $router}
|
||||
<div class="panel mb20 panel-info panel-hovered">
|
||||
@ -22,6 +22,10 @@
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-striped">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{Lang::T('Type')}</td>
|
||||
<td>{$plan['type']}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Price</td>
|
||||
<td>{$plan['price']}</td>
|
||||
@ -34,7 +38,7 @@
|
||||
</table>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<a href="{$_url}order/hotspot-buy/{$router['id']}/{$plan['id']}" onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')" class="btn btn-sm btn-block btn-primary">Buy</a>
|
||||
<a href="{$_url}order/buy/{$router['id']}/{$plan['id']}" onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')" class="btn btn-sm btn-block btn-primary">Buy</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -75,7 +75,10 @@
|
||||
{if $trx['status']==1}
|
||||
<div class="panel-footer ">
|
||||
<div class="btn-group btn-group-justified">
|
||||
<a href="{$trx['pg_url_payment']}" target="_blank" class="btn btn-primary">{Lang::T('PAY NOW')}</a>
|
||||
<a href="{$trx['pg_url_payment']}"
|
||||
{if $trx['gateway']=='midtrans'}
|
||||
target="_blank"
|
||||
{/if} class="btn btn-primary">{Lang::T('PAY NOW')}</a>
|
||||
<a href="{$_url}order/view/{$trx['id']}/check" class="btn btn-info">{Lang::T('Check for Payment')}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user