Add fee calculation back in V5 #322
This commit is contained in:
parent
98eeb8e431
commit
ac5e60ffbc
|
|
@ -362,6 +362,36 @@ abstract class FeesAndLimitsSettings
|
|||
@BuiltValueField(wireName: 'is_enabled')
|
||||
bool get isEnabled;
|
||||
|
||||
double calculateSampleFee(double amount) {
|
||||
double fee = 0;
|
||||
|
||||
fee += feeAmount;
|
||||
|
||||
if (feePercent != 0) {
|
||||
if (adjustFeePercent) {
|
||||
fee += round((amount / (1 - feePercent / 100)) - amount, 2);
|
||||
} else {
|
||||
fee += round(amount * feePercent / 100, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (taxRate1 != 0) {
|
||||
fee += round(amount * 1 / taxRate1, 2);
|
||||
}
|
||||
if (taxRate2 != 0) {
|
||||
fee += round(amount * 1 / taxRate2, 2);
|
||||
}
|
||||
if (taxRate2 != 0) {
|
||||
fee += round(amount * 1 / taxRate2, 2);
|
||||
}
|
||||
|
||||
if (feeCap > 0 && fee > feeCap) {
|
||||
fee = feeCap;
|
||||
}
|
||||
|
||||
return fee;
|
||||
}
|
||||
|
||||
// ignore: unused_element
|
||||
static void _initializeBuilder(FeesAndLimitsSettingsBuilder builder) =>
|
||||
builder..isEnabled = false;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class LearnMoreUrl extends StatelessWidget {
|
|||
}
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: child,
|
||||
|
|
@ -37,11 +36,7 @@ class LearnMoreUrl extends StatelessWidget {
|
|||
),
|
||||
TextButton(
|
||||
child: Text(label ?? localization.learnMore),
|
||||
onPressed: () async {
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url, forceSafariVC: false, forceWebView: false);
|
||||
}
|
||||
},
|
||||
onPressed: () => launch(url),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -902,6 +902,21 @@ class _FeesEditorState extends State<FeesEditor> {
|
|||
}
|
||||
}
|
||||
|
||||
String _sampleFee() {
|
||||
final localization = AppLocalization.of(context);
|
||||
final viewModel = widget.viewModel;
|
||||
final companyGateway = viewModel.companyGateway;
|
||||
final settings =
|
||||
companyGateway.getSettingsForGatewayTypeId(widget.gatewayTypeId);
|
||||
|
||||
const double amount = 100;
|
||||
final fee = settings.calculateSampleFee(100);
|
||||
|
||||
return localization.feesSample
|
||||
.replaceFirst(':amount', formatNumber(amount, context))
|
||||
.replaceFirst(':total', formatNumber(fee, context));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localization = AppLocalization.of(context);
|
||||
|
|
@ -912,6 +927,7 @@ class _FeesEditorState extends State<FeesEditor> {
|
|||
companyGateway.getSettingsForGatewayTypeId(widget.gatewayTypeId);
|
||||
|
||||
return FormCard(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
DecoratedFormField(
|
||||
label: localization.feePercent,
|
||||
|
|
@ -927,13 +943,6 @@ class _FeesEditorState extends State<FeesEditor> {
|
|||
keyboardType:
|
||||
TextInputType.numberWithOptions(decimal: true, signed: true),
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.feeCap,
|
||||
controller: _capController,
|
||||
isMoney: true,
|
||||
keyboardType:
|
||||
TextInputType.numberWithOptions(decimal: true, signed: true),
|
||||
),
|
||||
if (company.enableFirstItemTaxRate)
|
||||
TaxRateDropdown(
|
||||
onSelected: (taxRate) => viewModel.onChanged(companyGateway.rebuild(
|
||||
|
|
@ -970,6 +979,13 @@ class _FeesEditorState extends State<FeesEditor> {
|
|||
initialTaxName: settings.taxName3,
|
||||
initialTaxRate: settings.taxRate3,
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.feeCap,
|
||||
controller: _capController,
|
||||
isMoney: true,
|
||||
keyboardType:
|
||||
TextInputType.numberWithOptions(decimal: true, signed: true),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
LearnMoreUrl(
|
||||
url: kGatewayFeeHelpURL,
|
||||
|
|
@ -984,6 +1000,11 @@ class _FeesEditorState extends State<FeesEditor> {
|
|||
subtitle: Text(localization.adjustFeePercentHelp),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
_sampleFee(),
|
||||
style: TextStyle(color: Colors.grey),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
static final Map<String, Map<String, String>> _localizedValues = {
|
||||
'en': {
|
||||
// STARTER: lang key - do not remove comment
|
||||
'fees_sample': 'The fee for a :amount invoice would be :total.',
|
||||
'enable_touch_events': 'Enable Touch Events',
|
||||
'enable_touch_events_help': 'Support drag events to scroll',
|
||||
'after_saving': 'After Saving',
|
||||
|
|
@ -74210,6 +74211,10 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
_localizedValues[localeCode]['enable_touch_events_help'] ??
|
||||
_localizedValues['en']['enable_touch_events_help'];
|
||||
|
||||
String get feesSample =>
|
||||
_localizedValues[localeCode]['fees_sample'] ??
|
||||
_localizedValues['en']['fees_sample'];
|
||||
|
||||
// STARTER: lang field - do not remove comment
|
||||
|
||||
String lookup(String key) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue