1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/app/Http/Controllers/IntegrationController.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
2015-03-17 02:30:56 +01:00
2017-01-30 20:40:43 +01:00
namespace App\Http\Controllers;
use App\Models\Subscription;
2015-04-28 22:13:52 +02:00
use Auth;
use Input;
2017-01-30 20:40:43 +01:00
use Response;
use Utils;
2015-03-16 22:45:25 +01:00
/**
2017-01-30 20:40:43 +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')));
2017-01-30 20:40:43 +01:00
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
2017-01-30 20:40:43 +01:00
if (! $subscription) {
2015-03-16 22:45:25 +01:00
$subscription = new Subscription();
$subscription->account_id = Auth::user()->account_id;
$subscription->event_id = $eventId;
}
$subscription->target_url = trim(Input::get('target_url'));
$subscription->save();
2017-01-30 20:40:43 +01:00
if (! $subscription->id) {
2015-10-02 10:32:13 +02:00
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
}
}