midtrans succes paid, but will be drop

This commit is contained in:
Ibnu Maksum 2022-09-10 12:17:38 +07:00
parent dd46273a04
commit 71e8b8e22f
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
9 changed files with 147 additions and 119 deletions

View File

@ -1,23 +1,25 @@
<?php <?php
/** /**
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/) * PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
**/ **/
// Payment Gateway Server // Payment Gateway Server
if($_app_stage = 'Live'){ if ($_app_stage == 'Live') {
$xendit_server = 'https://api.xendit.co/v2/'; $xendit_server = 'https://api.xendit.co/v2/';
$midtrans_server = 'https://api.midtrans.com'; $midtrans_server = 'https://api.midtrans.com/';
$tripay_server = 'https://tripay.co.id/api/transaction/create'; $tripay_server = 'https://tripay.co.id/api/';
}else{ } else {
$xendit_server = 'https://api.xendit.co/v2/'; $xendit_server = 'https://api.xendit.co/v2/';
$midtrans_server = 'https://api.sandbox.midtrans.com'; $midtrans_server = 'https://api.sandbox.midtrans.com/';
$tripay_server = 'https://tripay.co.id/api-sandbox/transaction/create'; $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; {
global $xendit_server, $_c;
$json = [ $json = [
'external_id' => $trxID, 'external_id' => $trxID,
'amount' => $amount, 'amount' => $amount,
@ -25,18 +27,18 @@ function xendit_create_invoice($trxID, $amount, $phone, $description){
'customer' => [ 'customer' => [
'mobile_number' => $phone, 'mobile_number' => $phone,
], ],
'customer_notification_preference'=>[ 'customer_notification_preference' => [
'invoice_created' => ['whatsapp','sms'], 'invoice_created' => ['whatsapp', 'sms'],
'invoice_reminder' => ['whatsapp','sms'], 'invoice_reminder' => ['whatsapp', 'sms'],
'invoice_paid' => ['whatsapp','sms'], 'invoice_paid' => ['whatsapp', 'sms'],
'invoice_expired' => ['whatsapp','sms'] 'invoice_expired' => ['whatsapp', 'sms']
], ],
'payment_methods ' => explode(',',$_c['xendit_channel']), 'payment_methods ' => explode(',', $_c['xendit_channel']),
'success_redirect_url' => U.'order/view/'.$trxID, 'success_redirect_url' => U . 'order/view/' . $trxID . '/check',
'failure_redirect_url' => U.'order/view/'.$trxID '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); return json_decode(postJsonData($xendit_server . 'invoices', $json, ['Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')]), true);
/* /*
{ {
"id": "631597513897510bace2459d", #gateway_trx_id "id": "631597513897510bace2459d", #gateway_trx_id
@ -55,11 +57,12 @@ 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, [ global $xendit_server, $_c;
'Authorization: Basic '.base64_encode($_c['xendit_secret_key'].':') return json_decode(getData($xendit_server . 'invoices/' . $xendittrxID, [
]),true); 'Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')
]), true);
/* /*
{ {
"id": "631597513897510bace2459d", #gateway_trx_id "id": "631597513897510bace2459d", #gateway_trx_id
@ -81,24 +84,33 @@ function xendit_get_invoice($xendittrxID){
/** MIDTRANS */ /** MIDTRANS */
function midtrans_create_payment($trxID, $amount){ function midtrans_create_payment($trxID, $invoiceID, $amount, $description)
global $midtrans_server,$_c; {
global $midtrans_server, $_c;
$json = [ $json = [
'transaction_details ' => [ 'transaction_details' => [
'order_id' => $trxID, 'order_id' => $trxID,
'gross_amount' => $amount, 'gross_amount' => intval($amount),
"payment_link_id" => alphanumeric(ucwords($_c['CompanyName']))."_".crc32($_c['CompanyName'])."_".$trxID "payment_link_id" => $invoiceID
], ],
'enabled_payments' => explode(',',$_c['midtrans_channel']), "item_details" => [
"usage_limit"=> 1, [
"name" => $description,
"price" => intval($amount),
"quantity" => 1
]
],
'enabled_payments' => explode(',', $_c['midtrans_channel']),
"usage_limit" => 4,
"expiry" => [ "expiry" => [
"duration" => 24, "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'] . ':')]);
if(!empty($json['error_messages'])){ $json = json_decode($data, true);
sendTelegram(json_encode("Midtrans create Payment error:\n".alphanumeric($_c['CompanyName'])."_".crc32($_c['CompanyName'])."_".$trxID."\n".$json['error_messages'])); 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; return $json;
/* /*
@ -109,11 +121,13 @@ function midtrans_create_payment($trxID, $amount){
*/ */
} }
function midtrans_check_payment($midtranstrxID){ function midtrans_check_payment($midtranstrxID)
global $midtrans_server,$_c; {
return json_decode(getData($midtrans_server.'v2/'.$midtranstrxID.'/status', [ global $midtrans_server, $_c;
'Authorization: Basic '.base64_encode($_c['midtrans_server_key'].':') echo $midtrans_server . 'v2/' . $midtranstrxID . '/status';
]),true); return json_decode(getData($midtrans_server . 'v2/' . $midtranstrxID . '/status', [
'Authorization: Basic ' . base64_encode($_c['midtrans_server_key'] . ':')
]), true);
/* /*
{ {
"masked_card": "41111111-1111", "masked_card": "41111111-1111",

View 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";
}

View File

@ -18,33 +18,43 @@ switch ($action) {
$ui->assign('_title', $_L['Order_Voucher'] . ' - ' . $config['CompanyName']); $ui->assign('_title', $_L['Order_Voucher'] . ' - ' . $config['CompanyName']);
$ui->display('user-order.tpl'); $ui->display('user-order.tpl');
break; break;
case 'ppoe': case 'package':
$ui->assign('_title', 'Order PPOE Internet - ' . $config['CompanyName']); $ui->assign('_title', 'Order PPOE Internet - ' . $config['CompanyName']);
$routers = ORM::for_table('tbl_routers')->find_many(); $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('routers', $routers);
$ui->assign('plans', $plans); $ui->assign('plans', $plans);
$ui->display('user-orderPPOE.tpl'); $ui->display('user-orderPackage.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');
break; 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': case 'view':
$trxid = $routes['2'] * 1; $trxid = $routes['2'] * 1;
$trx = ORM::for_table('tbl_payment_gateway') $trx = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username']) ->where('username', $user['username'])
->find_one($trxid); ->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 ($routes['3'] == 'check') {
if ($trx['gateway'] == 'xendit') { if ($trx['gateway'] == 'xendit') {
$result = xendit_get_invoice($trx['gateway_trx_id']); $result = xendit_get_invoice($trx['gateway_trx_id']);
if ($result['status'] == 'PENDING') { if ($result['status'] == 'PENDING') {
r2(U . "order/view/" . $trxid, 'w', Lang::T("Transaction still unpaid.")); 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'])) { 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.")); 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){ }else if($trx['status'] == 2){
r2(U . "order/view/" . $trxid, 'd', Lang::T("Transaction has been paid..")); 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.")); r2(U . "order/view/" . $trxid, 'd', Lang::T("Unknown Command."));
} else if ($trx['gateway'] == 'midtrans') { } else if ($trx['gateway'] == 'midtrans') {
$result = midtrans_check_payment($trx['gateway_trx_id']);
print_r($result);
} else if ($trx['gateway'] == 'tripay') { } else if ($trx['gateway'] == 'tripay') {
} }
} else if ($routes['3'] == 'cancel') { } else if ($routes['3'] == 'cancel') {
$trx->pg_paid_response = json_encode($result); $trx->pg_paid_response = '{}';
$trx->status = 4; $trx->status = 4;
$trx->paid_date = date('Y-m-d H:i:s');
$trx->save(); $trx->save();
$trx = ORM::for_table('tbl_payment_gateway') $trx = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username']) ->where('username', $user['username'])
->find_one($trxid); ->find_one($trxid);
if('midtrans'==$trx['gateway']){
//Hapus invoice link
}
} }
if (empty($trx)) { if (empty($trx)) {
r2(U . "home", 'e', Lang::T("Transaction Not found")); r2(U . "home", 'e', Lang::T("Transaction Not found"));
@ -91,9 +109,8 @@ switch ($action) {
$ui->assign('_title', 'TRX #' . $trxid . ' - ' . $config['CompanyName']); $ui->assign('_title', 'TRX #' . $trxid . ' - ' . $config['CompanyName']);
$ui->display('user-orderView.tpl'); $ui->display('user-orderView.tpl');
break; break;
case 'ppoe-buy': case 'buy':
case 'hotspot-buy': $back = "order/package";
$back = "order/".str_replace('-buy','',$action);
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2'] * 1); $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); $plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3'] * 1);
if (empty($router) || empty($plan)) { if (empty($router) || empty($plan)) {
@ -103,14 +120,16 @@ switch ($action) {
->where('username', $user['username']) ->where('username', $user['username'])
->where('status', 1) ->where('status', 1)
->find_one(); ->find_one();
if ($d['pg_url_payment']) { if($d){
r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it.")); if ($d['pg_url_payment']) {
}else{ r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it."));
if($_c['payment_gateway']==$d['gateway']){
$id = $d['id'];
}else{ }else{
$d->status = 4; if($_c['payment_gateway']==$d['gateway']){
$d->save(); $id = $d['id'];
}else{
$d->status = 4;
$d->save();
}
} }
} }
if(empty($id)){ if(empty($id)){
@ -157,15 +176,17 @@ switch ($action) {
r2(U . $back, 'e', Lang::T("Admin has not yet setup Midtrans payment gateway, please tell admin")); r2(U . $back, 'e', Lang::T("Admin has not yet setup Midtrans payment gateway, please tell admin"));
} }
if ($id) { 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']) { 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.")); r2(U . $back, 'e', Lang::T("Failed to create transaction."));
} }
$d = ORM::for_table('tbl_payment_gateway') $d = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username']) ->where('username', $user['username'])
->where('status', 1) ->where('status', 1)
->find_one(); ->find_one();
$d->gateway_trx_id = $result['order_id']; $d->gateway_trx_id = $invoiceID;
$d->pg_url_payment = $result['payment_url']; $d->pg_url_payment = $result['payment_url'];
$d->pg_request = json_encode($result); $d->pg_request = json_encode($result);
$d->expired_date = date('Y-m-d H:i:s', strtotime("+1 days")); $d->expired_date = date('Y-m-d H:i:s', strtotime("+1 days"));

View File

@ -274,3 +274,10 @@ $_L['Transaction_has_been_paid'] = 'Transaction has been paid.';
$_L['PAID'] = 'PAID'; $_L['PAID'] = 'PAID';
$_L['Buy_Hotspot_Plan'] = 'Buy Hotspot Plan'; $_L['Buy_Hotspot_Plan'] = 'Buy Hotspot Plan';
$_L['Buy_PPOE_Plan'] = 'Buy PPOE 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';

View File

@ -38,7 +38,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">Finish Redirect URL</label> <label class="col-md-2 control-label">Finish Redirect URL</label>
<div class="col-md-6"> <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> <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> <a href="https://dashboard.midtrans.com/settings/vtweb_configuration" target="_blank" class="help-block">https://dashboard.midtrans.com/settings/vtweb_configuration</a>
</div> </div>

View File

@ -138,8 +138,7 @@
<ul class="inner-drop list-unstyled"> <ul class="inner-drop list-unstyled">
<li {if $_system_menu eq 'order'}class="active"{/if}><a href="{$_url}order/voucher">Voucher</a></li> <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'] == '' } {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/package">{Lang::T('Package')}</a></li>
<li {if $_system_menu eq 'order'}class="active"{/if}><a href="{$_url}order/ppoe">PPOE</a></li>
{/if} {/if}
</ul> </ul>
</li> </li>

View File

@ -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"}

View File

@ -2,7 +2,7 @@
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<div class="panel mb20 panel-default panel-hovered"> <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> </div>
{foreach $routers as $router} {foreach $routers as $router}
<div class="panel mb20 panel-info panel-hovered"> <div class="panel mb20 panel-info panel-hovered">
@ -22,6 +22,10 @@
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">
<tbody> <tbody>
<tr>
<td>{Lang::T('Type')}</td>
<td>{$plan['type']}</td>
</tr>
<tr> <tr>
<td>Price</td> <td>Price</td>
<td>{$plan['price']}</td> <td>{$plan['price']}</td>
@ -34,7 +38,7 @@
</table> </table>
</div> </div>
<div class="panel-footer"> <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> </div>
</div> </div>

View File

@ -75,7 +75,10 @@
{if $trx['status']==1} {if $trx['status']==1}
<div class="panel-footer "> <div class="panel-footer ">
<div class="btn-group btn-group-justified"> <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> <a href="{$_url}order/view/{$trx['id']}/check" class="btn btn-info">{Lang::T('Check for Payment')}</a>
</div> </div>
</div> </div>