DigiflazzModel
unknown
php
5 years ago
69 kB
15
Indexable
<?php
//'tes' => number_format(200 / 100, 2, ",", "."),
defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Pelanggan extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('ci_ext_model', 'ci_ext');
$ci_ext = $this->ci_ext->ciext();
if (!$ci_ext) {
redirect(gagal);
}
$this->load->helper("url");
$this->load->database();
$this->load->model('Pelanggan_model');
$this->load->model('Driver_model');
$this->load->model('Digiflazz_model', 'digiflazz');
$this->load->model('appsettings_model', 'app');
date_default_timezone_set('Asia/Jakarta');
if ($this->uri->segment(3) == "login" || $this->uri->segment(3) == "privacy" || $this->uri->segment(3) == "wallet" || $this->uri->segment(3) == "list_payment" || $this->uri->segment(3) == "check_trx" || $this->uri->segment(3) == "req_trx" || $this->uri->segment(3) == "forget" || $this->uri->segment(3) == "register_user") {
$this->config->set_item("rest_enable_keys", FALSE);
}
}
function index_get()
{
$this->response("Api for ouride!", 200);
}
function privacy_post()
{
$app_settings = $this->Pelanggan_model->get_settings();
$message = array(
'code' => '200',
'message' => 'found',
'data' => $app_settings
);
$this->response($message, 200);
}
function forgot_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'email' => $decoded_data->email,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
$app_settings = $this->Pelanggan_model->get_settings();
$token = sha1(rand(0, 999999) . time());
if ($cek_login->num_rows() > 0) {
$cheker = array('msg' => $cek_login->result());
foreach ($app_settings as $item) {
foreach ($cheker['msg'] as $item2 => $val) {
$dataforgot = array(
'userid' => $val->id,
'token' => $token,
'idKey' => '1'
);
}
$forgot = $this->Pelanggan_model->dataforgot($dataforgot);
$linkbtn = base_url() . 'resetpass/rest/' . $token . '/1';
$template = $this->Pelanggan_model->template1($item['email_subject'], $item['email_text1'], $item['email_text2'], $item['app_website'], $item['app_name'], $linkbtn, $item['app_linkgoogle'], $item['app_address']);
$sendmail = $this->Pelanggan_model->emailsend($item['email_subject'] . " [ticket-" . rand(0, 999999) . "]", $decoded_data->email, $template, $item['smtp_host'], $item['smtp_port'], $item['smtp_username'], $item['smtp_password'], $item['smtp_from'], $item['app_name'], $item['smtp_secure']);
}
if ($forgot && $sendmail) {
$message = array(
'code' => '200',
'message' => 'found',
'data' => []
);
$this->response($message, 200);
} else {
$message = array(
'code' => '401',
'message' => 'email not registered',
'data' => []
);
$this->response($message, 200);
}
} else {
$message = array(
'code' => '404',
'message' => 'email not registered',
'data' => []
);
$this->response($message, 200);
}
}
function verif_ktp_post()
{
$apikey = $this->input->request_headers()['x-api-key'];
$userid = $this->Pelanggan_model->get_userid($apikey);
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$noktp = $dec_data->noktp;
$nama = $dec_data->nama;
$ktp = $dec_data->ktp;
$wajah = $dec_data->wajah;
if (!$noktp || !$nama || !$ktp || !$wajah) {
$message = array(
'message' => 'Masih terdapat data yang kosong!',
'status' => 0
);
$this->response($message, 200);
} else {
$image_ktp = time() . '-' . rand(0, 99999) . ".jpg";
$image_wajah = time() . '-' . rand(0, 99999) . ".jpg";
$path = "images/verif/ktp/" . $image_ktp;
file_put_contents($path, base64_decode($ktp));
$path = "images/verif/wajah/" . $image_wajah;
file_put_contents($path, base64_decode($wajah));
$data = array(
'userid' => $userid,
'nik' => $noktp,
'nama' => $nama,
'image_ktp' => $image_ktp,
'image_wajah' => $image_wajah
);
$this->Pelanggan_model->insert_verif($data);
$message = array(
'message' => 'Data diterima, silahkan tunggu verifikasi admin',
'status' => 1
);
$this->response($message, 200);
}
}
function login_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$reg_id = array(
'token' => $decoded_data->token
);
$condition = array(
'password' => sha1($decoded_data->password),
'no_telepon' => $decoded_data->no_telepon,
//'token' => $decoded_data->token
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
if ($check_banned) {
$message = array(
'message' => 'banned',
'data' => []
);
$this->response($message, 200);
} else {
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
$message = array();
if ($cek_login->num_rows() > 0) {
$apikey = $decoded_data->token ? password_hash($decoded_data->token, PASSWORD_BCRYPT) : password_hash(md5("sukses2020" + md5(time())), PASSWORD_BCRYPT);
$upd_regid = $this->Pelanggan_model->edit_profile($reg_id, $decoded_data->no_telepon);
$get_pelanggan = $this->Pelanggan_model->get_data_pelanggan($condition);
$data = $get_pelanggan->result_array();
$data[0]['apikey'] = $apikey;
$userid = $data[0]["id"];
$this->Pelanggan_model->insert_apikey($apikey, $userid);
$message = array(
'code' => '200',
'message' => 'found',
'data' => $data
);
$this->response($message, 200);
} else {
$message = array(
'code' => '404',
'message' => 'wrong phone or password',
'data' => []
);
$this->response($message, 200);
}
}
}
function register_user_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$email = $dec_data->email;
$phone = $dec_data->no_telepon;
$check_exist = $this->Pelanggan_model->check_exist($email, $phone);
$check_exist_phone = $this->Pelanggan_model->check_exist_phone($phone);
$check_exist_email = $this->Pelanggan_model->check_exist_email($email);
if ($check_exist) {
$message = array(
'code' => '201',
'message' => 'email and phone number already exist',
'data' => []
);
$this->response($message, 201);
} else if ($check_exist_phone) {
$message = array(
'code' => '201',
'message' => 'phone already exist',
'data' => []
);
$this->response($message, 201);
} else if ($check_exist_email) {
$message = array(
'code' => '201',
'message' => 'email already exist',
'data' => []
);
$this->response($message, 201);
} else {
if ($dec_data->checked == "true") {
$message = array(
'code' => '200',
'message' => 'next',
'data' => []
);
$this->response($message, 200);
} else {
$apikey = $dec_data->token ? password_hash($dec_data->token, PASSWORD_BCRYPT) : password_hash(md5("sukses2020" + md5(time())), PASSWORD_BCRYPT);
$image = $dec_data->fotopelanggan;
$namafoto = time() . '-' . rand(0, 99999) . ".jpg";
$path = "images/pelanggan/" . $namafoto;
file_put_contents($path, base64_decode($image));
$userid = 'P' . time();
$data_signup = array(
'id' => $userid,
'fullnama' => $dec_data->fullnama,
'email' => $dec_data->email,
'no_telepon' => $dec_data->no_telepon,
'phone' => $dec_data->phone,
'password' => sha1($dec_data->password),
'tgl_lahir' => $dec_data->tgl_lahir,
'countrycode' => $dec_data->countrycode,
'fotopelanggan' => $namafoto,
'token' => $dec_data->token,
);
$signup = $this->Pelanggan_model->signup($data_signup);
$this->Pelanggan_model->insert_apikey($apikey, $userid);
if ($signup) {
$condition = array(
'password' => sha1($dec_data->password),
'email' => $dec_data->email
);
$datauser1 = $this->Pelanggan_model->get_data_pelanggan($condition)->result_array();
$datauser1[0]["apikey"] = $apikey;
$message = array(
'code' => '200',
'message' => 'success',
'data' => $datauser1
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
}
}
function food_post()
{
//sleep(2);
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$merchantnearby = $this->Pelanggan_model->merchantnearby($long, $lat);
$kategorymerchant = $this->Pelanggan_model->allfoodcategory()->result();
$merchantpromo = $this->Pelanggan_model->merchantpromo($long, $lat)->result();
$slider = $this->Pelanggan_model->sliderfood();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login) {
$message = array(
'code' => '200',
'message' => 'success',
'foodkategori' => $kategorymerchant,
'merchantpromo' => $merchantpromo,
'merchantnearby' => $merchantnearby,
'slider' => $slider
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function is_verif_ktp_post()
{
$apikey = $this->input->request_headers()['x-api-key'];
$verif = $this->Pelanggan_model->check_verif_by_apikey($apikey);
$this->response(['status_verif' => $verif], 200);
}
function pembayaran_slider_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$slider = $this->Pelanggan_model->sliderPembayaran();
$berita = $this->Pelanggan_model->beritahome();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login) {
$message = array(
'slider' => $slider,
'berita' => $berita
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function list_pulsa_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$pulsa = $this->Pelanggan_model->listPulsa($dec_data->jenis, $dec_data->category);
$saldo = $this->Pelanggan_model->saldouser($dec_data->id);
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login) {
$message = array(
'produk' => $pulsa,
'saldo' => $saldo->row('saldo')
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function prabayar_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$prabayar = $this->Pelanggan_model->listPrabayar($dec_data->jenis, strtoupper($dec_data->brand));
$saldo = $this->Pelanggan_model->saldouser($dec_data->id);
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login) {
$message = array(
'produk' => $prabayar,
'saldo' => $saldo->row('saldo')
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function list_emoney_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$emoney = $this->Pelanggan_model->listEmoney();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login) {
$message = array(
'emoney' => $emoney,
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function list_prabayar_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$emoney = $this->Pelanggan_model->listPrabayarByJenis($dec_data->jenis, strtoupper($dec_data->brand));
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login) {
$message = array(
'list' => $emoney,
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function pabayarbyjenis()
{
}
function home_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$slider = $this->Pelanggan_model->sliderhome();
$fitur = $this->Pelanggan_model->fiturhome();
$allfitur = $this->Pelanggan_model->fiturhomeall();
$rating = $this->Pelanggan_model->ratinghome();
$saldo = $this->Pelanggan_model->saldouser($dec_data->id);
$app_settings = $this->Pelanggan_model->get_settings();
$berita = $this->Pelanggan_model->beritahome();
$kategorymerchant = $this->Pelanggan_model->kategorymerchant()->result();
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$merchantpromo = $this->Pelanggan_model->merchantpromo($long, $lat)->result();
$merchantnearby = $this->Pelanggan_model->merchantnearby($long, $lat);
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
foreach ($app_settings as $item) {
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'saldo' => $saldo->row('saldo'),
'currency' => $item['app_currency'],
'currency_text' => $item['app_currency_text'],
'app_aboutus' => $item['app_aboutus'],
'app_contact' => $item['app_contact'],
'app_website' => $item['app_website'],
'stripe_active' => $item['stripe_active'],
'paypal_key' => $item['paypal_key'],
'paypal_mode' => $item['paypal_mode'],
'paypal_active' => $item['paypal_active'],
'app_email' => $item['app_email'],
'slider' => $slider,
'fitur' => $fitur,
'allfitur' => $allfitur,
'ratinghome' => $rating,
'beritahome' => $berita,
'kategorymerchanthome' => $kategorymerchant,
'merchantnearby' => $merchantnearby,
'merchantpromo' => $merchantpromo,
'data' => $cek_login->result()
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
}
public function merchantbykategori_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$kategori = $dec_data->kategori;
$fitur = $dec_data->fitur;
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$merchantbykategori = $this->Pelanggan_model->merchantbykategori($kategori, $long, $lat, $fitur)->result();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'merchantbykategori' => $merchantbykategori
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function merchantbykategoripromo_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$kategori = $dec_data->kategori;
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$merchantbykategori = $this->Pelanggan_model->merchantbykategoripromo($kategori, $long, $lat)->result();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'merchantbykategori' => $merchantbykategori
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function allmerchant_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$fitur = $dec_data->fitur;
$kategorymerchant = $this->Pelanggan_model->kategorymerchantbyfitur($fitur)->result();
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$allmerchantnearby = $this->Pelanggan_model->allmerchantnearby($long, $lat, $fitur)->result();
$condition = array(
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'kategorymerchant' => $kategorymerchant,
'allmerchantnearby' => $allmerchantnearby
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function allmerchantbykategori_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$fitur = $dec_data->fitur;
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$kategori = $dec_data->kategori;
$allmerchantnearbybykategori = $this->Pelanggan_model->allmerchantnearbybykategori($long, $lat, $fitur, $kategori)->result();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'allmerchantnearby' => $allmerchantnearbybykategori
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function searchmerchant_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$like = $dec_data->like;
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$fitur = $dec_data->fitur;
$kategori = $dec_data->kategori;
$searchmerchantnearby = $this->Pelanggan_model->searchmerchantnearby($like, $long, $lat, $fitur, $kategori);
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'allmerchantnearby' => $searchmerchantnearby
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function merchantbyid_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$idmerchant = $dec_data->idmerchant;
$long = $dec_data->longitude;
$lat = $dec_data->latitude;
$merchantbyid = $this->Pelanggan_model->merchantbyid($idmerchant, $long, $lat)->row();
$itemstatus = $this->Pelanggan_model->itemstatus($idmerchant)->row();
if (empty($itemstatus->status_promo)) {
$itempromo = '0';
} else {
$itempromo = $itemstatus->status_promo;
}
$itembyid = $this->Pelanggan_model->itembyid($idmerchant)->Result();
$kategoriitem = $this->Pelanggan_model->kategoriitem($idmerchant)->Result();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'idfitur' => $merchantbyid->id_fitur,
'idmerchant' => $merchantbyid->id_merchant,
'namamerchant' => $merchantbyid->nama_merchant,
'alamatmerchant' => $merchantbyid->alamat_merchant,
'latmerchant' => $merchantbyid->latitude_merchant,
'longmerchant' => $merchantbyid->longitude_merchant,
'is_24h' => $merchantbyid->is_24h,
'bukamerchant' => $merchantbyid->jam_buka,
'tutupmerchant' => $merchantbyid->jam_tutup,
'descmerchant' => $merchantbyid->deskripsi_merchant,
'fotomerchant' => $merchantbyid->foto_merchant,
'telpcmerchant' => $merchantbyid->telepon_merchant,
'distance' => $merchantbyid->distance,
'partner' => $merchantbyid->partner,
'kategori' => $merchantbyid->nama_kategori,
'promo' => $itempromo,
'itembyid' => $itembyid,
'kategoriitem' => $kategoriitem
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function itembykategori_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$idmerchant = $dec_data->id;
$itemk = $dec_data->kategori;
$itembykategori = $this->Pelanggan_model->itembykategori($idmerchant, $itemk)->result();
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$message = array(
'code' => '200',
'message' => 'success',
'itembyid' => $itembykategori
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
function rate_driver_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$data_rate = array();
if ($dec_data->catatan == "") {
$data_rate = array(
'id_pelanggan' => $dec_data->id_pelanggan,
'id_driver' => $dec_data->id_driver,
'rating' => $dec_data->rating,
'id_transaksi' => $dec_data->id_transaksi
);
} else {
$data_rate = array(
'id_pelanggan' => $dec_data->id_pelanggan,
'id_driver' => $dec_data->id_driver,
'rating' => $dec_data->rating,
'id_transaksi' => $dec_data->id_transaksi,
'catatan' => $dec_data->catatan
);
}
$finish_transaksi = $this->Pelanggan_model->rate_driver($data_rate);
if ($finish_transaksi) {
$message = array(
'message' => 'success',
'data' => []
);
$this->response($message, 200);
} else {
$message = array(
'message' => 'fail',
'data' => []
);
$this->response($message, 200);
}
}
public function upload_tf_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$image = $dec_data->image;
if ($image) {
$namafoto = time() . '-' . rand(0, 99999) . ".jpg";
$path = "images/trx/" . $namafoto;
file_put_contents($path, base64_decode($image));
$this->Pelanggan_model->upload_tf($namafoto, $dec_data->id);
$message = array(
'code' => '200',
'message' => 'success',
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
);
$this->response($message, 201);
}
} else {
$message = array(
'code' => '201',
'message' => 'failed',
);
$this->response($message, 201);
}
}
public function pending_topup_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$condition = array(
'no_telepon' => $dec_data->no_telepon,
'status' => '1'
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$list_topup = $this->Pelanggan_model->listPendingTopup($dec_data->id);
$count = $this->Pelanggan_model->countPendingTopup($dec_data->id);
$message = array(
'code' => '200',
'message' => 'success',
'jumlah' => $count,
'topup' => $list_topup
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'failed',
'data' => []
);
$this->response($message, 201);
}
}
public function topupstripe_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$name = $dec_data->name;
$email = $dec_data->email;
$card_num = $dec_data->card_num;
$card_cvc = $dec_data->cvc;
$card_exp = explode("/", $dec_data->expired);
$product = $dec_data->product;
$number = $dec_data->number;
$price = $dec_data->price;
$iduser = $dec_data->id;
//include Stripe PHP library
require_once APPPATH . "third_party/stripe/init.php";
//set api key
$app_settings = $this->Pelanggan_model->get_settings();
foreach ($app_settings as $item) {
$stripe = array(
"secret_key" => $item['stripe_secret_key'],
"publishable_key" => $item['stripe_published_key']
);
if ($item['stripe_status'] == '1') {
\Stripe\Stripe::setApiKey($stripe['secret_key']);
} else if ($item['stripe_status'] == '2') {
\Stripe\Stripe::setApiKey($stripe['publishable_key']);
} else {
\Stripe\Stripe::setApiKey("");
}
}
$tokenstripe = \Stripe\Token::create([
'card' => [
'number' => $card_num,
'exp_month' => $card_exp[0],
'exp_year' => $card_exp[1],
'cvc' => $card_cvc,
],
]);
if (!empty($tokenstripe['id'])) {
//add customer to stripe
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $tokenstripe['id']
));
//item information
$itemName = $product;
$itemNumber = $number;
$itemPrice = $price;
$currency = "usd";
$orderID = "INV-" . time();
//charge a credit or a debit card
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $itemPrice,
'currency' => $currency,
'description' => $itemNumber,
'metadata' => array(
'item_id' => $itemNumber
)
));
//retrieve charge details
$chargeJson = $charge->jsonSerialize();
//check whether the charge is successful
if ($chargeJson['amount_refunded'] == 0 && empty($chargeJson['failure_code']) && $chargeJson['paid'] == 1 && $chargeJson['captured'] == 1) {
//order details
$amount = $chargeJson['amount'];
$balance_transaction = $chargeJson['balance_transaction'];
$currency = $chargeJson['currency'];
$status = $chargeJson['status'];
$date = date("Y-m-d H:i:s");
$datatopup = array(
'id_user' => $iduser,
'rekening' => $card_num,
'bank' => 'stripe',
'nama_pemilik' => $name,
'type' => 'topup',
'jumlah' => $chargeJson['amount'],
'status' => 1
);
if ($status == 'succeeded') {
$topupdata = $this->Pelanggan_model->insertwallet($datatopup);
$saldolama = $this->Pelanggan_model->saldouser($iduser);
$saldobaru = $saldolama->row('saldo') + $itemPrice;
$saldo = array('saldo' => $saldobaru);
$this->Pelanggan_model->tambahsaldo($iduser, $saldo);
$message = array(
'code' => '200',
'message' => 'success',
'data' => []
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'error',
'data' => []
);
$this->response($message, 200);
}
} else {
$message = array(
'code' => '202',
'message' => 'error',
'data' => []
);
$this->response($message, 200);
}
} else {
echo "Invalid Token";
$statusMsg = "";
}
}
public function topuppaypal_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$iduser = $dec_data->id;
$bank = $dec_data->bank;
$nama = $dec_data->nama;
$amount = $dec_data->amount;
$card = $dec_data->card;
$email = $dec_data->email;
$phone = $dec_data->no_telepon;
$datatopup = array(
'id_user' => $iduser,
'rekening' => $card,
'bank' => $bank,
'nama_pemilik' => $nama,
'type' => 'topup',
'jumlah' => $amount,
'status' => 1
);
$check_exist = $this->Pelanggan_model->check_exist($email, $phone);
if ($check_exist) {
$this->Pelanggan_model->insertwallet($datatopup);
$saldolama = $this->Pelanggan_model->saldouser($iduser);
$saldobaru = $saldolama->row('saldo') + $amount;
$saldo = array('saldo' => $saldobaru);
$this->Pelanggan_model->tambahsaldo($iduser, $saldo);
$message = array(
'code' => '200',
'message' => 'success',
'data' => []
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'You have insufficient balance',
'data' => []
);
$this->response($message, 200);
}
}
public function withdraw_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$iduser = $dec_data->id;
$bank = $dec_data->bank;
$nama = $dec_data->nama;
$amount = $dec_data->amount;
$card = $dec_data->card;
$email = $dec_data->email;
$phone = $dec_data->no_telepon;
$saldolama = $this->Pelanggan_model->saldouser($iduser);
$datawithdraw = array(
'id_user' => $iduser,
'rekening' => $card,
'bank' => $bank,
'nama_pemilik' => $nama,
'type' => $dec_data->type,
'jumlah' => $amount,
'status' => 0
);
$check_exist = $this->Pelanggan_model->check_exist($email, $phone);
$apikey = $this->input->request_headers()['x-api-key'];
$verif = $this->Pelanggan_model->check_verif_by_apikey($apikey);
if ($verif == 0) {
$message = array(
'code' => '401',
'message' => 'Akun kamu belum di verifikasi',
'data' => []
);
$this->response($message, 200);
} else if ($dec_data->type == "topup") {
$withdrawdata = $this->Pelanggan_model->insertwallet($datawithdraw);
$message = array(
'code' => '200',
'message' => 'success',
'data' => []
);
$this->response($message, 200);
} else {
if ($saldolama->row('saldo') >= $amount && $check_exist) {
$withdrawdata = $this->Pelanggan_model->insertwallet($datawithdraw);
$message = array(
'code' => '200',
'message' => 'success',
'data' => []
);
$this->response($message, 200);
} else {
$message = array(
'code' => '201',
'message' => 'You have insufficient balance',
'data' => []
);
$this->response($message, 200);
}
}
}
function list_ride_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$near = $this->Pelanggan_model->get_driver_ride($dec_data->latitude, $dec_data->longitude, $dec_data->fitur);
$message = array(
'data' => $near->result()
);
$this->response($message, 200);
}
function list_bank_post()
{
$near = $this->Pelanggan_model->listbank();
$message = array(
'data' => $near->result()
);
$this->response($message, 200);
}
function list_car_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$near = $this->Pelanggan_model->get_driver_car($dec_data->latitude, $dec_data->longitude, $dec_data->fitur);
$message = array(
'data' => $near->result()
);
$this->response($message, 200);
}
function detail_fitur_get()
{
$app_settings = $this->Pelanggan_model->get_settings();
$biaya = $this->Pelanggan_model->get_biaya();
foreach ($app_settings as $item) {
$message = array(
'data' => $biaya['fitur'],
'diskon_wallet' => $biaya['diskon'],
'currency' => $item['app_currency'],
);
$this->response($message, 200);
}
}
function request_transaksi_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$data_req = array(
'id_pelanggan' => $dec_data->id_pelanggan,
'order_fitur' => $dec_data->order_fitur,
'start_latitude' => $dec_data->start_latitude,
'start_longitude' => $dec_data->start_longitude,
'end_latitude' => $dec_data->end_latitude,
'end_longitude' => $dec_data->end_longitude,
'jarak' => $dec_data->jarak,
'harga' => $dec_data->harga,
'estimasi_time' => $dec_data->estimasi,
'waktu_order' => date('Y-m-d H:i:s'),
'alamat_asal' => $dec_data->alamat_asal,
'alamat_tujuan' => $dec_data->alamat_tujuan,
'biaya_akhir' => $dec_data->harga,
'kredit_promo' => $dec_data->kredit_promo,
'pakai_wallet' => $dec_data->pakai_wallet
);
$request = $this->Pelanggan_model->insert_transaksi($data_req);
if ($request['status']) {
$message = array(
'message' => 'success',
'data' => $request['data']
);
$this->response($message, 200);
} else {
$message = array(
'message' => 'fail',
'data' => $request['data']
);
$this->response($message, 200);
}
}
function check_status_transaksi_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$dataTrans = array(
'id_transaksi' => $dec_data->id_transaksi
);
$getStatus = $this->Pelanggan_model->check_status($dataTrans);
$this->response($getStatus, 200);
}
function user_cancel_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$data_req = array(
'id_transaksi' => $dec_data->id_transaksi
);
$cancel_req = $this->Pelanggan_model->user_cancel_request($data_req);
if ($cancel_req['status']) {
$this->Driver_model->delete_chat($cancel_req['iddriver'], $cancel_req['idpelanggan']);
$message = array(
'message' => 'canceled',
'data' => []
);
$this->response($message, 200);
} else {
$message = array(
'message' => 'cancel fail',
'data' => []
);
$this->response($message, 200);
}
}
function liat_lokasi_driver_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$getLoc = $this->Pelanggan_model->get_driver_location($dec_data->id);
$message = array(
'status' => true,
'data' => $getLoc->result()
);
$this->response($message, 200);
}
function detail_transaksi_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$gettrans = $this->Pelanggan_model->transaksi($dec_data->id);
$getdriver = $this->Pelanggan_model->detail_driver($dec_data->id_driver);
$getitem = $this->Pelanggan_model->detail_item($dec_data->id);
$message = array(
'status' => true,
'data' => $gettrans->result(),
'driver' => $getdriver->result(),
'item' => $getitem->result(),
);
$this->response($message, 200);
}
function detail_berita_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$getberita = $this->Pelanggan_model->beritadetail($dec_data->id);
$message = array(
'status' => true,
'data' => $getberita->result()
);
$this->response($message, 200);
}
function add_komentar_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data, true);
$id_berita = $dec_data["id_berita"];
$uid = $dec_data["userid"];
$parent_id = $dec_data["parent_id"];
$komentar = $dec_data["komentar"];
if (!$id_berita || !$uid || !$komentar) {
$message = array(
'status' => false,
'message' => "Terdapat data yang kosong!"
);
} else {
$insert = $this->Pelanggan_model->insertKomentar($id_berita, $parent_id, $uid, $komentar);
if ($insert) {
$message = array(
'status' => true,
'message' => "Berhasil menambah komentar"
);
} else {
$message = array(
'status' => true,
'message' => "Gagal menyimpan ke database!"
);
}
}
$this->response($message, 200);
}
function all_berita_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data, true);
$getberita = $this->Pelanggan_model->allberita($dec_data['cabang']);
$data = array();
foreach ($getberita as $berita) {
$berita['count'] = $this->Pelanggan_model->countKomentar($berita['id_berita']);
array_push($data, $berita);
}
$message = array(
'status' => true,
'data' => $data
);
$this->response($message, 200);
}
function get_komentar_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data, true);
$getkomen = $this->Pelanggan_model->getkomentar($dec_data['berita_id']);
$count = $this->Pelanggan_model->countKomentar($dec_data['berita_id']);
$message = array(
'status' => true,
'count' => $count,
'data' => $getkomen
);
$this->response($message, 200);
}
function list_cabang_get()
{
$cabang = $this->Pelanggan_model->getCabang();
$message = array(
'status' => true,
'data' => $cabang
);
$this->response($message, 200);
}
function edit_profile_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$check_exist_phone = $this->Pelanggan_model->check_exist_phone_edit($decoded_data->id, $decoded_data->no_telepon);
$check_exist_email = $this->Pelanggan_model->check_exist_email_edit($decoded_data->id, $decoded_data->email);
if ($check_exist_phone) {
$message = array(
'code' => '201',
'message' => 'phone already exist',
'data' => []
);
$this->response($message, 201);
} else if ($check_exist_email) {
$message = array(
'code' => '201',
'message' => 'email already exist',
'data' => []
);
$this->response($message, 201);
} else {
$condition = array(
'no_telepon' => $decoded_data->no_telepon
);
$condition2 = array(
'no_telepon' => $decoded_data->no_telepon_lama
);
if ($decoded_data->fotopelanggan == null && $decoded_data->fotopelanggan_lama == null) {
$datauser = array(
'fullnama' => $decoded_data->fullnama,
'no_telepon' => $decoded_data->no_telepon,
'phone' => $decoded_data->phone,
'email' => $decoded_data->email,
'countrycode' => $decoded_data->countrycode,
'tgl_lahir' => $decoded_data->tgl_lahir
);
} else {
$image = $decoded_data->fotopelanggan;
$namafoto = time() . '-' . rand(0, 99999) . ".jpg";
$path = "images/pelanggan/" . $namafoto;
file_put_contents($path, base64_decode($image));
$foto = $decoded_data->fotopelanggan_lama;
$path = "./images/pelanggan/$foto";
unlink("$path");
$datauser = array(
'fullnama' => $decoded_data->fullnama,
'no_telepon' => $decoded_data->no_telepon,
'phone' => $decoded_data->phone,
'email' => $decoded_data->email,
'fotopelanggan' => $namafoto,
'countrycode' => $decoded_data->countrycode,
'tgl_lahir' => $decoded_data->tgl_lahir
);
}
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition2);
if ($cek_login->num_rows() > 0) {
$upd_user = $this->Pelanggan_model->edit_profile($datauser, $decoded_data->no_telepon_lama);
$getdata = $this->Pelanggan_model->get_data_pelanggan($condition);
$message = array(
'code' => '200',
'message' => 'success',
'data' => $getdata->result()
);
$this->response($message, 200);
} else {
$message = array(
'code' => '404',
'message' => 'error data',
'data' => []
);
$this->response($message, 200);
}
}
}
function wallet_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$getWallet = $this->Pelanggan_model->getwallet($decoded_data->id);
$message = array(
'status' => true,
'data' => $getWallet->result()
);
$this->response($message, 200);
}
function history_progress_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$getWallet = $this->Pelanggan_model->all_transaksi($decoded_data->id);
$message = array(
'status' => true,
'data' => $getWallet->result()
);
$this->response($message, 200);
}
function request_transaksi_send_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$data_req = array(
'id_pelanggan' => $dec_data->id_pelanggan,
'order_fitur' => $dec_data->order_fitur,
'start_latitude' => $dec_data->start_latitude,
'start_longitude' => $dec_data->start_longitude,
'end_latitude' => $dec_data->end_latitude,
'end_longitude' => $dec_data->end_longitude,
'jarak' => $dec_data->jarak,
'harga' => $dec_data->harga,
'estimasi_time' => $dec_data->estimasi,
'waktu_order' => date('Y-m-d H:i:s'),
'alamat_asal' => $dec_data->alamat_asal,
'alamat_tujuan' => $dec_data->alamat_tujuan,
'biaya_akhir' => $dec_data->harga,
'kredit_promo' => $dec_data->kredit_promo,
'pakai_wallet' => $dec_data->pakai_wallet
);
$dataDetail = array(
'nama_pengirim' => $dec_data->nama_pengirim,
'telepon_pengirim' => $dec_data->telepon_pengirim,
'nama_penerima' => $dec_data->nama_penerima,
'telepon_penerima' => $dec_data->telepon_penerima,
'nama_barang' => $dec_data->nama_barang
);
$request = $this->Pelanggan_model->insert_transaksi_send($data_req, $dataDetail);
if ($request['status']) {
$message = array(
'message' => 'success',
'data' => $request['data']->result()
);
$this->response($message, 200);
} else {
$message = array(
'message' => 'fail',
'data' => []
);
$this->response($message, 200);
}
}
function changepass_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$reg_id = array(
'password' => sha1($decoded_data->new_password)
);
$condition = array(
'password' => sha1($decoded_data->password),
'no_telepon' => $decoded_data->no_telepon
);
$condition2 = array(
'password' => sha1($decoded_data->new_password),
'no_telepon' => $decoded_data->no_telepon
);
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
$message = array();
if ($cek_login->num_rows() > 0) {
$upd_regid = $this->Pelanggan_model->edit_profile($reg_id, $decoded_data->no_telepon);
$get_pelanggan = $this->Pelanggan_model->get_data_pelanggan($condition2);
$message = array(
'code' => '200',
'message' => 'found',
'data' => $get_pelanggan->result()
);
$this->response($message, 200);
} else {
$message = array(
'code' => '404',
'message' => 'wrong password',
'data' => []
);
$this->response($message, 200);
}
}
function alldriver_get($id)
{
$near = $this->Pelanggan_model->get_driver_location_admin($this->session->userdata('level'), $this->session->userdata('cabang'));
$message = array(
'data' => $near->result()
);
$this->response($message, 200);
}
function alltransactionpickup_get()
{
$near = $this->Pelanggan_model->getAlltransaksipickup();
$message = array(
'data' => $near->result()
);
$this->response($message, 200);
}
function alltransactiondestination_get()
{
$near = $this->Pelanggan_model->getAlltransaksidestination();
$message = array(
'data' => $near->result()
);
$this->response($message, 200);
}
function inserttransaksimerchant_post()
{
$data = file_get_contents("php://input");
$dec_data = json_decode($data);
$data_transaksi = array(
'id_pelanggan' => $dec_data->id_pelanggan,
'order_fitur' => $dec_data->order_fitur,
'start_latitude' => $dec_data->start_latitude,
'start_longitude' => $dec_data->start_longitude,
'end_latitude' => $dec_data->end_latitude,
'end_longitude' => $dec_data->end_longitude,
'jarak' => $dec_data->jarak,
'harga' => $dec_data->harga,
'waktu_order' => date('Y-m-d H:i:s'),
'estimasi_time' => $dec_data->estimasi,
'alamat_asal' => $dec_data->alamat_asal,
'alamat_tujuan' => $dec_data->alamat_tujuan,
'kredit_promo' => $dec_data->kredit_promo,
'pakai_wallet' => $dec_data->pakai_wallet,
);
$total_belanja = [
'total_belanja' => $dec_data->total_biaya_belanja,
];
$dataDetail = [
'id_merchant' => $dec_data->id_resto,
'total_biaya' => $dec_data->total_biaya_belanja,
'struk' => rand(0, 9999),
];
$result = $this->Pelanggan_model->insert_data_transaksi_merchant($data_transaksi, $dataDetail, $total_belanja);
if ($result['status'] == true) {
$pesanan = $dec_data->pesanan;
foreach ($pesanan as $pes) {
$item[] = [
'catatan_item' => $pes->catatan,
'id_item' => $pes->id_item,
'id_merchant' => $dec_data->id_resto,
'id_transaksi' => $result['id_transaksi'],
'jumlah_item' => $pes->qty,
'total_harga' => $pes->total_harga,
];
}
$request = $this->Pelanggan_model->insert_data_item($item);
if ($request['status']) {
$message = array(
'message' => 'success',
'data' => $result['data'],
);
$this->response($message, 200);
} else {
$message = array(
'message' => 'fail',
'data' => []
);
$this->response($message, 200);
}
} else {
$message = array(
'message' => 'fail',
'data' => []
);
$this->response($message, 200);
}
}
function req_trx_post()
{
//error_reporting(0);
$json = file_get_contents('php://input');
$result = json_decode($json);
// Set your merchant code (Note: Server key for sandbox and production mode are different)
$merchantCode = $this->config->item("code_duitku");
// Set your merchant key (Note: Server key for sandbox and production mode are different)
$merchantKey = $this->config->item("key_duitku");
$paymentAmount = $result->{'paymentAmount'};
$iduser = $result->{'merchantUserInfo'};
$result->{'merchantOrderId'} = time() . substr($iduser, 1, 5) . rand(111, 999);
$paymentMethod = $result->{'paymentMethod'};
$orderid = $result->{'merchantOrderId'};
$result->{'additionalParam'} = $orderid;
$name = $result->{'customerVaName'};
$exp = $result->{'expiryPeriod'};
$merchantOrderId = time();
$signature = md5($merchantCode . $merchantOrderId . $paymentAmount . $merchantKey);
$itemsParam = array(
'merchantCode' => $merchantCode,
'merchantKey' => $merchantKey,
'merchantOrderId' => $merchantOrderId,
'signature' => $signature
);
$data_duitku = array(
'id_user' => $iduser,
'jumlah' => $paymentAmount,
'method' => $paymentMethod,
'name' => $name,
'expiry_period' => $exp,
'signature' => $signature,
'orderid' => $orderid,
'status' => 0
);
$data = array(
'id_user' => $iduser,
'rekening' => $orderid,
'bank' => "duitku",
'nama_pemilik' => $name,
'type' => 'topup',
'jumlah' => $paymentAmount,
'status' => 0
);
$params = array_merge((array) $result, $itemsParam);
$params_string = json_encode($params);
$url = 'https://passport.duitku.com/webapi/api/merchant/v2/inquiry'; // Sandbox
//$url = 'https://passport.duitku.com/webapi/api/merchant/v2/inquiry'; // Production
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params_string)
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//execute post
$request = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
$this->Pelanggan_model->insertDuitku($data_duitku);
$result = $this->Pelanggan_model->insertwallet($data);
if ($result) {
$this->response(json_decode($request, true), 200);
} else {
$this->response(['statusMessage' => "Server Error !!", "error" => 400], 400);
}
} else {
$response['statusMessage'] = "Server Error . $httpCode ";
$response['error'] = $httpCode;
$this->response($response, $httpCode);
}
}
function check_trx_post()
{
$json = file_get_contents('php://input');
$result = json_decode($json);
// Set your merchant code (Note: Server key for sandbox and production mode are different)
$merchantCode = $this->config->item("code_duitku");
// Set your merchant key (Note: Server key for sandbox and production mode are different)
$merchantKey = $this->config->item("key_duitku");
$reference = $result->{'reference'};
$signature = md5($merchantCode . $reference . $merchantKey);
$itemsParam = array(
'merchantCode' => $merchantCode,
'signature' => $signature
);
$params = array_merge((array) $result, $itemsParam);
$params_string = json_encode($params);
//if sandbox
$url = 'https://passport.duitku.com/webapi/api/merchant/transactionStatus';
//if production
//$url = 'https://passport.duitku.com/webapi/api/merchant/transactionStatus';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params_string)
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//execute post
$request = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
echo $request;
} else
echo $httpCode;
}
function list_payment_post()
{
$json = file_get_contents('php://input');
date_default_timezone_set('Asia/Jakarta');
$result = json_decode($json);
// Set your merchant code (Note: Server key for sandbox and production mode are different)
$merchantCode = $this->config->item("code_duitku");
// Set your merchant key (Note: Server key for sandbox and production mode are different)
$merchantKey = $this->config->item("key_duitku");
$datetime = date('Y-m-d H:i:s');
$paymentAmount = $result->{'paymentAmount'};
$signature = hash('sha256', $merchantCode . $paymentAmount . $datetime . $merchantKey);
$itemsParam = array(
'merchantcode' => $merchantCode,
'amount' => $paymentAmount,
'datetime' => $datetime,
'signature' => $signature
);
$params = array_merge((array) $result, $itemsParam);
$params_string = json_encode($params);
$url = 'https://passport.duitku.com/webapi/api/merchant/paymentmethod/getpaymentmethod';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params_string)
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//execute post
$request = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
$this->response(json_decode($request, true), 200);
} else {
$response['statusMessage'] = "Server Error . $httpCode ";
$response['error'] = $httpCode;
die(json_encode($response));
}
}
function order_ppob_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$apikey = $this->input->request_headers()['x-api-key'];
$verif = $this->Pelanggan_model->check_verif_by_apikey($apikey);
$condition = array(
'password' => sha1($decoded_data->password),
'no_telepon' => $decoded_data->no_telepon,
//'token' => $decoded_data->token
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
if ($check_banned) {
$message = array(
'message' => 'banned',
'data' => []
);
$this->response($message, 200);
} else if ($verif == 0) {
$message = array(
'code' => '400',
'message' => 'Akun belum di verifikasi!'
);
$this->response($message, 200);
} else {
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
$data = $cek_login->row_array();
$type = $decoded_data->type;
$message = array();
if ($cek_login->num_rows() > 0 && $decoded_data->no_pelanggan) {
$cek_barang = $this->digiflazz->cek_barang($decoded_data->orderid, $type);
$pelanggan = $data['id'];
$saldo = $data['saldo'];
if ($cek_barang->num_rows() > 0) {
$data_ppob = $cek_barang->row_array();
if ($type == "prabayar") {
$harga = $data_ppob['price'] + $data_ppob['fee'];
} else {
$harga = $this->digiflazz->cek_tagihan($decoded_data->orderid, $decoded_data->no_pelanggan)['selling_price'];
}
$limit = $harga * $this->app->get_limit() / 100;
if ($saldo - $limit >= $harga) {
$ref = time() . rand(00000, 99999);
if ($type == "prabayar") {
$order = $this->digiflazz->order($decoded_data->orderid, $decoded_data->no_pelanggan, $pelanggan, $decoded_data->detailpesanan, $decoded_data->brand, $ref);
} else {
$order = $this->digiflazz->order_pasca($decoded_data->orderid, $decoded_data->no_pelanggan, $pelanggan, $decoded_data->price, $decoded_data->detailpesanan, $decoded_data->brand, $ref);
}
$potongan = $saldo - $harga;
$insert = array(
'id_user' => $pelanggan,
'jumlah' => $harga,
'bank' => "ppob",
'nama_pemilik' => $data['fullnama'],
'rekening' => "wallet",
'type' => "Order-",
'ppob_id' => $order['id_ppob'],
'status' => 1
);
$this->digiflazz->potongSaldo($pelanggan, $potongan);
$this->digiflazz->insertWallet($insert);
$chek = $this->db->get_where("wallet", ['ppob_id' => $order['id_ppob']]);
if ($order["id_ppob"] != null && $chek->num_rows() > 0) {
if ($type == "prabayar") {
$senderdata = array(
'username' => $this->config->item('digiflazz_username'),
'buyer_sku_code' => $decoded_data->orderid,
'customer_no' => $decoded_data->no_pelanggan,
'ref_id' => $ref,
'sign' => md5($this->config->item('digiflazz_username') . $this->config->item('digiflazz_apikey') . $ref),
'msg' => "testing"
);
$headers = array(
"Content-Type: application/json"
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.digiflazz.com/v1/transaction",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($senderdata),
CURLOPT_HTTPHEADER => $headers,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$dec_data = json_decode($response, true);
$data = $dec_data['data'];
if ($data['status'] == "Sukses") {
$sn = $data['sn'];
$this->db->update("history_digiflazz", ['sn' => $sn, 'status' => 1], ['id' => $order['id_ppob']]);
$message = array(
'code' => '200',
'message' => "Transaksi sedang di proses :)"
);
} else if ($data['status'] == "Gagal") {
$this->db->update("history_digiflazz", ['status' => 2, 'failed_reason' => $data['message']], ['id' => $order['id_ppob']]);
$reason[] = $data['message'];
$message = array(
'code' => '400',
'message' => "Gagal transaksi, hubungi admin!"
);
} else {
$this->db->update("history_digiflazz", ['status' => 0, 'failed_reason' => $data['message']], ['id' => $order['id_ppob']]);
$reason[] = $data['message'];
$message = array(
'code' => '200',
'message' => "Pesanan Sedang diproses!"
);
}
} else {
$id_bayar = $this->digiflazz->id_bayar_tripay($decoded_data->orderid, $decoded_data->no_pelanggan, $ref);
$url = 'https://tripay.co.id/api/v2/transaksi/pembayaran';
$header = array(
'Accept: application/json',
'Authorization: Bearer ' . $this->config->item('tripay_apikey'), // Ganti [apikey] dengan API KEY Anda
);
$data = array(
'order_id' => $id_bayar, // Masukkan ID yang didapat setelah melakukan pengecekan pembayaran
'api_trxid' => $ref, // Atau Anda bisa menggunakan ID transaksi dari server Anda (pilih salah satu)
'pin' => $this->config->item('tripay_pin'), // Masukkan PIN user (anda)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result = curl_exec($ch);
$json = json_decode($result, true);
if ($json['success']) {
if ($json['data']['status'] != 2) {
$this->db->update("history_digiflazz", ['tripay_bayar' => $id_bayar, 'status' => $json['status']], ['id' => $order['id_ppob']]);
$message = array(
'code' => '200',
'message' => "Transaksi sedang di proses :)"
);
} else {
$this->db->update("history_digiflazz", ['status' => 2, 'failed_reason' => "From Tripay : " . $json['message']], ['id' => $order['id_ppob']]);
$reason[] = $json['message'];
$message = array(
'code' => '400',
'message' => "Transaksi failed, hubungi admin!"
);
}
} else {
$this->db->update("history_digiflazz", ['tripay_bayar', 'status' => 2, 'failed_reason' => "From Tripay : " . $json['message']], ['id' => $order['id_ppob']]);
$reason[] = $json['message'];
$message = array(
'code' => '400',
'message' => "Transaksi failed, hubungi admin!"
);
}
}
} else {
$message = array(
'code' => '400',
'message' => "Transaksi failed, hubungi admin!"
);
}
$this->response($message, 200);
} else {
$message = array(
'code' => '400',
'message' => 'Saldo tidak cukup, setiap transaksi minimal memiliki saldo 10% dari saldo awal'
);
$this->response($message, 200);
}
} else {
$message = array(
'code' => '404',
'message' => 'Produk tidak ditemukan!'
);
$this->response($message, 200);
}
} else {
$message = array(
'code' => '404',
'message' => 'wrong phone or password',
'data' => []
);
$this->response($message, 200);
}
}
}
function cek_tagian_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'status' => 'gagal',
'no_telepon' => $decoded_data->no_telepon,
'status' => '1'
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
if ($check_banned) {
$message = array(
'status' => 'gagal',
'message' => 'banned',
'data' => []
);
$this->response($message, 200);
} else {
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
$data = $cek_login->row_array();
$saldo = $data['saldo'];
$message = array();
if ($cek_login->num_rows() > 0 && $decoded_data->no_pelanggan) {
$cek_barang = $this->digiflazz->cek_barang_pascabayar($decoded_data->orderid);
$cek_tripay = $this->digiflazz->cek_tripay($decoded_data->orderid);
if ($cek_barang->num_rows() > 0 && $cek_tripay) {
$cek_tagihan = $this->digiflazz->cek_tagihan($decoded_data->orderid, $decoded_data->no_pelanggan);
$cek_tagihan['saldo'] = $saldo;
$this->response($cek_tagihan, 200);
} else {
$message = array(
'status' => 'gagal',
'message' => 'Produk tidak tersedia atau sedang gangguan!',
'data' => []
);
$this->response($message, 200);
}
} else {
$message = array(
'status' => 'gagal',
'message' => 'wrong phone or password',
'data' => []
);
$this->response($message, 200);
}
}
}
function list_pascabayar_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'no_telepon' => $decoded_data->no_telepon,
'status' => '1'
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
if ($check_banned) {
$message = array(
'message' => 'banned',
'data' => []
);
$this->response($message, 200);
} else {
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
$data = $cek_login->row_array();
$saldo = $data['saldo'];
$message = array();
if ($cek_login->num_rows() > 0) {
$list_layanan = $this->digiflazz->list_layanan($decoded_data->brand);
$message = array(
'code' => '200',
'message' => 'ok',
'data' => $list_layanan
);
$this->response($message, 200);
} else {
$message = array(
'code' => '404',
'message' => 'wrong phone or password',
'data' => []
);
$this->response($message, 200);
}
}
}
function history_ppob_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'no_telepon' => $decoded_data->no_telepon,
'status' => '1'
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'no_telepon' => $decoded_data->no_telepon,
'status' => '1'
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
if ($check_banned) {
$message = array(
'status' => 'gagal',
'message' => 'banned',
'data' => []
);
$this->response($message, 200);
} else {
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$data = $cek_login->row_array();
$pelanggan = $data['id'];
$message = array(
'status' => 'sukses',
'message' => 'OK',
'data' => $this->digiflazz->history($pelanggan)
);
$this->response($message, 200);
} else {
$message = array(
'status' => 'gagal',
'message' => 'wrong phone or password',
'data' => []
);
$this->response($message, 200);
}
}
}
function detail_history_post()
{
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'no_telepon' => $decoded_data->no_telepon,
'status' => '1'
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
$data = file_get_contents("php://input");
$decoded_data = json_decode($data);
$condition = array(
'no_telepon' => $decoded_data->no_telepon,
'status' => '1'
);
$check_banned = $this->Pelanggan_model->check_banned($decoded_data->no_telepon);
if ($check_banned) {
$message = array(
'status' => 'gagal',
'message' => 'banned',
'data' => []
);
$this->response($message, 200);
} else {
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
if ($cek_login->num_rows() > 0) {
$data = $cek_login->row_array();
$pelanggan = $data['id'];
$this->response($this->digiflazz->detailHistory($pelanggan, $decoded_data->id_ppob), 200);
} else {
$message = array(
'status' => 'gagal',
'message' => 'wrong phone or password',
'data' => []
);
$this->response($message, 200);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
}
Editor is loading...