function addConfirm()
 {
     $err = array();
     $json['bool'] = 0;
     //       $json['err'] = array("apptitle"=>"harus diisi");
     $ttdate = addslashes($_POST['ttdate']);
     if ($ttdate == "") {
         $err['ttdate'] = "Date must be filled";
     }
     $ttname = addslashes($_POST['ttname']);
     if ($ttname == "") {
         $err['ttname'] = "Name must be filled";
     }
     $ttamount = addslashes($_POST['ttamount']);
     if ($ttamount == "") {
         $err['ttamount'] = "Amount must be filled";
     }
     $ttto = addslashes($_POST['ttto']);
     if ($ttto == "") {
         $err['ttto'] = "Bank Account must be filled";
     }
     if (count($err) > 0) {
         $json['bool'] = 0;
         $json['err'] = $err;
     } else {
         //save here
         $pc = new PaymentConfirm();
         $pc->confirm_app_id = addslashes($_POST['appid']);
         $pc->confirm_bank = $ttto;
         $pc->confirm_amount = $ttamount;
         $pc->confirm_create_date = leap_mysqldate();
         $pc->confirm_date = $ttdate;
         $pc->confirm_name = $ttname;
         $pc->confirm_receipt = addslashes($_POST['ttfile']);
         $pc->confirm_status = "not reviewed";
         $pc->confirm_user_id = Account::getMyID();
         $confirmID = $pc->save();
         if ($confirmID) {
             $app = new AppAccount();
             $app->getByID($pc->confirm_app_id);
             $app->app_active = 2;
             $app->load = 1;
             $app->app_pulsa = 1000;
             $app->save();
             $paket = new Paket();
             $paket->getByID($app->app_paket_id);
             //add pporder
             $ppo = new PaypalOrder();
             $ppo->payment_id = $confirmID;
             $ppo->payment_type = "banktt";
             $ppo->amount = $pc->confirm_amount;
             $ppo->currency = "IDR";
             $ppo->created_time = leap_mysqldate();
             $ppo->state = "pending";
             $ppo->user_id = Account::getMyID();
             $ppo->description = "Payment " . $app->app_name . " Paket " . $paket->paket_name . " ID : " . $app->app_id;
             $succ = $ppo->save();
             if ($succ) {
                 $json['bool'] = 1;
                 $json['order_id'] = $succ;
             } else {
                 $json['bool'] = 0;
                 $json['all'] = "Saving PPO Error";
             }
         } else {
             $json['bool'] = 0;
             $json['all'] = "Saving PConfirm Error";
         }
     }
     echo json_encode($json);
     die;
 }
 function placeOrder()
 {
     //sementara semua credit card
     //$order = $_REQUEST['order'];
     //$order['payment_method'] == 'credit_card';
     $json['paystate'] = 0;
     //langkah pertama daftarkan cc
     $creditCardId = $this->daftarkanCC();
     $currency = 'USD';
     $amount = addslashes($_POST['appprice']);
     $descr = addslashes($_POST['appdescr']);
     $app_id = addslashes($_POST['appid']);
     if ($creditCardId != NULL) {
         try {
             $paypal = new PaypalWrap();
             $payment = $paypal->makePaymentUsingCC($creditCardId, $amount, $currency, $descr);
             //                pr($payment);
             $order = new PaypalOrder();
             $order->amount = $amount;
             $order->created_time = leap_mysqldate();
             $order->currency = $currency;
             $order->description = $descr;
             $order->user_id = Account::getMyID();
             $order->payment_id = $payment->getId();
             $order->state = $payment->getState();
             $orderId = $order->save();
             $state = $order->state;
             if ($state == "approved") {
                 $json['paystate'] = 1;
                 //update paket active
                 $app = new AppAccount();
                 $app->getByID($app_id);
                 $app->app_active = 1;
                 $app->app_contract_start = leap_mysqldate();
                 $app->app_pulsa = 1000;
                 $app->app_contract_end = date('Y-m-d', strtotime('+1 year'));
                 $app->load = 1;
                 $app->save();
             }
             $message = "Your order has been placed successfully. Your Order id is <b>{$orderId}</b>";
             $messageType = 1;
         } catch (\PayPal\Exception\PPConnectionException $ex) {
             $message = parseApiError($ex->getData());
             $messageType = 0;
         } catch (Exception $ex) {
             $message = $ex->getMessage();
             $messageType = 0;
         }
     } else {
         $messageType = 0;
         $message = "credit card ID registration error";
     }
     $json['bool'] = $messageType;
     $json['err'] = $message;
     echo json_encode($json);
     die;
     //        if($_SERVER['REQUEST_METHOD'] == 'POST') {
     //
     //            try {
     //                if($order['payment_method'] == 'credit_card') {
     //
     //                    // Make a payment using credit card.
     //                    $user = getUser(getSignedInUser());
     //                    $payment = makePaymentUsingCC($user['creditcard_id'], $order['amount'], 'USD', $order['description']);
     //                    $orderId = addOrder(getSignedInUser(), $payment->getId(), $payment->getState(),
     //                        $order['amount'], $order['description']);
     //                    $message = "Your order has been placed successfully. Your Order id is <b>$orderId</b>";
     //                    $messageType = "success";
     //
     //                } else if($order['payment_method'] == 'paypal') {
     //
     //                    $orderId = addOrder(getSignedInUser(), NULL, NULL, $order['amount'], $order['description']);
     //                    // Create the payment and redirect buyer to paypal for payment approval.
     //                    $baseUrl = getBaseUrl() . "/order_completion.php?orderId=$orderId";
     //                    $payment = makePaymentUsingPayPal($order['amount'], 'USD', $order['description'],
     //                        "$baseUrl&success=true", "$baseUrl&success=false");
     //                    updateOrder($orderId, $payment->getState(), $payment->getId());
     //                    header("Location: " . getLink($payment->getLinks(), "approval_url") );
     //                    exit;
     //                }
     //            } catch (\PayPal\Exception\PPConnectionException $ex) {
     //                $message = parseApiError($ex->getData());
     //                $messageType = "error";
     //            } catch (Exception $ex) {
     //                $message = $ex->getMessage();
     //                $messageType = "error";
     //            }
     //        }
 }