diff --git a/CHANGELOG.md b/CHANGELOG.md index c664934..84112ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ +### 2.1.1 March 17th, 2024 + +- Fixed applied taxes and applied discounts on `OrderLineItem` + ### 2.1.0 October 14th, 2023 + - Added customer group and customer segment endpoints! ### 2.0.2 October 14th, 2023 + - Hot fixed issue with modifier location overrides ### 2.0.1 July 3rd, 2023 diff --git a/lib/src/shared_model/order_line_item.dart b/lib/src/shared_model/order_line_item.dart index 6edf625..f1c55a1 100644 --- a/lib/src/shared_model/order_line_item.dart +++ b/lib/src/shared_model/order_line_item.dart @@ -43,8 +43,8 @@ class OrderLineItem extends Equatable { final String? catalogObjectId; final String? variationName; final List? modifiers; - final List? appliedTaxes; - final List? appliedDiscounts; + final List? appliedTaxes; + final List? appliedDiscounts; final Money? basePriceMoney; final Money? variationTotalPriceMoney; final Money? grossSalesMoney; diff --git a/lib/src/shared_model/order_line_item.g.dart b/lib/src/shared_model/order_line_item.g.dart index db132d2..b3b8d9f 100644 --- a/lib/src/shared_model/order_line_item.g.dart +++ b/lib/src/shared_model/order_line_item.g.dart @@ -23,11 +23,12 @@ OrderLineItem _$OrderLineItemFromJson(Map json) => (e) => OrderLineItemModifier.fromJson(e as Map)) .toList(), appliedDiscounts: (json['applied_discounts'] as List?) - ?.map( - (e) => OrderLineItemDiscount.fromJson(e as Map)) + ?.map((e) => + OrderLineItemAppliedDiscount.fromJson(e as Map)) .toList(), appliedTaxes: (json['applied_taxes'] as List?) - ?.map((e) => OrderLineItemTax.fromJson(e as Map)) + ?.map((e) => + OrderLineItemAppliedTax.fromJson(e as Map)) .toList(), basePriceMoney: json['base_price_money'] == null ? null diff --git a/lib/src/shared_model/order_line_item_applied_discount.dart b/lib/src/shared_model/order_line_item_applied_discount.dart new file mode 100644 index 0000000..057006f --- /dev/null +++ b/lib/src/shared_model/order_line_item_applied_discount.dart @@ -0,0 +1,28 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'order_line_item_applied_discount.g.dart'; + +@JsonSerializable() +class OrderLineItemAppliedDiscount extends Equatable { + const OrderLineItemAppliedDiscount({ + required this.discountUid, + this.uid, + this.appliedMoney, + }); + + /// Converts a [Map]<[String], [dynamic]> to a [OrderLineItemAppliedDiscount] + factory OrderLineItemAppliedDiscount.fromJson(Map json) => + _$OrderLineItemAppliedDiscountFromJson(json); + + /// Converts a [OrderLineItemAppliedDiscount] to a [Map]<[String], [dynamic]> + Map toJson() => _$OrderLineItemAppliedDiscountToJson(this); + + final String? uid; + final String discountUid; + final Money? appliedMoney; + + @override + List get props => [uid, discountUid, appliedMoney]; +} diff --git a/lib/src/shared_model/order_line_item_applied_discount.g.dart b/lib/src/shared_model/order_line_item_applied_discount.g.dart new file mode 100644 index 0000000..17ac80c --- /dev/null +++ b/lib/src/shared_model/order_line_item_applied_discount.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'order_line_item_applied_discount.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +OrderLineItemAppliedDiscount _$OrderLineItemAppliedDiscountFromJson( + Map json) => + OrderLineItemAppliedDiscount( + discountUid: json['discount_uid'] as String, + uid: json['uid'] as String?, + appliedMoney: json['applied_money'] == null + ? null + : Money.fromJson(json['applied_money'] as Map), + ); + +Map _$OrderLineItemAppliedDiscountToJson( + OrderLineItemAppliedDiscount instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('uid', instance.uid); + val['discount_uid'] = instance.discountUid; + writeNotNull('applied_money', instance.appliedMoney?.toJson()); + return val; +} diff --git a/lib/src/shared_model/order_line_item_applied_tax.dart b/lib/src/shared_model/order_line_item_applied_tax.dart new file mode 100644 index 0000000..ffdb1f9 --- /dev/null +++ b/lib/src/shared_model/order_line_item_applied_tax.dart @@ -0,0 +1,28 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'order_line_item_applied_tax.g.dart'; + +@JsonSerializable() +class OrderLineItemAppliedTax extends Equatable { + const OrderLineItemAppliedTax({ + required this.taxUid, + this.uid, + this.appliedMoney, + }); + + /// Converts a [Map] to an [OrderLineItemAppliedTax] + factory OrderLineItemAppliedTax.fromJson(Map json) => + _$OrderLineItemAppliedTaxFromJson(json); + + /// Converts a [OrderLineItemAppliedTax] to a [Map] + Map toJson() => _$OrderLineItemAppliedTaxToJson(this); + + final String? uid; + final String taxUid; + final Money? appliedMoney; + + @override + List get props => [uid, taxUid, appliedMoney]; +} diff --git a/lib/src/shared_model/order_line_item_applied_tax.g.dart b/lib/src/shared_model/order_line_item_applied_tax.g.dart new file mode 100644 index 0000000..af502db --- /dev/null +++ b/lib/src/shared_model/order_line_item_applied_tax.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'order_line_item_applied_tax.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +OrderLineItemAppliedTax _$OrderLineItemAppliedTaxFromJson( + Map json) => + OrderLineItemAppliedTax( + taxUid: json['tax_uid'] as String, + uid: json['uid'] as String?, + appliedMoney: json['applied_money'] == null + ? null + : Money.fromJson(json['applied_money'] as Map), + ); + +Map _$OrderLineItemAppliedTaxToJson( + OrderLineItemAppliedTax instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('uid', instance.uid); + val['tax_uid'] = instance.taxUid; + writeNotNull('applied_money', instance.appliedMoney?.toJson()); + return val; +} diff --git a/lib/src/shared_model/shared_model.dart b/lib/src/shared_model/shared_model.dart index 63edcc8..ed016ee 100644 --- a/lib/src/shared_model/shared_model.dart +++ b/lib/src/shared_model/shared_model.dart @@ -181,6 +181,8 @@ export 'order_fulfillment_shipment_details.dart'; export 'order_fulfillment_state.dart'; export 'order_fulfillment_type.dart'; export 'order_line_item.dart'; +export 'order_line_item_applied_discount.dart'; +export 'order_line_item_applied_tax.dart'; export 'order_line_item_discount.dart'; export 'order_line_item_discount_scope.dart'; export 'order_line_item_discount_type.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 8dda785..6ed6e7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: square_connect description: A wrapper for the Square Connect APIs. It's intended use is in a flutter application to manage inventory, catalog, customers, labor, and more on the Square platform. -version: 2.1.0 +version: 2.1.1 homepage: https://github.com/mtwichel/square-connect-flutter-library environment: