Skip to content

Commit

Permalink
fix add api for webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Nov 20, 2024
1 parent aa3e730 commit 3e16bdf
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Http/Controllers/Api/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,80 @@
class WebhookController extends Controller
{
// create a new webhook
public function create(Request $request) {
$request->validate([
'webhook' => 'required',
'webhook.url' => 'required',
'webhook.topic' => 'required',
'webhook.format' => 'required',
'webhook.fields' => 'required',
'webhook.fields.*' => 'required',
]);

$webhook = Webhook::create($request->webhook);

return response()->json([
'data' => $webhook
]);
}

// update a webhook
public function update(Request $request, $id) {
$request->validate([
'webhook' => 'required',
'webhook.url' => 'required',
'webhook.topic' => 'required',
'webhook.format' => 'required',
'webhook.fields' => 'required',
'webhook.fields.*' => 'required',
]);

$webhook = Webhook::findOrFail($id);
$webhook->update($request->webhook);

return response()->json([
'data' => $webhook
]);
}
// delete a webhook
public function delete($id) {
$webhook = Webhook::findOrFail($id);
$webhook->delete();

return response()->json([
'data' => $webhook
]);
}
// list all webhooks
public function list(Request $request) {
$webhooks = Webhook::where("user_id", Auth()->user()->id)->get();

return response()->json([
'data' => $webhooks
]);
}
// get a webhook
public function get($id) {
$webhook = Webhook::findOrFail($id);

return response()->json([
'data' => $webhook
]);
}
// test a webhook
public function test(Request $request, $id) {
$webhook = Webhook::findOrFail($id);

$response = Http::post($webhook->url, [
'data' => [
'message' => 'This is a test message'
]
]);

return response()->json([
'data' => $response->json()
]);
}

// list all webhook types
// https://shopify.dev/docs/api/webhooks?reference=toml
Expand Down

0 comments on commit 3e16bdf

Please sign in to comment.