예제 #1
0
 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;
 }