public function create($data) { $currentUser = parent::authenticateUser(); $revenue = new Revenue(); if (isset($data->quantity) && isset($data->name) && isset($data->date)) { $revenue->setDate($data->date); $revenue->setQuantity($data->quantity); $revenue->setName($data->name); $revenue->setOwner($currentUser->getLogin()); try { $idRevenue = $this->revenueDAO->save($revenue); foreach ($data->types as $type_loop) { $type = $this->typeDAO->findById($type_loop->idType); if ($type == NULL) { $this->revenueDAO->delete($idRevenue); header($this->server->getServerProtocol() . ' 400 Bad request'); echo "Type with id " . $type_loop->idType . " not found"; return; } $typeRevenue = new TypeRevenue(); $typeRevenue->setRevenue($idRevenue); $typeRevenue->setType($type); $this->typeRevenueDAO->save($typeRevenue); } header($this->server->getServerProtocol() . ' 201 Created'); header('Location: ' . $this->server->getRequestUri() . "/" . $idRevenue); header('Content-Type: application/json'); } catch (ValidationException $e) { header($this->server->getServerProtocol() . ' 400 Bad request'); echo json_encode($e->getErrors()); } } }
} } //add to revenue stats $r = new Revenue(); $r->account_code = $notification->account->account_code; $r->uuid = $notification->transaction->id; $r->invoice_id = $notification->transaction->invoice_id; $r->invoice_number = $notification->transaction->invoice_number; $r->subscription_id = $notification->transaction->subscription_id; $r->amount = $notification->transaction->amount_in_cents / 100.0; $r->transaction_date = $notification->transaction->date; $r->notification_reference = $raw->id; $r->save(); } else { if ($notification->type == 'successful_refund_notification') { $r = new Revenue(); $r->account_code = $notification->account->account_code; $r->uuid = $notification->transaction->id; $r->invoice_id = $notification->transaction->invoice_id; $r->invoice_number = $notification->transaction->invoice_number; $r->subscription_id = $notification->transaction->subscription_id; $r->amount = $notification->transaction->amount_in_cents / 100.0 * -1; $r->transaction_date = $notification->transaction->date; $r->notification_reference = $raw->id; $r->save(); } else { if ($notification->type == 'failed_payment_notification') { } else { if ($notification->type == 'void_payment_notification') { } else { if ($notification->type == 'new_subscription_notification') {