Skip to content

Commit

Permalink
Refactor code: Improve type checking, error handling, and code format…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
isrugeek committed Jan 31, 2025
1 parent 2d512f1 commit 75ed872
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion example/lib/model/cart_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Cart {

Map<String, dynamic> toMap() {
return {

'productId': productId,
'productName': productName,
'initialPrice': initialPrice,
Expand Down
2 changes: 1 addition & 1 deletion lib/chapawebview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _ChapaWebViewState extends State<ChapaWebView> {
}

void handleConnectivityChange(List<ConnectivityResult> result) {
if (result == ConnectivityResult.none) {
if (result.contains(ConnectivityResult.none)) {
setState(() {
isOffline = true;
});
Expand Down
11 changes: 8 additions & 3 deletions lib/data/model/response/api_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class ApiResponse {
break;
case 401:
try {
message = body is Map ? body['message'] ?? "Unauthorized" : "Unauthorized";
message =
body is Map ? body['message'] ?? "Unauthorized" : "Unauthorized";
errors.add(message);
} catch (error) {
errors.add("Unauthorized");
Expand All @@ -67,14 +68,18 @@ class ApiResponse {
break;
case 429:
try {
message = body is Map ? body['message'] ?? "Too many requests" : "Too many requests";
message = body is Map
? body['message'] ?? "Too many requests"
: "Too many requests";
errors.add(message);
} catch (error) {
errors.add("Too many requests");
}
break;
default:
message = body is Map ? body["message"] ?? "Something went wrong." : "Something went wrong.";
message = body is Map
? body["message"] ?? "Something went wrong."
: "Something went wrong.";
break;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/domain/constants/extentions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ extension PaymentTypeExtension on LocalPaymentMethods {

/// Returns the `VerificationType` associated with the payment method.
VerificationType verificationType() {
return VerificationType.ussd; // All methods default to USSD in this implementation.
return VerificationType
.ussd; // All methods default to USSD in this implementation.
}

/// Returns the icon path for the payment method.
Expand Down Expand Up @@ -91,7 +92,8 @@ extension StringExtension on String {
case "pending":
return PaymentStatus.pending;
default:
return PaymentStatus.pending; // Defaults to pending in this implementation.
return PaymentStatus
.pending; // Defaults to pending in this implementation.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ sealed class ChapaNativeCheckoutEvent {}

// ignore: must_be_immutable
/// Event triggered to initiate the payment process.
///
///
/// Contains the payment request data and the public key required for the payment.
class InitiatePayment extends ChapaNativeCheckoutEvent {

/// The request data needed to initialize a direct charge payment.
final DirectChargeRequest directChargeRequest;

/// The public key used to authenticate the payment request with the Chapa API.
final String publicKey;

Expand All @@ -28,19 +27,18 @@ class InitiatePayment extends ChapaNativeCheckoutEvent {

// ignore: must_be_immutable
/// Event triggered to validate a payment after initiation.
///
///
/// Contains the request data to verify the payment status and the public key.
class ValidatePayment extends ChapaNativeCheckoutEvent {

/// The request data needed to validate the direct charge payment.
final ValidateDirectChargeRequest validateDirectChargeRequest;

/// The public key used to authenticate the payment validation with the Chapa API.
final String publicKey;

/// Constructor for the [ValidatePayment] event.
///
/// [validateDirectChargeRequest]: The request object containing reference and
/// [validateDirectChargeRequest]: The request object containing reference and
/// other details to validate the payment.
/// [publicKey]: The public key used for authentication with the Chapa API.
ValidatePayment({
Expand Down

0 comments on commit 75ed872

Please sign in to comment.