Exemplo n.º 1
0
 private function processPayment($objectID)
 {
     $playerModel = new PlayerModel();
     $storeModel = new StoreModel();
     $error = false;
     $newOrder = false;
     $graphUrl = sprintf('https://graph.facebook.com/%s?access_token=%s|%s', $objectID, Config::get('facebook.appid'), Config::get('facebook.appsecret'));
     $curl = new Curl();
     $curl->get($graphUrl);
     if ($curl->error) {
         Log::add('Error in requesting object ' . $curl->error_code . ' : ' . $curl->error_message);
         throw new NinjaException("Error Processing Request");
     }
     $res = $curl->response;
     $facebookID = $res->user->id;
     $playerArray = $playerModel->getPlayerIDFromUID($facebookID, null, false);
     $playerID = $playerArray[0];
     $orderDetails = $storeModel->addOrder($playerID, $objectID, $res);
     if ($res->actions[0]->status == 'completed') {
         $status = 'ok';
         Log::add('payment ok charged status is good');
     } else {
         if ($res->actions[0]->status == 'failed') {
             $error = true;
             $status = 'error';
             $message = 'Payment Declined';
             Log::add('Payment failed ' . print_r($res, true));
         } else {
             if ($res->actions[0]->status == 'initiated') {
                 $error = false;
                 Log::add('Payment failed ' . print_r($res, true));
             } else {
                 $error = true;
                 $status = 'error';
                 $message = 'User canceled payment';
             }
         }
     }
     //ANALYTICS
     if (!$error) {
         $array['status'] = 'ok';
         $array['player'] = $playerModel->getPlayerData($playerID);
         $array['order'] = $orderDetails;
         $this->printJson($array);
     } else {
         $array['status'] = 'error';
         $array['message'] = $message;
         $this->printJson($array);
     }
 }