diff --git a/system/autoload/Paymentgateway.php b/system/autoload/Paymentgateway.php index 8dcdb0e0..ee0f913b 100644 --- a/system/autoload/Paymentgateway.php +++ b/system/autoload/Paymentgateway.php @@ -1,23 +1,25 @@ $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", diff --git a/system/controllers/callback.php b/system/controllers/callback.php new file mode 100644 index 00000000..0f2426e6 --- /dev/null +++ b/system/controllers/callback.php @@ -0,0 +1,28 @@ +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"; +} \ No newline at end of file diff --git a/system/controllers/order.php b/system/controllers/order.php index ebeecdf9..ab4e27f2 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -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")); diff --git a/system/lan/indonesia/common.lan.php b/system/lan/indonesia/common.lan.php index d67e96e3..c8f25c68 100644 --- a/system/lan/indonesia/common.lan.php +++ b/system/lan/indonesia/common.lan.php @@ -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'; diff --git a/ui/ui/app-midtrans.tpl b/ui/ui/app-midtrans.tpl index 12527919..20dd1566 100644 --- a/ui/ui/app-midtrans.tpl +++ b/ui/ui/app-midtrans.tpl @@ -38,7 +38,7 @@
- +

{Lang::T('Finish Redirect URL, Unfinish Redirect URL, Error Redirect URL')}

https://dashboard.midtrans.com/settings/vtweb_configuration
diff --git a/ui/ui/sections/user-header.tpl b/ui/ui/sections/user-header.tpl index 099dd58b..7b0787a4 100644 --- a/ui/ui/sections/user-header.tpl +++ b/ui/ui/sections/user-header.tpl @@ -138,8 +138,7 @@ diff --git a/ui/ui/user-orderPPOE.tpl b/ui/ui/user-orderPPOE.tpl deleted file mode 100644 index e6e1eca7..00000000 --- a/ui/ui/user-orderPPOE.tpl +++ /dev/null @@ -1,48 +0,0 @@ -{include file="sections/user-header.tpl"} -
-
-
-
Order PPOE
-
- {foreach $routers as $router} -
-
{$router['name']}
- {if $router['description'] != ''} -
- {$router['description']} -
- {/if} - -
- {foreach $plans as $plan} - {if $router['name'] eq $plan['routers']} -
-
-
{$plan['name_plan']}
-
- - - - - - - - - - - -
Price{$plan['price']}
Validity{$plan['validity']} {$plan['validity_unit']}
-
- -
-
- {/if} - {/foreach} -
-
- {/foreach} -
-
-{include file="sections/user-footer.tpl"} diff --git a/ui/ui/user-orderHotspot.tpl b/ui/ui/user-orderPackage.tpl similarity index 78% rename from ui/ui/user-orderHotspot.tpl rename to ui/ui/user-orderPackage.tpl index 8b5d6727..a26aae39 100644 --- a/ui/ui/user-orderHotspot.tpl +++ b/ui/ui/user-orderPackage.tpl @@ -2,7 +2,7 @@
-
Order Hotspot
+
{Lang::T('Order Internet Package')}
{foreach $routers as $router}
@@ -22,6 +22,10 @@
+ + + + @@ -34,7 +38,7 @@
{Lang::T('Type')}{$plan['type']}
Price {$plan['price']}
diff --git a/ui/ui/user-orderView.tpl b/ui/ui/user-orderView.tpl index 1190a0ff..00210536 100644 --- a/ui/ui/user-orderView.tpl +++ b/ui/ui/user-orderView.tpl @@ -75,7 +75,10 @@ {if $trx['status']==1}