Advertisement
ojanganteng

Virtual_account.php

Dec 12th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Virtual_account extends CI_Controller {
  5.  
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->client_id = 'client_id';
  10.         $this->secret_key = 'secret_key';
  11.         $this->url = 'URL';
  12.         $this->va = $this->load->database('va', true);
  13.         $this->load->library('BniEnc');
  14.         $this->load->helper('get_content');
  15.         if( ! $this->ion_auth->logged_in() )
  16.         {
  17.             redirect('auth/login');
  18.         }
  19.     }
  20.  
  21.     private function transmit($data_asli)
  22.     {
  23.         $hashed_string = BniEnc::encrypt(
  24.             $data_asli,
  25.             $this->client_id,
  26.             $this->secret_key
  27.         );
  28.  
  29.         $data = array(
  30.             'client_id' => $this->client_id,
  31.             'data' => $hashed_string,
  32.         );
  33.  
  34.         $response = get_content($this->url, json_encode($data));
  35.         $response_json = json_decode($response, true);
  36.  
  37.         if ($response_json['status'] !== '000') {
  38.             // handling jika gagal
  39.             var_dump($response_json);
  40.             exit;
  41.             // return FALSE;
  42.         }
  43.         else {
  44.             // $data_response = BniEnc::decrypt($response_json['data'], $this->client_id, $this->secret_key);
  45.             // return array( 'status' => $response_json['status'], 'data_response' => $data_response );
  46.             return TRUE;
  47.         }
  48.     }
  49.  
  50.     public function get_va( $id_invoice = null )
  51.     {
  52.         if( $id_invoice )
  53.         {
  54.             $this->load->helper('get_content');
  55.             include_once __DIR__ . "/../../../../libraries/BniEnc.php";
  56.  
  57.             $data_asli = array(
  58.                 'type' => 'inquirybilling',
  59.                 'client_id' => $this->client_id,
  60.                 'trx_id' => $this->db->get_where('invoice', array('id_invoice' => $id_invoice))->row()->trx_id,
  61.             );
  62.  
  63.             $this->transmit( $data_asli ); 
  64.         }
  65.         else
  66.         {
  67.             show_404();
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement