function testvp()
 {
     $str = 'O:22:"Veritrans_Notification":1:{s:8:"response";O:8:"stdClass":14:{s:11:"status_code";s:3:"200";s:14:"status_message";s:26:"Success, transaction found";s:14:"transaction_id";s:36:"a293ec21-9572-4333-9a41-640a6789b713";s:11:"masked_card";s:11:"518323-9790";s:8:"order_id";s:10:"1084599542";s:12:"gross_amount";s:8:"10000.00";s:12:"payment_type";s:11:"credit_card";s:16:"transaction_time";s:19:"2016-02-17 15:20:37";s:18:"transaction_status";s:10:"settlement";s:12:"fraud_status";s:6:"accept";s:13:"approval_code";s:6:"T08489";s:13:"signature_key";s:128:"12a2c1d52cdd03326727b1ee0cc8a9f658146dbaedac46490f269183291885772e5a31a121c94ebde9f501733c8e7802cf74c3bb839ad687188456c3bf0d45e0";s:4:"bank";s:3:"bni";s:3:"eci";s:2:"02";}} ||| {"status_code":"200","status_message":"Veritrans payment notification","transaction_id":"a293ec21-9572-4333-9a41-640a6789b713","masked_card":"518323-9790","order_id":"1084599542","gross_amount":"10000.00","payment_type":"credit_card","transaction_time":"2016-02-17 15:20:37","transaction_status":"settlement","fraud_status":"accept","approval_code":"T08489","signature_key":"12a2c1d52cdd03326727b1ee0cc8a9f658146dbaedac46490f269183291885772e5a31a121c94ebde9f501733c8e7802cf74c3bb839ad687188456c3bf0d45e0","bank":"bni","eci":"02"}';
     $exp = explode(" ||| ", $str);
     $obj = unserialize($exp[0]);
     pr($obj);
     pr($exp[1]);
     $vp = new VpData();
     $vp->printColumlistAsAttributes();
     $tt = new VpTransaction();
     $tt->printColumlistAsAttributes();
     $km = new KomisiModel();
     $km->printColumlistAsAttributes();
     $bk = new BonusKomisi();
     BonusKomisi::fillBK();
     $bg = new EmailLog();
     $bg->printColumlistAsAttributes();
 }
    function receipt()
    {
        $order_id = addslashes($_GET['order_id']);
        $order = new VpTransaction();
        $order->getByID($order_id);
        //        pr($order);
        //TODO : harus dibikin
        if ($order->order_acc_id != Account::getMyID() && !in_array("master_admin", Account::getMyRoles())) {
            die("hacking attempt");
        }
        $app = new AppAccount();
        $app->getByID($order->order_app_id);
        if ($app->app_active == 0) {
            die("App not active");
        }
        $acc = new Account();
        $acc->getByID($app->app_client_id);
        $paket = new Paket();
        $paket->getByID($order->order_paket_id);
        $vpData = new VpData();
        $arr = $vpData->getWhere("order_id = '{$order_id}' LIMIT 0,1");
        if (count($arr) > 0) {
            $data = $arr[0];
        } else {
            $data = new VpData();
        }
        if ($acc->admin_marketer != "") {
            $arrAg = $acc->getWhere("admin_username = '******' LIMIT 0,1");
            if (count($arrAg) > 0) {
                $agent = $arrAg[0];
            }
        }
        //        pr($arr);
        ?>
        <style>
            h1{
                font-size: 25px;
                padding-top: 30px;
            }
            h3{
                font-size: 20px;
                font-style: italic;
            }
            h4{
                font-size: 17px;
                margin-top: 20px;
                margin-bottom: 30px;
            }
            .billings td{
                padding-right: 20px;
                padding-bottom: 10px;
            }
            @media (max-width: 768px) {

                .monly {
                    display: initial;
                }

                .donly {
                    display: none;
                }

                h1{
                    font-size: 20px;
                }
                h3{
                    font-size: 17px;
                    font-style: italic;
                }
                h4{
                    font-size: 14px;
                    margin-bottom: 30px;
                }
                .billings td{
                    padding-bottom: 10px;
                }
            }

            @media (min-width: 768px) {
                .monly {
                    display: none;
                }

                .donly {
                    display: initial;
                }



            }
            @media print {
                .pure-toggle-label[data-toggle-label='left']{
                    display: none;
                }
                #printme{
                    display: none;
                }
                body{
                    background-color: #ffffff;
                }
            }
        </style>
        <div class="container attop"  >
                <div class="col-md-8 col-md-offset-2">


                    <div style="text-align: center; background-color: #ffffff; padding: 20px; min-height: 800px;  margin-top: 20px; padding-top: 20px; padding-bottom: 20px; ">
                        <img src="<?php 
        echo _SPPATH;
        ?>
images/header_appear.jpg" width="100%">

                        <h1>PAYMENT RECEIPT</h1>
                        <h3>Your payment has been completed successfully</h3>
                        <div class="receipt" style=" margin-top: 30px;">
                        <h4>TRANSACTION DETAILS</h4>
                        <table class="billings" align="center" style="text-align: left;">
                            <tr>
                                <td>ORDER ID</td>
                                <td><?php 
        echo $order_id;
        ?>
</td>
                            </tr>
                            <tr>
                                <td>PAYMENT DATE / TIME</td>
                                <td><?php 
        echo date("F j, Y, g:i a", strtotime($order->order_date));
        ?>
</td>
                            </tr>
                            <tr>
                                <td>PACKAGE NAME</td>
                                <td><?php 
        echo $paket->paket_name;
        ?>
</td>
                            </tr>
                            <tr>
                                <td>APP ID</td>
                                <td><?php 
        echo $app->app_id;
        ?>
</td>
                            </tr>
                            <tr>
                                <td>ACCOUNT ID</td>
                                <td><?php 
        echo $acc->admin_nama_depan;
        ?>
</td>
                            </tr>
                            <tr>
                                <td>AMOUNT</td>
                                <td>IDR <?php 
        echo idr($paket->paket_price);
        ?>
</td>
                            </tr>
                            <tr>
                                <td>STATUS</td>
                                <td><?php 
        echo $data->transaction_status;
        ?>
</td>
                            </tr>
                            <tr>
                                <td>PAYMENT TYPE</td>
                                <td><?php 
        echo $data->payment_type;
        ?>
</td>
                            </tr>
                            <tr>
                                <td>BANK NAME</td>
                                <td><?php 
        echo $data->bank;
        ?>
</td>
                            </tr>
                            <?php 
        if (count($arrAg) > 0) {
            ?>
                            <tr>
                                <td>AGENT ID</td>
                                <td><?php 
            echo $agent->admin_username;
            ?>
</td>
                            </tr>
                            <?php 
        }
        ?>
                        </table>
                        </div>


                    </div>
                    <div id="printme" style="text-align: right; margin-top: 5px; margin-bottom: 100px;" >
                         <a href="#" onclick="window.print();"><i class="glyphicon glyphicon-print"></i> print</a> |
                        <a href="<?php 
        echo _SPPATH;
        ?>
myOrders">back to my transactions</a>
                    </div>
                </div>
            </div>
        <?php 
    }
 function handling()
 {
     echo 1;
     if ($this->isProd) {
         Veritrans_Config::$isProduction = true;
     }
     echo 3;
     Veritrans_Config::$serverKey = $this->getKeyUsed();
     echo 4;
     $raw_notification = "";
     try {
         $notif = new Veritrans_Notification();
         $input_source = "php://input";
         $raw_notification = file_get_contents($input_source);
     } catch (Exception $e) {
         echo "<h2>" . $e->getMessage() . "</h2>";
     }
     echo "<h1>jahahaa</h1>";
     $transaction = $notif->transaction_status;
     $type = $notif->payment_type;
     $order_id = $notif->order_id;
     $fraud = $notif->fraud_status;
     $vpt = new VpTransaction();
     $vpt->getByID($order_id);
     //dataemail
     $dataemail = new DataEmail();
     if ($transaction == 'capture') {
         // For credit card transaction, we need to check whether transaction is challenge by FDS or not
         if ($type == 'credit_card') {
             if ($fraud == 'challenge') {
                 // TODO set payment status in merchant's database to 'Challenge by FDS'
                 // TODO merchant should decide whether this transaction is authorized or not in MAP
                 echo "Transaction order_id: " . $order_id . " is challenged by FDS";
                 $vpt->order_message = "Transaction order_id: " . $order_id . " is challenged by FDS";
                 $vpt->order_status = 3;
                 $vpt->save();
                 //notify User
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, $fraud);
             } else {
                 // TODO set payment status in merchant's database to 'Success'
                 echo "Transaction order_id: " . $order_id . " successfully captured using " . $type;
                 $vpt->order_message = "Transaction order_id: " . $order_id . " successfully captured using " . $type;
                 $vpt->order_status = 2;
                 $vpt->save();
                 //notify User
                 //update active di app
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $app->app_contract_start = date("Y-m-d");
                 $app->app_contract_end = date('Y-m-d', strtotime(date("Y-m-d", mktime()) . " + 365 day"));
                 $app->app_active = 1;
                 $app->app_paket_id = $vpt->order_paket_id;
                 $app->save();
                 //notify Admins kalau ada app active
                 $dataemail->appBisaDibuat($app->app_name, $app->app_id, $transaction);
                 //notify User
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentSuccess($acc->admin_email, $acc->admin_username, $app->app_name);
                 //hitung komisi
                 //ini belum bener
                 //TODO 31 maret 2016
                 KomisiModel::log($app, $vpt);
                 //email dapat komisi
             }
         }
     } else {
         if ($transaction == 'settlement') {
             // TODO set payment status in merchant's database to 'Settlement'
             echo "Transaction order_id: " . $order_id . " successfully transfered using " . $type;
             $oldstatus = $vpt->order_status;
             $vpt->order_message = "Transaction order_id: " . $order_id . " successfully transfered using " . $type;
             $vpt->order_status = 1;
             $vpt->save();
             if ($oldstatus != 2) {
                 //update active di app
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $app->app_contract_start = date("Y-m-d");
                 $app->app_contract_end = date('Y-m-d', strtotime(date("Y-m-d", mktime()) . " + 365 day"));
                 $app->app_active = 1;
                 $app->app_paket_id = $vpt->order_paket_id;
                 $app->save();
                 //notify Admins kalau ada app active
                 $dataemail->appBisaDibuat($app->app_name, $app->app_id, $transaction);
                 //notify User
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentSettle($acc->admin_email, $acc->admin_username, $app->app_name);
                 //hitung komisi
                 //TODO 31 maret 2016
                 KomisiModel::log($app, $vpt);
                 //email dpt komisi
             }
         } else {
             if ($transaction == 'pending') {
                 // TODO set payment status in merchant's database to 'Pending'
                 echo "Waiting customer to finish transaction order_id: " . $order_id . " using " . $type;
                 $vpt->order_message = "Waiting customer to finish transaction order_id: " . $order_id . " using " . $type;
                 $vpt->order_status = 4;
                 $vpt->save();
                 //notify User
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, $transaction);
             } else {
                 if ($transaction == 'deny') {
                     // TODO set payment status in merchant's database to 'Denied'
                     echo "Payment using " . $type . " for transaction order_id: " . $order_id . " is denied.";
                     $vpt->order_message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is denied.";
                     $vpt->order_status = 5;
                     $vpt->save();
                     //notify User
                     $app = new AppAccount();
                     $app->getByID($vpt->order_app_id);
                     $acc = new Account();
                     $acc->getByID($app->app_client_id);
                     $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, "denied");
                 } else {
                     if ($transaction == 'cancel') {
                         // TODO set payment status in merchant's database to 'Denied'
                         echo "Payment using " . $type . " for transaction order_id: " . $order_id . " is canceled.";
                         $vpt->order_message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is canceled.";
                         $vpt->order_status = 6;
                         $vpt->save();
                         //notify User
                         $app = new AppAccount();
                         $app->getByID($vpt->order_app_id);
                         $acc = new Account();
                         $acc->getByID($app->app_client_id);
                         $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, "canceled");
                     }
                 }
             }
         }
     }
     $vp = new VpData();
     $vp->vp_date = leap_mysqldate();
     $vp->vp_obj = serialize($notif) . " ||| " . $raw_notification;
     $vp->approval_code = $notif->approval_code;
     $vp->order_id = $notif->order_id;
     $vp->status_code = $notif->status_code;
     $vp->transaction_status = $notif->transaction_status;
     $vp->status_message = $notif->status_message;
     $vp->transaction_id = $notif->transaction_id;
     $vp->masked_card = $notif->masked_card;
     $vp->gross_amount = $notif->gross_amount;
     $vp->payment_type = $notif->payment_type;
     $vp->transaction_time = $notif->transaction_time;
     $vp->fraud_status = $notif->fraud_status;
     $vp->approval_code = $notif->approval_code;
     $vp->signature_key = $notif->signature_key;
     $vp->bank = $notif->bank;
     $vp->eci = $notif->eci;
     $vp->save();
     pr($notif);
     /*
              * Veritrans_Notification Object
     (
         [response:Veritrans_Notification:private] => stdClass Object
             (
                 [status_code] => 200
                 [status_message] => Success, transaction found
                 [transaction_id] => a293ec21-9572-4333-9a41-640a6789b713
                 [masked_card] => 518323-9790
                 [order_id] => 1084599542
                 [gross_amount] => 10000.00
                 [payment_type] => credit_card
                 [transaction_time] => 2016-02-17 15:20:37
                 [transaction_status] => capture
                 [fraud_status] => accept
                 [approval_code] => T08489
                 [signature_key] => 12a2c1d52cdd03326727b1ee0cc8a9f658146dbaedac46490f269183291885772e5a31a121c94ebde9f501733c8e7802cf74c3bb839ad687188456c3bf0d45e0
                 [bank] => bni
                 [eci] => 02
             )
     
     )
     */
     die;
 }