forked from enyo/stripe-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
subscription expansion
1 parent
62c3d03
commit ee7c46c
Showing
9 changed files
with
83 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:stripe/messages.dart'; | ||
|
||
class CustomerExpanded { | ||
final Customer customer; | ||
|
||
CustomerExpanded({ | ||
required this.customer, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,17 @@ | ||
import 'package:stripe/messages.dart'; | ||
import 'package:stripe/src/expanded.dart'; | ||
import 'package:stripe/src/utils/expandable_fields/customer_expandable_field.dart'; | ||
import 'package:stripe/src/utils/expandable_fields/discounts_expandable_field.dart'; | ||
import 'package:stripe/src/utils/expandable_fields/latest_invoice_expandable_field.dart'; | ||
import 'package:stripe/src/expanded/customer_expanded.dart'; | ||
|
||
class SubscriptionExpanded { | ||
final Subscription subscription; | ||
final List<Discount>? discounts; | ||
final InvoiceExpanded? latestInvoice; | ||
final Customer? customer; | ||
final CustomerExpanded? customer; | ||
|
||
SubscriptionExpanded({ | ||
required this.subscription, | ||
this.discounts, | ||
this.latestInvoice, | ||
this.customer, | ||
}); | ||
|
||
factory SubscriptionExpanded.fromJson( | ||
Map<String, dynamic> json, | ||
Set<SubscriptionExpandableField> expand, | ||
) { | ||
List<Discount>? discounts; | ||
if (expand.contains(SubscriptionExpandableField.discounts)) { | ||
discounts = const DiscountsExpandableField().extract(json); | ||
} | ||
|
||
InvoiceExpanded? latestInvoice; | ||
if (expand.contains(SubscriptionExpandableField.latestInvoice)) { | ||
latestInvoice = const LatestInvoiceExpandableField( | ||
|
||
).extract(json); | ||
} | ||
|
||
Customer? customer; | ||
if (expand.contains(SubscriptionExpandableField.customer)) { | ||
customer = const CustomerExpandableField().extract(json); | ||
} | ||
|
||
return SubscriptionExpanded( | ||
subscription: Subscription.fromJson(json), | ||
discounts: discounts, | ||
latestInvoice: latestInvoice, | ||
customer: customer, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
lib/src/messages/enums/expandable_fields/subscription_expandable_field.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
lib/src/utils/expandable_fields/customer_expandable_field.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import 'package:stripe/messages.dart'; | ||
import 'package:stripe/src/expanded/customer_expanded.dart'; | ||
import 'package:stripe/src/utils/expandable_object_field.dart'; | ||
|
||
class CustomerExpandableField extends ExpandableObjectField<Customer> { | ||
class CustomerExpandableField extends ExpandableObjectField<CustomerExpanded> { | ||
@override | ||
String get field => 'customer'; | ||
|
||
const CustomerExpandableField(); | ||
|
||
@override | ||
Customer parse(Map<String, dynamic> object) => Customer.fromJson(object); | ||
CustomerExpanded parse(Map<String, dynamic> object) => | ||
CustomerExpanded(customer: Customer.fromJson(object)); | ||
|
||
@override | ||
String replacement(Customer parsedValue) => parsedValue.id; | ||
String replacement(CustomerExpanded parsedValue) => parsedValue.customer.id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lib/src/utils/expandable_fields/subscription_expandable_field.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ignore_for_file: false | ||
import 'package:stripe/messages.dart'; | ||
import 'package:stripe/src/expanded/customer_expanded.dart'; | ||
import 'package:stripe/src/expanded/invoice_expanded.dart'; | ||
import 'package:stripe/src/expanded/subscription_expanded.dart'; | ||
import 'package:stripe/src/utils/expandable_fields/customer_expandable_field.dart'; | ||
import 'package:stripe/src/utils/expandable_fields/discounts_expandable_field.dart'; | ||
import 'package:stripe/src/utils/expandable_fields/latest_invoice_expandable_field.dart'; | ||
import 'package:stripe/src/utils/expandable_object_field.dart'; | ||
|
||
class SubscriptionExpandableField | ||
extends ExpandableObjectField<SubscriptionExpanded> { | ||
DiscountsExpandableField? discountsExpansion; | ||
LatestInvoiceExpandableField? latestInvoiceExpansion; | ||
CustomerExpandableField? customerExpansion; | ||
|
||
SubscriptionExpandableField({ | ||
this.discountsExpansion, | ||
this.latestInvoiceExpansion, | ||
this.customerExpansion, | ||
}); | ||
|
||
@override | ||
String get field => 'customer'; | ||
|
||
@override | ||
SubscriptionExpanded parse(Map<String, dynamic> object) { | ||
List<Discount>? discounts; | ||
if (discountsExpansion != null) { | ||
discounts = discountsExpansion!.extract(object); | ||
} | ||
|
||
InvoiceExpanded? latestInvoice; | ||
if (latestInvoiceExpansion != null) { | ||
latestInvoice = latestInvoiceExpansion!.extract(object); | ||
} | ||
|
||
CustomerExpanded? customer; | ||
if (customerExpansion != null) { | ||
customer = customerExpansion!.extract(object); | ||
} | ||
|
||
return SubscriptionExpanded( | ||
subscription: Subscription.fromJson(object), | ||
discounts: discounts, | ||
latestInvoice: latestInvoice, | ||
customer: customer, | ||
); | ||
} | ||
|
||
@override | ||
String replacement(SubscriptionExpanded parsedValue) => | ||
parsedValue.subscription.id; | ||
} |