1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Controllers/IntegrationController.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2015-03-17 02:30:56 +01:00
<?php namespace App\Http\Controllers;
use Utils;
2015-04-28 22:13:52 +02:00
use Response;
use Auth;
use Input;
use App\Models\Subscription;
2015-03-16 22:45:25 +01:00
/**
* Class IntegrationController
*/
2015-03-16 22:45:25 +01:00
class IntegrationController extends Controller
{
/**
* @return \Illuminate\Http\JsonResponse
*/
2015-03-16 22:45:25 +01:00
public function subscribe()
{
$eventId = Utils::lookupEventId(trim(Input::get('event')));
if (!$eventId) {
2015-10-02 10:32:13 +02:00
return Response::json('Event is invalid', 500);
2015-03-16 22:45:25 +01:00
}
2015-10-02 10:32:13 +02:00
$subscription = Subscription::where('account_id', '=', Auth::user()->account_id)
->where('event_id', '=', $eventId)->first();
2015-03-16 22:45:25 +01: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 10:32:13 +02:00
if (!$subscription->id) {
return Response::json('Failed to create subscription', 500);
}
2016-11-15 09:39:35 +01:00
return Response::json(['id' => $subscription->id], 201);
2015-03-16 22:45:25 +01:00
}
}