Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/adding delete billing plan endpoint #640

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions app/Http/Controllers/BillingPlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ public function destroy(string $id)
if (!$plans) {
return response()->json([
'status_code' => 404,
'error' => 'Not Found',
'message' => 'Plan not found'
'status' => 'error',
'message' => 'Plan not found',
'data' => []
], 404);
}

Expand All @@ -175,14 +176,17 @@ public function destroy(string $id)

// Return success response
return response()->json([
'data' => true,
'status_code' => 200,
'data' => [],
'status_code' => 204,
'status' => 'success',
'message' => 'Plan deleted successfully'
], 200);
], 204);
} catch (\Exception $e) {
return response()->json([
'status' => 500,
'message' => 'Internal server error'
'status' => "error",
'status_code' => 500,
'message' => 'Internal server error',
'data' => []
], 500);
}
}
Expand Down
106 changes: 104 additions & 2 deletions resources/docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,58 @@
"description": "Billing plan details retrieved successfully"
}
}
}
},
"delete": {
"summary": "Delete billing plan",
"tags": ["Billing"],
"security": [
{
"bearerAuth": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "uuid"
}
}
],
"responses": {
"204": {
"description": "Billing plan details deleted successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"404": {
"description": "Billing plan not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
}
}
},
"/api/v1/payments/paystack/{organisation_id}/verify/{id}": {
"get": {
Expand Down Expand Up @@ -2425,7 +2476,58 @@
}
},
"required": ["type", "content"]
}
},
"ErrorResponse": {
"type": "object",
"properties": {
"status": {
"type": "string"
},
"status_code": {
"type": "integer"
},
"message": {
"type": "string"
},
"data": {
"type": "object"
}
}
},
"BillingPlan": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"duration": {
"type": "string"
},
"price": {
"type": "integer"
},
"description": {
"type": "string"
}
}
},
"BillingPlanResponse": {
"type": "object",
"properties": {
"status": {
"type": "string"
},
"status_code": {
"type": "integer"
},
"message": {
"type": "string"
},
"data": {
"$ref": "#/components/schemas/BillingPlan"
}
}
}
},
"securitySchemes": {
"bearerAuth": {
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
Route::get('/billing-plans', [BillingPlanController::class, 'index']);
Route::get('/billing-plans/{id}', [BillingPlanController::class, 'getBillingPlan']);
Route::put('/billing-plans/{id}', [BillingPlanController::class, 'update']);
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
15 changes: 15 additions & 0 deletions tests/Feature/BillingPlanControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\SubscriptionPlan;
use App\Models\User;

class BillingPlanControllerTest extends TestCase
{
Expand Down Expand Up @@ -58,4 +59,18 @@ public function it_updates_a_billing_plan_successfully()
'description' => 'An updated plan description',
]);
}

/** @test **/
public function test_delete_billing_plan()
{
$plan = SubscriptionPlan::factory()->create();
$user = User::factory()->create();
$this->actingAs($user);

$response = $this->deleteJson("/api/v1/billing-plans/{$plan->id}");

$response->assertStatus(204);

$this->assertDatabaseMissing('subscription_plans', ['id' => $plan->id]);
}
}
Loading