Exemplo n.º 1
0
 function create_transaction($playerID)
 {
     //we are going to create a pending order.. we are just intiatng a transaction id - then we will set the order to status pending.
     Validate::player($playerID);
     $store = new StoreModel();
     $player = new PlayerModel();
     $itemID = filter_input(INPUT_POST, 'item');
     LOg::add('Received create transaction request with payload: ' . print_r($item, true));
     $transactionID = 'y_' . time() . md5(uniqid(rand(), true));
     $data['transaction_id'] = $transactionID;
     $data['player_id'] = $playerID;
     $data['order_date'] = date('Y-m-d H:i:s');
     $data['uid'] = $player->getUidFromPlayerId($playerID);
     $data['quantity'] = 1;
     $data['currency'] = 'USD';
     $data['updated_at'] = date('Y-m-d H:i:s');
     $data['status'] = 'pending';
     $data['item'] = $itemID;
     Log::add('Adding pending transaction sending data to model: ' . print_r($data, true));
     $response = $store->addPendingPurchase($data);
     $item = $store->getItem($itemID);
     $status = $response['status'];
     if ($status === 'ok') {
         $icon = 'coinItem.png';
         if ($item->type == 1) {
             $icon = 'coinItem.png';
         }
         if ($item->type == 2) {
             $icon = 'lifeItem.png';
         }
         $this->printJson(array('status' => 'ok', 'transactionid' => $response['transaction_id'], 'item' => $itemID, 'name' => $item->title, 'description' => $item->description, 'icon' => Config::get('storage.url') . 'game_assets/' . $icon, 'currency' => 'usd', 'amount' => $item->price));
     } else {
         $this->printJson(array('status' => 'error'));
     }
 }