mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Subscription;
|
|
use Auth;
|
|
use Response;
|
|
use Utils;
|
|
|
|
/**
|
|
* Class IntegrationController.
|
|
*/
|
|
class IntegrationController extends BaseAPIController
|
|
{
|
|
/**
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function subscribe()
|
|
{
|
|
$eventId = Utils::lookupEventId(trim(\Request::input('event')));
|
|
|
|
if (! $eventId) {
|
|
return Response::json('Event is invalid', 500);
|
|
}
|
|
|
|
$subscription = Subscription::createNew();
|
|
$subscription->event_id = $eventId;
|
|
$subscription->target_url = trim(\Request::input('target_url'));
|
|
$subscription->save();
|
|
|
|
if (! $subscription->id) {
|
|
return Response::json('Failed to create subscription', 500);
|
|
}
|
|
|
|
return Response::json(['id' => $subscription->public_id], 201);
|
|
}
|
|
|
|
public function unsubscribe($publicId)
|
|
{
|
|
$subscription = Subscription::scope($publicId)->firstOrFail();
|
|
$subscription->delete();
|
|
|
|
return $this->response(RESULT_SUCCESS);
|
|
}
|
|
}
|