Files
Sample
admin
docs
pages_template
qrcode
system
autoload
PEAR2
Admin.php
App.php
Paginator.php
Password.php
Paymentgateway.php
Recharge.php
Router.php
Timezone.php
User.php
Validator.php
index.html
controllers
install
lan
paymentgateway
uploads
vendors
boot.php
config.sample.php
cron.php
index.html
orm.php
radius.php
ui
.gitignore
LICENSE
README.md
index.php
mitrobill/system/autoload/Paymentgateway.php

176 lines
6.3 KiB
PHP
Raw Normal View History

2022-09-05 15:12:00 +07:00
<?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';
2022-09-08 17:09:21 +07:00
$tripay_server = 'https://tripay.co.id/api/transaction/create';
2022-09-05 15:12:00 +07:00
}else{
$xendit_server = 'https://api.xendit.co/v2/';
$midtrans_server = 'https://api.sandbox.midtrans.com';
2022-09-08 17:09:21 +07:00
$tripay_server = 'https://tripay.co.id/api-sandbox/transaction/create';
2022-09-05 15:12:00 +07:00
}
2022-09-08 17:09:21 +07:00
function xendit_create_invoice($trxID, $amount, $phone, $description){
2022-09-05 15:12:00 +07:00
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']
],
2022-09-08 17:09:21 +07:00
'payment_methods ' => explode(',',$_c['xendit_channel']),
'success_redirect_url' => U.'order/view/'.$trxID,
'failure_redirect_url' => U.'order/view/'.$trxID
2022-09-05 15:12:00 +07:00
];
2022-09-08 17:09:21 +07:00
return json_decode(postJsonData($xendit_server.'invoices', $json, ['Authorization: Basic '.base64_encode($_c['xendit_secret_key'].':')]),true);
2022-09-05 15:12:00 +07:00
/*
{
"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"
}
*/
}
2022-09-08 17:09:21 +07:00
function xendit_get_invoice($xendittrxID){
2022-09-05 15:12:00 +07:00
global $xendit_server,$_c;
return json_decode(getData($xendit_server.'invoices/'.$xendittrxID, [
2022-09-08 17:09:21 +07:00
'Authorization: Basic '.base64_encode($_c['xendit_secret_key'].':')
2022-09-05 15:12:00 +07:00
]),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"
}
*/
}
2022-09-09 16:46:39 +07:00
/** MIDTRANS */
function midtrans_create_payment($trxID, $amount){
global $midtrans_server,$_c;
$json = [
'transaction_details ' => [
'order_id' => $trxID,
'gross_amount' => $amount,
"payment_link_id" => alphanumeric(ucwords($_c['CompanyName']))."_".crc32($_c['CompanyName'])."_".$trxID
],
'enabled_payments' => explode(',',$_c['midtrans_channel']),
"usage_limit"=> 1,
"expiry" => [
"duration" => 24,
"unit" => "hour"
]
];
$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']));
}
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;
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"
}
*/
}
2022-09-05 15:12:00 +07:00
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;
}