From b2c77acca477ca31e0682701c613c24ca04e559d Mon Sep 17 00:00:00 2001 From: Marcus Twichel Date: Sat, 14 Oct 2023 21:35:18 -0600 Subject: [PATCH] feat: customer groups and segments --- CHANGELOG.md | 3 + .../create_customer_group.dart | 47 ++++ .../create_customer_group.g.dart | 57 +++++ .../functions_model/create_payment_link.dart | 2 +- .../delete_customer_group.dart | 19 ++ .../delete_customer_group.g.dart | 29 +++ lib/src/functions_model/functions_model.dart | 7 + .../functions_model/list_customer_groups.dart | 31 +++ .../list_customer_groups.g.dart | 35 +++ .../list_customer_segments.dart | 32 +++ .../list_customer_segments.g.dart | 35 +++ .../retrieve_customer_group.dart | 21 ++ .../retrieve_customer_group.g.dart | 33 +++ .../retrieve_customer_segment.dart | 22 ++ .../retrieve_customer_segment.g.dart | 33 +++ .../update_customer_group.dart | 43 ++++ .../update_customer_group.g.dart | 55 +++++ lib/src/shared_model/customer_group.dart | 50 +++++ lib/src/shared_model/customer_group.g.dart | 35 +++ lib/src/shared_model/customer_segment.dart | 50 +++++ lib/src/shared_model/customer_segment.g.dart | 35 +++ lib/src/shared_model/loyalty_program.dart | 2 +- lib/src/shared_model/shared_model.dart | 2 + lib/src/square_api_client.dart | 47 ++++ lib/src/square_api_client.g.dart | 212 ++++++++++++++++++ pubspec.yaml | 2 +- 26 files changed, 936 insertions(+), 3 deletions(-) create mode 100644 lib/src/functions_model/create_customer_group.dart create mode 100644 lib/src/functions_model/create_customer_group.g.dart create mode 100644 lib/src/functions_model/delete_customer_group.dart create mode 100644 lib/src/functions_model/delete_customer_group.g.dart create mode 100644 lib/src/functions_model/list_customer_groups.dart create mode 100644 lib/src/functions_model/list_customer_groups.g.dart create mode 100644 lib/src/functions_model/list_customer_segments.dart create mode 100644 lib/src/functions_model/list_customer_segments.g.dart create mode 100644 lib/src/functions_model/retrieve_customer_group.dart create mode 100644 lib/src/functions_model/retrieve_customer_group.g.dart create mode 100644 lib/src/functions_model/retrieve_customer_segment.dart create mode 100644 lib/src/functions_model/retrieve_customer_segment.g.dart create mode 100644 lib/src/functions_model/update_customer_group.dart create mode 100644 lib/src/functions_model/update_customer_group.g.dart create mode 100644 lib/src/shared_model/customer_group.dart create mode 100644 lib/src/shared_model/customer_group.g.dart create mode 100644 lib/src/shared_model/customer_segment.dart create mode 100644 lib/src/shared_model/customer_segment.g.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index a5ae5f9..c664934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### 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 diff --git a/lib/src/functions_model/create_customer_group.dart b/lib/src/functions_model/create_customer_group.dart new file mode 100644 index 0000000..0f15805 --- /dev/null +++ b/lib/src/functions_model/create_customer_group.dart @@ -0,0 +1,47 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'create_customer_group.g.dart'; + +@JsonSerializable() +class CreateCustomerGroupRequest extends Equatable { + const CreateCustomerGroupRequest({ + this.group, + this.idempotencyKey, + }); + + /// Converts a [Map] to an [CreateCustomerGroupRequest] + factory CreateCustomerGroupRequest.fromJson(Map json) => + _$CreateCustomerGroupRequestFromJson(json); + + /// Converts a [CreateCustomerGroupRequest] to a [Map] + Map toJson() => _$CreateCustomerGroupRequestToJson(this); + + /// The idempotency key for the request. + final String? idempotencyKey; + + /// The customer group to create. + final CustomerGroup? group; + + @override + List get props => [idempotencyKey, group]; +} + +@JsonSerializable() +class CreateCustomerGroupResponse extends SquareResponse { + const CreateCustomerGroupResponse({this.group, super.errors}); + + /// Converts a [Map] to an [CreateCustomerGroupResponse] + factory CreateCustomerGroupResponse.fromJson(Map json) => + _$CreateCustomerGroupResponseFromJson(json); + + /// Converts a [CreateCustomerGroupResponse] to a [Map] + Map toJson() => _$CreateCustomerGroupResponseToJson(this); + + /// The successfully created customer group. + final CustomerGroup? group; + + @override + List get props => [group, errors]; +} diff --git a/lib/src/functions_model/create_customer_group.g.dart b/lib/src/functions_model/create_customer_group.g.dart new file mode 100644 index 0000000..6448c18 --- /dev/null +++ b/lib/src/functions_model/create_customer_group.g.dart @@ -0,0 +1,57 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'create_customer_group.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CreateCustomerGroupRequest _$CreateCustomerGroupRequestFromJson( + Map json) => + CreateCustomerGroupRequest( + group: json['group'] == null + ? null + : CustomerGroup.fromJson(json['group'] as Map), + idempotencyKey: json['idempotency_key'] as String?, + ); + +Map _$CreateCustomerGroupRequestToJson( + CreateCustomerGroupRequest instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('idempotency_key', instance.idempotencyKey); + writeNotNull('group', instance.group?.toJson()); + return val; +} + +CreateCustomerGroupResponse _$CreateCustomerGroupResponseFromJson( + Map json) => + CreateCustomerGroupResponse( + group: json['group'] == null + ? null + : CustomerGroup.fromJson(json['group'] as Map), + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$CreateCustomerGroupResponseToJson( + CreateCustomerGroupResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + writeNotNull('group', instance.group?.toJson()); + return val; +} diff --git a/lib/src/functions_model/create_payment_link.dart b/lib/src/functions_model/create_payment_link.dart index b168a47..4d2d5db 100644 --- a/lib/src/functions_model/create_payment_link.dart +++ b/lib/src/functions_model/create_payment_link.dart @@ -39,7 +39,7 @@ class CreatePaymentLinkRequest extends Equatable { order, checkoutOptions, prePopulatedData, - paymentNote + paymentNote, ]; } diff --git a/lib/src/functions_model/delete_customer_group.dart b/lib/src/functions_model/delete_customer_group.dart new file mode 100644 index 0000000..a0a6a1a --- /dev/null +++ b/lib/src/functions_model/delete_customer_group.dart @@ -0,0 +1,19 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'delete_customer_group.g.dart'; + +@JsonSerializable() +class DeleteCustomerGroupResponse extends SquareResponse { + const DeleteCustomerGroupResponse({super.errors}); + + /// Converts a [Map] to an [DeleteCustomerGroupResponse] + factory DeleteCustomerGroupResponse.fromJson(Map json) => + _$DeleteCustomerGroupResponseFromJson(json); + + /// Converts a [DeleteCustomerGroupResponse] to a [Map] + Map toJson() => _$DeleteCustomerGroupResponseToJson(this); + + @override + List get props => [errors]; +} diff --git a/lib/src/functions_model/delete_customer_group.g.dart b/lib/src/functions_model/delete_customer_group.g.dart new file mode 100644 index 0000000..fd31aac --- /dev/null +++ b/lib/src/functions_model/delete_customer_group.g.dart @@ -0,0 +1,29 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'delete_customer_group.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +DeleteCustomerGroupResponse _$DeleteCustomerGroupResponseFromJson( + Map json) => + DeleteCustomerGroupResponse( + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$DeleteCustomerGroupResponseToJson( + DeleteCustomerGroupResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + return val; +} diff --git a/lib/src/functions_model/functions_model.dart b/lib/src/functions_model/functions_model.dart index 01c91ed..bb4c406 100644 --- a/lib/src/functions_model/functions_model.dart +++ b/lib/src/functions_model/functions_model.dart @@ -10,6 +10,7 @@ export 'clone_order.dart'; export 'create_card.dart'; export 'create_checkout.dart'; export 'create_customer.dart'; +export 'create_customer_group.dart'; export 'create_gift_card.dart'; export 'create_gift_card_activity.dart'; export 'create_invoice.dart'; @@ -21,6 +22,7 @@ export 'create_payment.dart'; export 'create_payment_link.dart'; export 'create_subscription.dart'; export 'delete_customer.dart'; +export 'delete_customer_group.dart'; export 'delete_invoice.dart'; export 'delete_loyalty_reward.dart'; export 'delete_subscription_action.dart'; @@ -29,6 +31,8 @@ export 'get_invoice.dart'; export 'link_customer_to_gift_card.dart'; export 'list_cards.dart'; export 'list_catalog.dart'; +export 'list_customer_groups.dart'; +export 'list_customer_segments.dart'; export 'list_customers.dart'; export 'list_gift_cards.dart'; export 'list_invoices.dart'; @@ -45,6 +49,8 @@ export 'resume_subscription.dart'; export 'retrieve_card.dart'; export 'retrieve_catalog_objects.dart'; export 'retrieve_customer.dart'; +export 'retrieve_customer_group.dart'; +export 'retrieve_customer_segment.dart'; export 'retrieve_gift_card.dart'; export 'retrieve_gift_card_from_gan.dart'; export 'retrieve_gift_card_from_nonce.dart'; @@ -67,6 +73,7 @@ export 'search_subscriptions.dart'; export 'swap_plan.dart'; export 'unlink_customer_from_gift_card.dart'; export 'update_customer.dart'; +export 'update_customer_group.dart'; export 'update_invoice.dart'; export 'update_location.dart'; export 'update_order.dart'; diff --git a/lib/src/functions_model/list_customer_groups.dart b/lib/src/functions_model/list_customer_groups.dart new file mode 100644 index 0000000..225618b --- /dev/null +++ b/lib/src/functions_model/list_customer_groups.dart @@ -0,0 +1,31 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'list_customer_groups.g.dart'; + +@JsonSerializable() +class ListCustomerGroupsResponse extends SquareResponse { + const ListCustomerGroupsResponse({ + this.groups, + this.cursor, + super.errors, + }); + + /// Converts a [Map] to an [ListCustomerGroupsResponse] + factory ListCustomerGroupsResponse.fromJson(Map json) => + _$ListCustomerGroupsResponseFromJson(json); + + /// Converts a [ListCustomerGroupsResponse] to a [Map] + Map toJson() => _$ListCustomerGroupsResponseToJson(this); + + /// A list of customer groups belonging to the current seller. + final List? groups; + + /// A pagination cursor to retrieve the next set of results for your + /// original query to the endpoint. This value is present only if the + /// request succeeded and additional results are available. + final String? cursor; + + @override + List get props => [groups, cursor, errors]; +} diff --git a/lib/src/functions_model/list_customer_groups.g.dart b/lib/src/functions_model/list_customer_groups.g.dart new file mode 100644 index 0000000..1deb69b --- /dev/null +++ b/lib/src/functions_model/list_customer_groups.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'list_customer_groups.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ListCustomerGroupsResponse _$ListCustomerGroupsResponseFromJson( + Map json) => + ListCustomerGroupsResponse( + groups: (json['groups'] as List?) + ?.map((e) => CustomerGroup.fromJson(e as Map)) + .toList(), + cursor: json['cursor'] as String?, + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$ListCustomerGroupsResponseToJson( + ListCustomerGroupsResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + writeNotNull('groups', instance.groups?.map((e) => e.toJson()).toList()); + writeNotNull('cursor', instance.cursor); + return val; +} diff --git a/lib/src/functions_model/list_customer_segments.dart b/lib/src/functions_model/list_customer_segments.dart new file mode 100644 index 0000000..279d25c --- /dev/null +++ b/lib/src/functions_model/list_customer_segments.dart @@ -0,0 +1,32 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'list_customer_segments.g.dart'; + +@JsonSerializable() +class ListCustomerSegmentsResponse extends SquareResponse { + const ListCustomerSegmentsResponse({ + this.segments, + this.cursor, + super.errors, + }); + + /// Converts a [Map] to an [ListCustomerSegmentsResponse] + factory ListCustomerSegmentsResponse.fromJson(Map json) => + _$ListCustomerSegmentsResponseFromJson(json); + + /// Converts a [ListCustomerSegmentsResponse] to a [Map] + Map toJson() => _$ListCustomerSegmentsResponseToJson(this); + + /// The list of customer segments belonging to the associated Square account. + final List? segments; + + /// A pagination cursor to be used in subsequent calls to + /// ListCustomerSegments to retrieve the next set of query results. The cursor + /// is only present if the request succeeded and additional results are + /// available. + final String? cursor; + + @override + List get props => [segments, cursor, errors]; +} diff --git a/lib/src/functions_model/list_customer_segments.g.dart b/lib/src/functions_model/list_customer_segments.g.dart new file mode 100644 index 0000000..59559d3 --- /dev/null +++ b/lib/src/functions_model/list_customer_segments.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'list_customer_segments.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ListCustomerSegmentsResponse _$ListCustomerSegmentsResponseFromJson( + Map json) => + ListCustomerSegmentsResponse( + segments: (json['segments'] as List?) + ?.map((e) => CustomerSegment.fromJson(e as Map)) + .toList(), + cursor: json['cursor'] as String?, + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$ListCustomerSegmentsResponseToJson( + ListCustomerSegmentsResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + writeNotNull('segments', instance.segments?.map((e) => e.toJson()).toList()); + writeNotNull('cursor', instance.cursor); + return val; +} diff --git a/lib/src/functions_model/retrieve_customer_group.dart b/lib/src/functions_model/retrieve_customer_group.dart new file mode 100644 index 0000000..079a52d --- /dev/null +++ b/lib/src/functions_model/retrieve_customer_group.dart @@ -0,0 +1,21 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'retrieve_customer_group.g.dart'; + +@JsonSerializable() +class RetrieveCustomerGroupResponse extends SquareResponse { + const RetrieveCustomerGroupResponse({this.group, super.errors}); + + /// Converts a [Map] to an [RetrieveCustomerGroupResponse] + factory RetrieveCustomerGroupResponse.fromJson(Map json) => + _$RetrieveCustomerGroupResponseFromJson(json); + + /// Converts a [RetrieveCustomerGroupResponse] to a [Map] + Map toJson() => _$RetrieveCustomerGroupResponseToJson(this); + + final CustomerGroup? group; + + @override + List get props => [group, errors]; +} diff --git a/lib/src/functions_model/retrieve_customer_group.g.dart b/lib/src/functions_model/retrieve_customer_group.g.dart new file mode 100644 index 0000000..169816f --- /dev/null +++ b/lib/src/functions_model/retrieve_customer_group.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'retrieve_customer_group.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +RetrieveCustomerGroupResponse _$RetrieveCustomerGroupResponseFromJson( + Map json) => + RetrieveCustomerGroupResponse( + group: json['group'] == null + ? null + : CustomerGroup.fromJson(json['group'] as Map), + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$RetrieveCustomerGroupResponseToJson( + RetrieveCustomerGroupResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + writeNotNull('group', instance.group?.toJson()); + return val; +} diff --git a/lib/src/functions_model/retrieve_customer_segment.dart b/lib/src/functions_model/retrieve_customer_segment.dart new file mode 100644 index 0000000..9be0838 --- /dev/null +++ b/lib/src/functions_model/retrieve_customer_segment.dart @@ -0,0 +1,22 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'retrieve_customer_segment.g.dart'; + +@JsonSerializable() +class RetrieveCustomerSegmentResponse extends SquareResponse { + const RetrieveCustomerSegmentResponse({this.segment, super.errors}); + + /// Converts a [Map] to an [RetrieveCustomerSegmentResponse] + factory RetrieveCustomerSegmentResponse.fromJson(Map json) => + _$RetrieveCustomerSegmentResponseFromJson(json); + + /// Converts a [RetrieveCustomerSegmentResponse] to a [Map] + Map toJson() => + _$RetrieveCustomerSegmentResponseToJson(this); + + final CustomerSegment? segment; + + @override + List get props => [segment, errors]; +} diff --git a/lib/src/functions_model/retrieve_customer_segment.g.dart b/lib/src/functions_model/retrieve_customer_segment.g.dart new file mode 100644 index 0000000..abc2dda --- /dev/null +++ b/lib/src/functions_model/retrieve_customer_segment.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'retrieve_customer_segment.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +RetrieveCustomerSegmentResponse _$RetrieveCustomerSegmentResponseFromJson( + Map json) => + RetrieveCustomerSegmentResponse( + segment: json['segment'] == null + ? null + : CustomerSegment.fromJson(json['segment'] as Map), + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$RetrieveCustomerSegmentResponseToJson( + RetrieveCustomerSegmentResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + writeNotNull('segment', instance.segment?.toJson()); + return val; +} diff --git a/lib/src/functions_model/update_customer_group.dart b/lib/src/functions_model/update_customer_group.dart new file mode 100644 index 0000000..bc04ac3 --- /dev/null +++ b/lib/src/functions_model/update_customer_group.dart @@ -0,0 +1,43 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:square_connect/square_connect.dart'; + +part 'update_customer_group.g.dart'; + +@JsonSerializable() +class UpdateCustomerGroupRequest extends Equatable { + const UpdateCustomerGroupRequest({ + this.group, + }); + + /// Converts a [Map] to an [UpdateCustomerGroupRequest] + factory UpdateCustomerGroupRequest.fromJson(Map json) => + _$UpdateCustomerGroupRequestFromJson(json); + + /// Converts a [UpdateCustomerGroupRequest] to a [Map] + Map toJson() => _$UpdateCustomerGroupRequestToJson(this); + + /// The CustomerGroup object including all the updates you want to make. + final CustomerGroup? group; + + @override + List get props => [group]; +} + +@JsonSerializable() +class UpdateCustomerGroupResponse extends SquareResponse { + const UpdateCustomerGroupResponse({this.group, super.errors}); + + /// Converts a [Map] to an [UpdateCustomerGroupResponse] + factory UpdateCustomerGroupResponse.fromJson(Map json) => + _$UpdateCustomerGroupResponseFromJson(json); + + /// Converts a [UpdateCustomerGroupResponse] to a [Map] + Map toJson() => _$UpdateCustomerGroupResponseToJson(this); + + /// The successfully updated customer group. + final CustomerGroup? group; + + @override + List get props => [group, errors]; +} diff --git a/lib/src/functions_model/update_customer_group.g.dart b/lib/src/functions_model/update_customer_group.g.dart new file mode 100644 index 0000000..7b1165b --- /dev/null +++ b/lib/src/functions_model/update_customer_group.g.dart @@ -0,0 +1,55 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'update_customer_group.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UpdateCustomerGroupRequest _$UpdateCustomerGroupRequestFromJson( + Map json) => + UpdateCustomerGroupRequest( + group: json['group'] == null + ? null + : CustomerGroup.fromJson(json['group'] as Map), + ); + +Map _$UpdateCustomerGroupRequestToJson( + UpdateCustomerGroupRequest instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('group', instance.group?.toJson()); + return val; +} + +UpdateCustomerGroupResponse _$UpdateCustomerGroupResponseFromJson( + Map json) => + UpdateCustomerGroupResponse( + group: json['group'] == null + ? null + : CustomerGroup.fromJson(json['group'] as Map), + errors: (json['errors'] as List?) + ?.map((e) => SquareError.fromJson(e as Map)) + .toList(), + ); + +Map _$UpdateCustomerGroupResponseToJson( + UpdateCustomerGroupResponse instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('errors', instance.errors?.map((e) => e.toJson()).toList()); + writeNotNull('group', instance.group?.toJson()); + return val; +} diff --git a/lib/src/shared_model/customer_group.dart b/lib/src/shared_model/customer_group.dart new file mode 100644 index 0000000..e012ca6 --- /dev/null +++ b/lib/src/shared_model/customer_group.dart @@ -0,0 +1,50 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'customer_group.g.dart'; + +@JsonSerializable() +class CustomerGroup extends Equatable { + const CustomerGroup({ + this.id, + this.name, + this.createdAt, + this.updatedAt, + }); + + /// Converts a [Map]<[String], [dynamic]> to a [CustomerGroup] + factory CustomerGroup.fromJson(Map json) => + _$CustomerGroupFromJson(json); + + /// Converts a [CustomerGroup] to a [Map]<[String], [dynamic]> + Map toJson() => _$CustomerGroupToJson(this); + + /// **Read only** A unique Square-generated ID for the customer group. + final String? id; + + /// The name of the customer group. + final String? name; + + /// **Read only** The timestamp when the customer group was created, in + /// RFC 3339 format. + /// + /// Examples for January 25th, 2020 6:25:34pm Pacific Standard Time: + /// + /// UTC: 2020-01-26T02:25:34Z + /// + /// Pacific Standard Time with UTC offset: 2020-01-25T18:25:34-08:00 + final DateTime? createdAt; + + /// **Read only** The timestamp when the customer group was last updated, + /// in RFC 3339 format. + /// + /// Examples for January 25th, 2020 6:25:34pm Pacific Standard Time: + /// + /// UTC: 2020-01-26T02:25:34Z + /// + /// Pacific Standard Time with UTC offset: 2020-01-25T18:25:34-08:00 + final DateTime? updatedAt; + + @override + List get props => [id, name, createdAt, updatedAt]; +} diff --git a/lib/src/shared_model/customer_group.g.dart b/lib/src/shared_model/customer_group.g.dart new file mode 100644 index 0000000..9ddfc32 --- /dev/null +++ b/lib/src/shared_model/customer_group.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'customer_group.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CustomerGroup _$CustomerGroupFromJson(Map json) => + CustomerGroup( + id: json['id'] as String?, + name: json['name'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + ); + +Map _$CustomerGroupToJson(CustomerGroup instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + writeNotNull('name', instance.name); + writeNotNull('created_at', instance.createdAt?.toIso8601String()); + writeNotNull('updated_at', instance.updatedAt?.toIso8601String()); + return val; +} diff --git a/lib/src/shared_model/customer_segment.dart b/lib/src/shared_model/customer_segment.dart new file mode 100644 index 0000000..44dd678 --- /dev/null +++ b/lib/src/shared_model/customer_segment.dart @@ -0,0 +1,50 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'customer_segment.g.dart'; + +@JsonSerializable() +class CustomerSegment extends Equatable { + const CustomerSegment({ + this.id, + this.name, + this.createdAt, + this.updatedAt, + }); + + /// Converts a [Map]<[String], [dynamic]> to a [CustomerSegment] + factory CustomerSegment.fromJson(Map json) => + _$CustomerSegmentFromJson(json); + + /// Converts a [CustomerSegment] to a [Map]<[String], [dynamic]> + Map toJson() => _$CustomerSegmentToJson(this); + + /// **Read only** A unique Square-generated ID for the segment. + final String? id; + + /// The name of the segment. + final String? name; + + /// **Read only** The timestamp when the segment was created, in + /// RFC 3339 format. + /// + /// Examples for January 25th, 2020 6:25:34pm Pacific Standard Time: + /// + /// UTC: 2020-01-26T02:25:34Z + /// + /// Pacific Standard Time with UTC offset: 2020-01-25T18:25:34-08:00 + final DateTime? createdAt; + + /// **Read only** The timestamp when the segment was last updated, + /// in RFC 3339 format. + /// + /// Examples for January 25th, 2020 6:25:34pm Pacific Standard Time: + /// + /// UTC: 2020-01-26T02:25:34Z + /// + /// Pacific Standard Time with UTC offset: 2020-01-25T18:25:34-08:00 + final DateTime? updatedAt; + + @override + List get props => [id, name, createdAt, updatedAt]; +} diff --git a/lib/src/shared_model/customer_segment.g.dart b/lib/src/shared_model/customer_segment.g.dart new file mode 100644 index 0000000..a34f6eb --- /dev/null +++ b/lib/src/shared_model/customer_segment.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'customer_segment.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CustomerSegment _$CustomerSegmentFromJson(Map json) => + CustomerSegment( + id: json['id'] as String?, + name: json['name'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + ); + +Map _$CustomerSegmentToJson(CustomerSegment instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + writeNotNull('name', instance.name); + writeNotNull('created_at', instance.createdAt?.toIso8601String()); + writeNotNull('updated_at', instance.updatedAt?.toIso8601String()); + return val; +} diff --git a/lib/src/shared_model/loyalty_program.dart b/lib/src/shared_model/loyalty_program.dart index 4251e79..80c1e36 100644 --- a/lib/src/shared_model/loyalty_program.dart +++ b/lib/src/shared_model/loyalty_program.dart @@ -45,6 +45,6 @@ class LoyaltyProgram extends Equatable { terminology, updatedAt, expirationPolicy, - locationIds + locationIds, ]; } diff --git a/lib/src/shared_model/shared_model.dart b/lib/src/shared_model/shared_model.dart index 06c6c6b..63edcc8 100644 --- a/lib/src/shared_model/shared_model.dart +++ b/lib/src/shared_model/shared_model.dart @@ -64,9 +64,11 @@ export 'customer.dart'; export 'customer_creation_source.dart'; export 'customer_creation_source_filter.dart'; export 'customer_filter.dart'; +export 'customer_group.dart'; export 'customer_inclusion_exclusion.dart'; export 'customer_preferences.dart'; export 'customer_query.dart'; +export 'customer_segment.dart'; export 'customer_sort.dart'; export 'customer_sort_field.dart'; export 'customer_tax_ids.dart'; diff --git a/lib/src/square_api_client.dart b/lib/src/square_api_client.dart index e84440b..17924b8 100644 --- a/lib/src/square_api_client.dart +++ b/lib/src/square_api_client.dart @@ -635,4 +635,51 @@ abstract class SquareApiClient { @Path() required String invoiceId, @Body() required PublishInvoiceRequest body, }); + + /// Retrieves the list of customer groups of a business. + @GET('/v2/customers/groups') + Future listCustomerGroups({ + @Query('cursor') String? cursor, + @Query('limit') int? limit, + }); + + /// Creates a new customer group for a business. + /// The request must include the name value of the group. + @POST('/v2/customers/groups') + Future createCustomerGroup({ + @Body() required CreateCustomerGroupRequest body, + }); + + /// Deletes a customer group as identified by the group_id value. + @DELETE('/v2/customers/groups/{groupId}') + Future deleteCustomerGroup({ + @Path() required String groupId, + }); + + /// Retrieves a specific customer group as identified by the group_id value. + @GET('/v2/customers/groups/{groupId}') + Future retrieveCustomerGroup({ + @Path() required String groupId, + }); + + /// Updates a customer group as identified by the group_id value. + @PUT('/v2/customers/groups/{groupId}') + Future updateCustomerGroup({ + @Path() required String groupId, + @Body() required UpdateCustomerGroupRequest body, + }); + + /// Retrieves the list of customer segments of a business. + @GET('/v2/customers/segments') + Future listCustomerSegments({ + @Query('cursor') String? cursor, + @Query('limit') int? limit, + }); + + /// Retrieves a specific customer segment as identified by the segment_id + /// value. + @GET('/v2/customers/segments/{segmentId}') + Future retrieveCustomerSegment({ + @Path() required String segmentId, + }); } diff --git a/lib/src/square_api_client.g.dart b/lib/src/square_api_client.g.dart index 743ceae..15c42ca 100644 --- a/lib/src/square_api_client.g.dart +++ b/lib/src/square_api_client.g.dart @@ -2264,6 +2264,218 @@ class _SquareApiClient implements SquareApiClient { return value; } + @override + Future listCustomerGroups({ + String? cursor, + int? limit, + }) async { + const _extra = {}; + final queryParameters = { + r'cursor': cursor, + r'limit': limit, + }; + queryParameters.removeWhere((k, v) => v == null); + final _headers = {}; + final Map? _data = null; + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/groups', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = ListCustomerGroupsResponse.fromJson(_result.data!); + return value; + } + + @override + Future createCustomerGroup( + {required CreateCustomerGroupRequest body}) async { + const _extra = {}; + final queryParameters = {}; + final _headers = {}; + final _data = {}; + _data.addAll(body.toJson()); + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'POST', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/groups', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = CreateCustomerGroupRequest.fromJson(_result.data!); + return value; + } + + @override + Future deleteCustomerGroup( + {required String groupId}) async { + const _extra = {}; + final queryParameters = {}; + final _headers = {}; + final Map? _data = null; + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'DELETE', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/groups/${groupId}', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = DeleteCustomerGroupResponse.fromJson(_result.data!); + return value; + } + + @override + Future retrieveCustomerGroup( + {required String groupId}) async { + const _extra = {}; + final queryParameters = {}; + final _headers = {}; + final Map? _data = null; + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/groups/${groupId}', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = RetrieveCustomerGroupResponse.fromJson(_result.data!); + return value; + } + + @override + Future updateCustomerGroup({ + required String groupId, + required UpdateCustomerGroupRequest body, + }) async { + const _extra = {}; + final queryParameters = {}; + final _headers = {}; + final _data = {}; + _data.addAll(body.toJson()); + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'PUT', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/groups/${groupId}', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = UpdateCustomerGroupResponse.fromJson(_result.data!); + return value; + } + + @override + Future listCustomerSegments({ + String? cursor, + int? limit, + }) async { + const _extra = {}; + final queryParameters = { + r'cursor': cursor, + r'limit': limit, + }; + queryParameters.removeWhere((k, v) => v == null); + final _headers = {}; + final Map? _data = null; + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/segments', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = ListCustomerSegmentsResponse.fromJson(_result.data!); + return value; + } + + @override + Future retrieveCustomerSegment( + {required String segmentId}) async { + const _extra = {}; + final queryParameters = {}; + final _headers = {}; + final Map? _data = null; + final _result = await _dio.fetch>( + _setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/v2/customers/segments/${segmentId}', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + )))); + final value = RetrieveCustomerSegmentResponse.fromJson(_result.data!); + return value; + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes || diff --git a/pubspec.yaml b/pubspec.yaml index 3700cd0..8dda785 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.0.2 +version: 2.1.0 homepage: https://github.com/mtwichel/square-connect-flutter-library environment: