diff --git a/lib/constants.dart b/lib/constants.dart index a95b8b9ea..1c51d5788 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -238,6 +238,7 @@ const kNotificationEvents = [ ]; const String kGatewayStripe = 'd14dd26a37cecc30fdd65700bfb55b23'; +const String kGatewayCustom = '54faab2ab6e3223dbe848b1686490baa'; const String kClientPortalModeSubdomain = 'subdomain'; const String kClientPortalModeDomain = 'domain'; diff --git a/lib/data/models/company_gateway_model.dart b/lib/data/models/company_gateway_model.dart index 6aa3863a9..ea2126c9c 100644 --- a/lib/data/models/company_gateway_model.dart +++ b/lib/data/models/company_gateway_model.dart @@ -140,6 +140,8 @@ abstract class CompanyGatewayEntity extends Object return gateway.name; } + bool get isCustom => gatewayId == kGatewayCustom; + bool supportsCard(int cardType) => acceptedCreditCards & cardType > 0; CompanyGatewayEntity addCard(int cardType) => diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index 7ca74a167..aba55fdc0 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -278,18 +278,13 @@ abstract class CompanyEntity extends Object } return matchesStrings( - haystacks: [ - subdomain, - displayName, - companyKey - ], + haystacks: [subdomain, displayName, companyKey], needle: filter, ); } @override String matchesFilterValue(String filter) { - for (final user in users) { final value = user.matchesFilterValue(filter); if (value != null) { @@ -310,11 +305,7 @@ abstract class CompanyEntity extends Object } return matchesStringsValue( - haystacks: [ - subdomain, - displayName, - companyKey - ], + haystacks: [subdomain, displayName, companyKey], needle: filter, ); } @@ -350,15 +341,13 @@ abstract class CompanyEntity extends Object bool get hasCustomSurcharge => hasCustomField(CustomFieldType.surcharge1) || - hasCustomField(CustomFieldType.surcharge2) || - hasCustomField(CustomFieldType.surcharge3) || - hasCustomField(CustomFieldType.surcharge4); + hasCustomField(CustomFieldType.surcharge2) || + hasCustomField(CustomFieldType.surcharge3) || + hasCustomField(CustomFieldType.surcharge4); String getCustomFieldLabel(String field) { if (customFields.containsKey(field)) { - return customFields[field] - .split('|') - .first; + return customFields[field].split('|').first; } else { return ''; } @@ -366,9 +355,7 @@ abstract class CompanyEntity extends Object String getCustomFieldType(String field) { if ((customFields[field] ?? '').contains('|')) { - final value = customFields[field] - .split('|') - .last; + final value = customFields[field].split('|').last; if ([kFieldTypeSingleLineText, kFieldTypeDate, kFieldTypeSwitch] .contains(value)) { return value; @@ -405,9 +392,7 @@ abstract class CompanyEntity extends Object } // TODO make sure to clear everything - CompanyEntity get coreCompany => - rebuild((b) => - b + CompanyEntity get coreCompany => rebuild((b) => b ..clients.clear() ..products.clear() ..invoices.clear() @@ -418,8 +403,8 @@ abstract class CompanyEntity extends Object ..projects.clear() ..vendors.clear() ..expenses.clear() - //..designs.clear() - //..companyGateways.clear() + //..designs.clear() + //..companyGateways.clear() ); bool isModuleEnabled(EntityType entityType) { @@ -435,7 +420,7 @@ abstract class CompanyEntity extends Object } if ((entityType == EntityType.invoice || - entityType == EntityType.payment) && + entityType == EntityType.payment) && enabledModules & kModuleInvoices == 0) { return false; } else if (entityType == EntityType.credit && @@ -503,6 +488,8 @@ abstract class GatewayEntity extends Object String get fields; + bool get supportsTokenBilling => [kGatewayStripe].contains(id); + Map get parsedFields => fields.isEmpty ? {} : jsonDecode(fields); @@ -571,7 +558,6 @@ abstract class GatewayEntity extends Object FormatNumberType get listDisplayAmountType => null; } - abstract class UserCompanyEntity implements Built { factory UserCompanyEntity() { @@ -583,10 +569,9 @@ abstract class UserCompanyEntity user: UserEntity(), token: TokenEntity(), account: AccountEntity(), - notifications: BuiltMap>().rebuild((b) => - b + notifications: BuiltMap>().rebuild((b) => b ..[kNotificationChannelEmail] = - BuiltList([kNotificationsAll])), + BuiltList([kNotificationsAll])), ); } @@ -656,7 +641,7 @@ abstract class UserCompanyEntity bool receivesAllNotifications(String channel) => notifications.containsKey(channel) && - notifications[channel].contains(kNotificationsAll); + notifications[channel].contains(kNotificationsAll); bool canView(EntityType entityType) => can(UserPermission.view, entityType); @@ -861,9 +846,9 @@ abstract class SettingsEntity groupSettings?.customMessagePaidInvoice ?? companySettings?.customMessagePaidInvoice, customMessageUnapprovedQuote: - clientSettings?.customMessageUnapprovedQuote ?? - groupSettings?.customMessageUnapprovedQuote ?? - companySettings?.customMessageUnapprovedQuote, + clientSettings?.customMessageUnapprovedQuote ?? + groupSettings?.customMessageUnapprovedQuote ?? + companySettings?.customMessageUnapprovedQuote, lockSentInvoices: clientSettings?.lockSentInvoices ?? groupSettings?.lockSentInvoices ?? companySettings?.lockSentInvoices, @@ -1069,7 +1054,7 @@ abstract class SettingsEntity groupSettings?.requireQuoteSignature ?? companySettings?.requireQuoteSignature, name: - clientSettings?.name ?? groupSettings?.name ?? companySettings?.name, + clientSettings?.name ?? groupSettings?.name ?? companySettings?.name, companyLogo: clientSettings?.companyLogo ?? groupSettings?.companyLogo ?? companySettings?.companyLogo, @@ -1083,7 +1068,7 @@ abstract class SettingsEntity groupSettings?.address2 ?? companySettings?.address2, city: - clientSettings?.city ?? groupSettings?.city ?? companySettings?.city, + clientSettings?.city ?? groupSettings?.city ?? companySettings?.city, state: clientSettings?.state ?? groupSettings?.state ?? companySettings?.state, @@ -1966,7 +1951,7 @@ abstract class SettingsEntity abstract class CompanyItemResponse implements Built { factory CompanyItemResponse([void updates(CompanyItemResponseBuilder b)]) = - _$CompanyItemResponse; + _$CompanyItemResponse; CompanyItemResponse._(); diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index dd9587f9a..75972af85 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -633,6 +633,7 @@ abstract class AppState implements Built { //return 'Invitations: ${uiState.invoiceUIState.editing.invitations}'; //return 'Selection: ${clientUIState.selectedId}'; //return '${clientState.map[clientUIState.selectedId].gatewayTokens}'; + //return 'gatewayId: ${companyGatewayState.map[companyGatewayUIState.selectedId].gatewayId}'; return '\n\nURL: ${authState.url}\nRoute: ${uiState.currentRoute}\nPrev: ${uiState.previousRoute}\nIs Loaded: ${isLoaded ? 'Yes' : 'No'}\nis Large: ${(company?.isLarge ?? false) ? 'Yes' : 'No'}\nCompany: $companyUpdated${userCompanyState.isStale ? ' [S]' : ''}\nStatic: $staticUpdated${staticState.isStale ? ' [S]' : ''}\n'; } } diff --git a/lib/ui/company_gateway/view/company_gateway_view.dart b/lib/ui/company_gateway/view/company_gateway_view.dart index d9b9f7eba..9b46e699f 100644 --- a/lib/ui/company_gateway/view/company_gateway_view.dart +++ b/lib/ui/company_gateway/view/company_gateway_view.dart @@ -7,6 +7,7 @@ import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_selec import 'package:invoiceninja_flutter/ui/app/FieldGrid.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_list_tile.dart'; import 'package:invoiceninja_flutter/ui/app/entity_header.dart'; +import 'package:invoiceninja_flutter/ui/app/icon_message.dart'; import 'package:invoiceninja_flutter/ui/app/lists/list_divider.dart'; import 'package:invoiceninja_flutter/ui/app/view_scaffold.dart'; import 'package:invoiceninja_flutter/ui/company_gateway/view/company_gateway_view_vm.dart'; @@ -64,13 +65,13 @@ class _CompanyGatewayViewState extends State { isFilter: widget.isFilter, entity: companyGateway, onBackPressed: () => viewModel.onBackPressed(), - body: ListView( - children: [ - EntityHeader( - entity: companyGateway, - label: localization.processed, - value: formatNumber(processed, context)), - ListDivider(), + body: ListView(children: [ + EntityHeader( + entity: companyGateway, + label: localization.processed, + value: formatNumber(processed, context)), + ListDivider(), + if (companyGateway.gateway.supportsTokenBilling) ...[ EntitiesListTile( isFilter: widget.isFilter, entityType: EntityType.client, @@ -83,23 +84,23 @@ class _CompanyGatewayViewState extends State { companyGateway.id, state.clientState.map) .present(localization.active, localization.archived), ), - ListDivider(), - EntitiesListTile( - isFilter: widget.isFilter, - entityType: EntityType.payment, - title: localization.payments, - onTap: () => viewEntitiesByType( - context: context, - entityType: EntityType.payment, - filterEntity: companyGateway), - subtitle: memoizedPaymentStatsForCompanyGateway( - companyGateway.id, state.paymentState.map) - .present(localization.active, localization.archived), - ), - ListDivider(), - FieldGrid(fields), ], - ), + ListDivider(), + EntitiesListTile( + isFilter: widget.isFilter, + entityType: EntityType.payment, + title: localization.payments, + onTap: () => viewEntitiesByType( + context: context, + entityType: EntityType.payment, + filterEntity: companyGateway), + subtitle: memoizedPaymentStatsForCompanyGateway( + companyGateway.id, state.paymentState.map) + .present(localization.active, localization.archived), + ), + ListDivider(), + FieldGrid(fields), + ]), ); } }