invoiceninja/app/Http/Controllers/IntegrationController.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2015-03-17 11:30:56 +10:00
<?php namespace App\Http\Controllers;
use Utils;
2015-04-28 23:13:52 +03:00
use Response;
use Auth;
use Input;
use App\Models\Subscription;
2015-03-17 07:45:25 +10:00
/**
* Class IntegrationController
*/
2015-03-17 07:45:25 +10:00
class IntegrationController extends Controller
{
/**
* @return \Illuminate\Http\JsonResponse
*/
2015-03-17 07:45:25 +10:00
public function subscribe()
{
$eventId = Utils::lookupEventId(trim(Input::get('event')));
if (!$eventId) {
2015-10-02 11:32:13 +03:00
return Response::json('Event is invalid', 500);
2015-03-17 07:45:25 +10:00
}
2015-10-02 11:32:13 +03:00
$subscription = Subscription::where('account_id', '=', Auth::user()->account_id)
->where('event_id', '=', $eventId)->first();
2015-03-17 07:45:25 +10:00
if (!$subscription) {
$subscription = new Subscription();
$subscription->account_id = Auth::user()->account_id;
$subscription->event_id = $eventId;
}
$subscription->target_url = trim(Input::get('target_url'));
$subscription->save();
2015-10-02 11:32:13 +03:00
if (!$subscription->id) {
return Response::json('Failed to create subscription', 500);
}
2015-03-17 07:45:25 +10:00
return Response::json('{"id":'.$subscription->id.'}', 201);
}
}