Skip to content

Commit

Permalink
Move payment status string to Strings class; use Strings.price to…
Browse files Browse the repository at this point in the history
… format price
  • Loading branch information
marfavi committed May 27, 2023
1 parent 20b08de commit e9e0cb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 7 additions & 0 deletions lib/base/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ abstract final class Strings {
static String noReceiptsOfTypeMessage(String buyOrSwipe) =>
'When you $buyOrSwipe tickets, they will show up here.\nGo to the Tickets tab to $buyOrSwipe tickets.';

// PaymentStatus enum
static const paymentStatusCompleted = 'Purchased';
static const paymentStatusRefunded = 'Purchase refunded';
static const paymentStatusAwaitingPayment = 'Payment pending';
static const paymentStatusReserved = 'Payment reserved';
static const paymentStatusFailed = 'Payment failed';

// Statistics page
static const statsYourStats = 'Your stats';
static const statsLeaderboards = 'Leaderboards';
Expand Down
14 changes: 8 additions & 6 deletions lib/features/purchase/domain/entities/payment_status.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:coffeecard/base/strings.dart';
import 'package:coffeecard/generated/api/coffeecard_api_v2.enums.swagger.dart';

enum PaymentStatus {
Expand Down Expand Up @@ -32,12 +33,13 @@ enum PaymentStatus {
@override
String toString() {
return switch (this) {
PaymentStatus.completed => 'Purchased',
PaymentStatus.refunded => 'Purchase refunded',
PaymentStatus.rejectedPayment => 'Payment rejected',
PaymentStatus.awaitingPayment => 'Payment pending',
PaymentStatus.error => 'Payment error',
PaymentStatus.reserved => 'Payment reserved',
PaymentStatus.completed => Strings.paymentStatusCompleted,
PaymentStatus.refunded => Strings.paymentStatusRefunded,
PaymentStatus.awaitingPayment => Strings.paymentStatusAwaitingPayment,
PaymentStatus.reserved => Strings.paymentStatusReserved,
PaymentStatus.rejectedPayment ||
PaymentStatus.error =>
Strings.paymentStatusFailed,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:coffeecard/base/strings.dart';
import 'package:coffeecard/base/style/colors.dart';
import 'package:coffeecard/features/purchase/domain/entities/payment_status.dart';
import 'package:coffeecard/features/receipt/domain/entities/receipt.dart';
Expand All @@ -12,13 +13,13 @@ class PurchaseReceiptListEntry extends StatelessWidget {
});

String get priceText {
final price = receipt.price;
final price = Strings.price(receipt.price);
return switch (receipt.paymentStatus) {
PaymentStatus.completed => '$price,-',
PaymentStatus.completed => price,
PaymentStatus.awaitingPayment ||
PaymentStatus.reserved ||
PaymentStatus.refunded =>
'($price,-)',
'($price)',
PaymentStatus.error || PaymentStatus.rejectedPayment => '',
};
}
Expand Down

0 comments on commit e9e0cb1

Please sign in to comment.