forked from kevinowino869/mitrobill
midtrans succes paid, but will be drop
This commit is contained in:
@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
||||
**/
|
||||
* 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';
|
||||
}else{
|
||||
$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){
|
||||
global $xendit_server,$_c;
|
||||
function xendit_create_invoice($trxID, $amount, $phone, $description)
|
||||
{
|
||||
global $xendit_server, $_c;
|
||||
$json = [
|
||||
'external_id' => $trxID,
|
||||
'amount' => $amount,
|
||||
@ -25,18 +27,18 @@ function xendit_create_invoice($trxID, $amount, $phone, $description){
|
||||
'customer' => [
|
||||
'mobile_number' => $phone,
|
||||
],
|
||||
'customer_notification_preference'=>[
|
||||
'invoice_created' => ['whatsapp','sms'],
|
||||
'invoice_reminder' => ['whatsapp','sms'],
|
||||
'invoice_paid' => ['whatsapp','sms'],
|
||||
'invoice_expired' => ['whatsapp','sms']
|
||||
'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,
|
||||
'failure_redirect_url' => U.'order/view/'.$trxID
|
||||
'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);
|
||||
return json_decode(postJsonData($xendit_server . 'invoices', $json, ['Authorization: Basic ' . base64_encode($_c['xendit_secret_key'] . ':')]), true);
|
||||
/*
|
||||
{
|
||||
"id": "631597513897510bace2459d", #gateway_trx_id
|
||||
@ -55,11 +57,12 @@ function xendit_create_invoice($trxID, $amount, $phone, $description){
|
||||
*/
|
||||
}
|
||||
|
||||
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);
|
||||
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
|
||||
@ -81,24 +84,33 @@ function xendit_get_invoice($xendittrxID){
|
||||
/** MIDTRANS */
|
||||
|
||||
|
||||
function midtrans_create_payment($trxID, $amount){
|
||||
global $midtrans_server,$_c;
|
||||
function midtrans_create_payment($trxID, $invoiceID, $amount, $description)
|
||||
{
|
||||
global $midtrans_server, $_c;
|
||||
$json = [
|
||||
'transaction_details ' => [
|
||||
'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
|
||||
],
|
||||
'enabled_payments' => explode(',',$_c['midtrans_channel']),
|
||||
"usage_limit"=> 1,
|
||||
"item_details" => [
|
||||
[
|
||||
"name" => $description,
|
||||
"price" => intval($amount),
|
||||
"quantity" => 1
|
||||
]
|
||||
],
|
||||
'enabled_payments' => explode(',', $_c['midtrans_channel']),
|
||||
"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);
|
||||
if(!empty($json['error_messages'])){
|
||||
sendTelegram(json_encode("Midtrans create Payment error:\n".alphanumeric($_c['CompanyName'])."_".crc32($_c['CompanyName'])."_".$trxID."\n".$json['error_messages']));
|
||||
$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;
|
||||
/*
|
||||
@ -109,11 +121,13 @@ function midtrans_create_payment($trxID, $amount){
|
||||
*/
|
||||
}
|
||||
|
||||
function midtrans_check_payment($midtranstrxID){
|
||||
global $midtrans_server,$_c;
|
||||
return json_decode(getData($midtrans_server.'v2/'.$midtranstrxID.'/status', [
|
||||
'Authorization: Basic '.base64_encode($_c['midtrans_server_key'].':')
|
||||
]),true);
|
||||
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",
|
||||
|
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,14 +120,16 @@ switch ($action) {
|
||||
->where('username', $user['username'])
|
||||
->where('status', 1)
|
||||
->find_one();
|
||||
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{
|
||||
if($_c['payment_gateway']==$d['gateway']){
|
||||
$id = $d['id'];
|
||||
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{
|
||||
$d->status = 4;
|
||||
$d->save();
|
||||
if($_c['payment_gateway']==$d['gateway']){
|
||||
$id = $d['id'];
|
||||
}else{
|
||||
$d->status = 4;
|
||||
$d->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
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"));
|
||||
}
|
||||
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';
|
||||
|
Reference in New Issue
Block a user