Skip to content

Commit 4b08f02

Browse files
Make CustomerExpandableField inherit ExpandableObjectField
1 parent 7a6e6dc commit 4b08f02

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

lib/src/expanded/subscription_expanded.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,19 @@ class SubscriptionExpanded {
2323
) {
2424
List<Discount>? discounts;
2525
if (expand.contains(SubscriptionExpandableField.discounts)) {
26-
discounts = DiscountsExpandableField().extract(json);
26+
discounts = const DiscountsExpandableField().extract(json);
2727
}
2828

2929
InvoiceExpanded? latestInvoice;
3030
if (expand.contains(SubscriptionExpandableField.latestInvoice)) {
31-
latestInvoice = LatestInvoiceExpandedExpandableField(
31+
latestInvoice = const LatestInvoiceExpandedExpandableField(
3232
expand: {InvoiceExpandableField.paymentIntent},
3333
).extract(json);
3434
}
3535

3636
Customer? customer;
3737
if (expand.contains(SubscriptionExpandableField.customer)) {
38-
const customerExpander = CustomerExpandableField();
39-
customer = customerExpander.extract(json);
40-
41-
/// A shim so that Subscription gets parsed correctly
42-
json[customerExpander.field] = customer.id;
38+
customer = const CustomerExpandableField().extract(json);
4339
}
4440

4541
return SubscriptionExpanded(
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import 'package:stripe/messages.dart';
2-
import 'package:stripe/src/utils/expandable_field.dart';
2+
import 'package:stripe/src/utils/expandable_object_field.dart';
33

4-
class CustomerExpandableField extends ExpandableField<Customer> {
4+
class CustomerExpandableField extends ExpandableObjectField<Customer> {
55
@override
66
String get field => 'customer';
77

88
const CustomerExpandableField();
99

1010
@override
11-
Customer extract(Map<String, dynamic> json) => Customer.fromJson(json[field]);
11+
Customer parse(Map<String, dynamic> object) =>
12+
Customer.fromJson(object[field]);
13+
14+
@override
15+
String replacement(Customer parsedValue) => parsedValue.id;
1216
}

0 commit comments

Comments
 (0)