Skip to content

Commit

Permalink
Merge pull request #582 from bamo100/deleteplan
Browse files Browse the repository at this point in the history
[FIX](PHP) Refactoring Billing Plan API Endpoint for  Deleting a Billing Plan
  • Loading branch information
timiajayi authored Aug 24, 2024
2 parents b5f7251 + d93064a commit a9abcae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/Http/Controllers/BillingPlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ public function update(Request $request, string $id)
*/
public function destroy(string $id)
{
//
$plans = SubscriptionPlan::find($id);

if (!$plans) {
return response()->json([
'status_code' => 404,
'error' => 'Not Found',
'message' => 'Plan not found'
], 404);
}

try {
$plans->delete();

// Return success response
return response()->json([
'data' => true,
'status_code' => 200,
'message' => 'Plan deleted successfully'
], 200);
} catch (\Exception $e) {
return response()->json([
'status' => 500,
'message' => 'Internal server error'
], 500);
}
}
}
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
Route::get('/products/{product_id}', [ProductController::class, 'show']);
Route::get('/billing-plans', [BillingPlanController::class, 'index']);
Route::get('/billing-plans/{id}', [BillingPlanController::class, 'getBillingPlan']);
Route::delete('/billing-plans/{id}', [BillingPlanController::class, 'destroy']);
Route::get('/payments/paystack/{organisation_id}/verify/{id}', [PaymentController::class, 'handlePaystackCallback']);
Route::get('/payments/flutterwave/{organisation_id}/verify/{id}', [PaymentController::class, 'handleFlutterwaveCallback']);
Route::post('/languages', [LanguageController::class, 'create']);
Expand Down

0 comments on commit a9abcae

Please sign in to comment.