Skip to content

Commit

Permalink
Merge pull request #428 from Goldengide/fix/preference-endpoint
Browse files Browse the repository at this point in the history
fix: response bodies accross implemented apis
  • Loading branch information
timiajayi authored Aug 8, 2024
2 parents 7984e56 + e52a016 commit 12d4317
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 48 deletions.
24 changes: 12 additions & 12 deletions app/Http/Controllers/Api/V1/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function create(Request $request)
{
if (!auth()->check()) {
return response()->json([
'status' => 401,
'status_code' => 401,
'message' => 'Unauthorized'
], 401);
}
Expand All @@ -29,7 +29,7 @@ public function create(Request $request)

if ($validator->fails()) {
return response()->json([
'status' => 400,
'status_code' => 400,
'message' => 'Bad Request',
'errors' => $validator->errors()
], 400);
Expand All @@ -43,17 +43,17 @@ public function create(Request $request)
]);

return response()->json([
'status' => 201,
'status_code' => 201,
'message' => 'Language Created Successfully',
'language' => $language
'data' => $language
], 201);
}

public function update(Request $request, $id)
{
if (!auth()->check()) {
return response()->json([
'status' => 401,
'status_code' => 401,
'message' => 'Unauthorized'
], 401);
}
Expand All @@ -66,7 +66,7 @@ public function update(Request $request, $id)

if ($validator->fails()) {
return response()->json([
'status' => 400,
'status_code' => 400,
'message' => 'Validation Error',
'errors' => $validator->errors()
], 400);
Expand All @@ -76,7 +76,7 @@ public function update(Request $request, $id)

if (!$language) {
return response()->json([
'status' => 404,
'status_code' => 404,
'message' => 'Language not found'
], 404);
}
Expand All @@ -88,9 +88,9 @@ public function update(Request $request, $id)
]);

return response()->json([
'status' => 200,
'status_code' => 200,
'message' => 'Language Updated Successfully',
'language' => $language
'data' => $language
], 200);
}

Expand All @@ -99,7 +99,7 @@ public function index()
{
if (!auth()->check()) {
return response()->json([
'status' => 401,
'status_code' => 401,
'message' => 'Unauthorized'
], 401);
}
Expand All @@ -109,9 +109,9 @@ public function index()
$languages = Language::select('id', 'language', 'code')->get();

return response()->json([
'status' => 200,
'status_code' => 200,
'message' => 'Languages fetched successfully',
'languages' => $languages
'data' => $languages
], 200);
}
}
Expand Down
38 changes: 19 additions & 19 deletions app/Http/Controllers/Api/V1/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function initiatePaymentForPayStack(Request $request)

if ($validator->fails()) {
return response()->json([
'status' => 400,
'status_code' => 400,
'message' => 'Validation error: ' . $validator->errors()->first()
], 400);
}
Expand All @@ -51,7 +51,7 @@ public function initiatePaymentForPayStack(Request $request)
->exists();
if (!$userIsAnAdminInOrganisation) {
return response()->json([
'status' => 403,
'status_code' => 403,
'message' => 'You do not have permission to initiate this payment'
], 403);
}
Expand All @@ -60,7 +60,7 @@ public function initiatePaymentForPayStack(Request $request)
$subscriptionPlan = SubscriptionPlan::find($request->plan_id);
if(!$subscriptionPlan) {
return response()->json([
'status' => 404,
'status_code' => 404,
'message' => 'Subscription Plan not found'
], 404);
}
Expand All @@ -87,15 +87,15 @@ public function initiatePaymentForPayStack(Request $request)
$payment->save();

return response()->json([
'status' => 200,
'status_code' => 200,
'message' => 'Payment initiated successfully',
'data' => [
'payment_url' => $paymentUrl
]
]);
} catch (\Exception $e) {
return response()->json([
'status' => 500,
'status_code' => 500,
'message' => 'An unexpected error occurred. Please try again later.'
// 'message' => 'Payment Initialization Failed: ' . $e->getMessage()
], 500);
Expand Down Expand Up @@ -123,7 +123,7 @@ public function handlePaystackCallback($organisation_id, $id, Request $request)
$user = Organisation::find($organisation_id)->first();
if(!$user) {
return response()->json([
'status' => 404,
'status_code' => 404,
'message' => 'User Not found'
], 404);
}
Expand All @@ -140,7 +140,7 @@ public function handlePaystackCallback($organisation_id, $id, Request $request)
return redirect()->to($payment->redirect_url . '?status=' . $payment->status);
} catch (Exception $e) {
return response()->json([
'status' => 500,
'status_code' => 500,
'message' => 'Transaction Verification Failed: ' . $e->getMessage()
], 500);
}
Expand All @@ -165,7 +165,7 @@ public function initiatePaymentForFlutterWave(Request $request)

if ($validator->fails()) {
return response()->json([
'status' => 400,
'status_code' => 400,
'message' => 'Validation error: ' . $validator->errors()->first()
], 400);
}
Expand All @@ -176,15 +176,15 @@ public function initiatePaymentForFlutterWave(Request $request)
// return response()->json(auth()->user()->id);
if (!$userIsAnAdminInOrganisation) {
return response()->json([
'status' => 403,
'status_code' => 403,
'message' => 'You do not have permission to initiate this payment'
], 403);
}
// $gateway_id = Gateway::where('code', 'flutterwave')->first()->id;
$subscriptionPlan = SubscriptionPlan::find($request->plan_id);
if(!$subscriptionPlan) {
return response()->json([
'status' => 404,
'status_code' => 404,
'message' => 'Subscription Plan not found'
], 404);
}
Expand Down Expand Up @@ -217,15 +217,15 @@ public function initiatePaymentForFlutterWave(Request $request)
$payment->save();

return response()->json([
'status' => 200,
'status_code' => 200,
'message' => 'Payment initiated successfully',
'data' => [
'payment_url' => $paymentUrl
]
]);
} catch (\Exception $e) {
return response()->json([
'status' => 500,
'status_code' => 500,
'message' => 'An unexpected error occurred. Please try again later.'
// 'message' => 'Payment Initialization Failed: ' . $e->getMessage()
], 500);
Expand Down Expand Up @@ -253,7 +253,7 @@ public function handleFlutterwaveCallback($organisation_id, $id, Request $reques
$user = Organisation::find($organisation_id)->first();
if(!$user) {
return response()->json([
'status' => 404,
'status_code' => 404,
'message' => 'User Not found'
], 404);
}
Expand All @@ -269,7 +269,7 @@ public function handleFlutterwaveCallback($organisation_id, $id, Request $reques
return redirect()->to($payment->redirect_url . '?status=' . $payment->status);
} catch (Exception $e) {
return response()->json([
'status' => 500,
'status_code' => 500,
'message' => 'Transaction Verification Failed: ' . $e->getMessage()
], 500);
}
Expand All @@ -286,7 +286,7 @@ public function initiatePaymentGeneral(Request $request)

if ($validator->fails()) {
return response()->json([
'status' => 400,
'status_code' => 400,
'message' => 'Validation error: ' . $validator->errors()->first()
], 400);
}
Expand All @@ -305,7 +305,7 @@ public function initiatePaymentGeneral(Request $request)
$paymentUrl = $this->paymentService->initiateFlutterwavePayment($data);
} else {
return response()->json([
'status' => 400,
'status_code' => 400,
'message' => 'Unsupported payment gateway'
], 400);
}
Expand All @@ -320,15 +320,15 @@ public function initiatePaymentGeneral(Request $request)
$payment->save();

return response()->json([
'status' => 200,
'status_code' => 200,
'message' => 'Payment initiated successfully',
'data' => [
'payment_url' => $paymentUrl
]
]);
} catch (\Exception $e) {
return response()->json([
'status' => 500,
'status_code' => 500,
'message' => 'Payment Initialization Failed: ' . $e->getMessage()
], 500);
}
Expand All @@ -338,7 +338,7 @@ public function cancel(Request $request)
{

return response()->json([
'status' => 200,
'status_code' => 200,
'message' => 'Payment was cancelled.',
], 200);
}
Expand Down
Loading

0 comments on commit 12d4317

Please sign in to comment.