Fixes for getting of purchased gift cards.

This commit is contained in:
M 2022-07-07 19:54:13 +01:00
parent 28ff890afd
commit d85cc72c42
5 changed files with 86 additions and 11 deletions

View file

@ -6,6 +6,7 @@ import 'package:http/http.dart';
import 'package:cake_wallet/ionia/ionia_user_credentials.dart';
import 'package:cake_wallet/ionia/ionia_virtual_card.dart';
import 'package:cake_wallet/ionia/ionia_category.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
class IoniaApi {
static const baseUri = 'apidev.ionia.io';
@ -17,6 +18,7 @@ class IoniaApi {
static final getMerchantsUrl = Uri.https(baseUri, '/$pathPrefix/GetMerchants');
static final getMerchantsByFilterUrl = Uri.https(baseUri, '/$pathPrefix/GetMerchantsByFilter');
static final getPurchaseMerchantsUrl = Uri.https(baseUri, '/$pathPrefix/PurchaseGiftCard');
static final getCurrentUserGiftCardSummariesUrl = Uri.https(baseUri, '/$pathPrefix/GetCurrentUserGiftCardSummaries');
// Create user
@ -245,7 +247,7 @@ class IoniaApi {
// Get Current User Gift Card Summaries
Future<List<IoniaMerchant>> getCurrentUserGiftCardSummaries({
Future<List<IoniaGiftCard>> getCurrentUserGiftCardSummaries({
@required String username,
@required String password,
@required String clientId}) async {
@ -253,7 +255,7 @@ class IoniaApi {
'clientId': clientId,
'username': username,
'password': password};
final response = await post(getMerchantsUrl, headers: headers);
final response = await post(getCurrentUserGiftCardSummariesUrl, headers: headers);
if (response.statusCode != 200) {
return [];
@ -269,7 +271,7 @@ class IoniaApi {
final data = decodedBody['Data'] as List<dynamic>;
return data.map((dynamic e) {
final element = e as Map<String, dynamic>;
return IoniaMerchant.fromJsonMap(element);
return IoniaGiftCard.fromJsonMap(element);
}).toList();
}
}

View file

@ -0,0 +1,71 @@
import 'package:flutter/foundation.dart';
class IoniaGiftCard {
IoniaGiftCard({
@required this.id,
@required this.merchantId,
@required this.legalName,
@required this.systemName,
@required this.barcodeUrl,
@required this.cardNumber,
@required this.cardPin,
@required this.usageInstructions,
@required this.balanceInstructions,
@required this.paymentInstructions,
@required this.cardImageUrl,
@required this.tip,
@required this.purchaseAmount,
@required this.actualAmount,
@required this.totalTransactionAmount,
@required this.totalDashTransactionAmount,
@required this.remainingAmount,
@required this.createdDateFormatted,
@required this.lastTransactionDateFormatted,
@required this.isActive,
@required this.isEmpty,
@required this.logoUrl});
factory IoniaGiftCard.fromJsonMap(Map<String, dynamic> element) {
return IoniaGiftCard(
id: element['Id'] as int,
merchantId: element['MerchantId'] as int,
legalName: element['LegalName'] as String,
systemName: element['SystemName'] as String,
barcodeUrl: element['BarcodeUrl'] as String,
cardNumber: element['CardNumber'] as String,
tip: element['Tip'] as double,
purchaseAmount: element['PurchaseAmount'] as double,
actualAmount: element['ActualAmount'] as double,
totalTransactionAmount: element['TotalTransactionAmount'] as double,
totalDashTransactionAmount: element['TotalDashTransactionAmount'] as double,
remainingAmount: element['RemainingAmount'] as double,
isActive: element['IsActive'] as bool,
isEmpty: element['IsEmpty'] as bool,
logoUrl: element['LogoUrl'] as String,
createdDateFormatted: element['CreatedDate'] as String,
lastTransactionDateFormatted: element['LastTransactionDate'] as String);
}
final int id;
final int merchantId;
final String legalName;
final String systemName;
final String barcodeUrl;
final String cardNumber;
final String cardPin;
final Map<String, dynamic> usageInstructions;
final Map<String, dynamic> balanceInstructions;
final Map<String, dynamic> paymentInstructions;
final String cardImageUrl;
final double tip;
final double purchaseAmount;
final double actualAmount;
final double totalTransactionAmount;
final double totalDashTransactionAmount;
final double remainingAmount;
final String createdDateFormatted;
final String lastTransactionDateFormatted;
final bool isActive;
final bool isEmpty;
final String logoUrl;
}

View file

@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'package:cake_wallet/ionia/ionia_api.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:cake_wallet/ionia/ionia_category.dart';
class IoniaService {
@ -114,7 +115,7 @@ class IoniaService {
// Get Current User Gift Card Summaries
Future<List<IoniaMerchant>> getCurrentUserGiftCardSummaries() async {
Future<List<IoniaGiftCard>> getCurrentUserGiftCardSummaries() async {
final username = await secureStorage.read(key: ioniaUsernameStorageKey);
final password = await secureStorage.read(key: ioniaPasswordStorageKey);
return ioniaApi.getCurrentUserGiftCardSummaries(username: username, password: password, clientId: clientId);

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/ionia/widgets/card_item.dart';
@ -125,7 +126,7 @@ class _IoniaCardListView extends StatelessWidget {
}) : super(key: key);
final String emptyText;
final List<IoniaMerchant> merchList;
final List<IoniaGiftCard> merchList;
@override
Widget build(BuildContext context) {
@ -148,12 +149,11 @@ class _IoniaCardListView extends StatelessWidget {
child: CardItem(
title: merchant.legalName,
backgroundColor: Theme.of(context).accentTextTheme.display4.backgroundColor.withOpacity(0.1),
discount: merchant.minimumDiscount,
discount: 0,
discountBackground: AssetImage('assets/images/red_badge_discount.png'),
titleColor: Theme.of(context).accentTextTheme.display4.backgroundColor,
subtitleColor: Theme.of(context).hintColor,
subTitle:
'${merchant.isOnline ? '${S.of(context).online}' ' && ${S.current.in_store}' : S.of(context).offline}',
subTitle: '',
logoUrl: merchant.logoUrl,
),
);

View file

@ -1,6 +1,7 @@
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
part 'ionia_account_view_model.g.dart';
@ -20,16 +21,16 @@ abstract class IoniaAccountViewModelBase with Store {
String email;
@observable
List<IoniaMerchant> merchs;
List<IoniaGiftCard> merchs;
@computed
int get countOfMerch => merchs.where((merch) => merch.isActive).length;
@computed
List<IoniaMerchant> get activeMechs => merchs.where((merch) => merch.isActive).toList();
List<IoniaGiftCard> get activeMechs => merchs.where((merch) => merch.isActive).toList();
@computed
List<IoniaMerchant> get redeemedMerchs => merchs.where((merch) => !merch.isActive).toList();
List<IoniaGiftCard> get redeemedMerchs => merchs.where((merch) => !merch.isActive).toList();
@action
void logout() {