Skip to content

Commit b0a4c31

Browse files
Merge pull request #38 from solid-software/sources
Add customer/:id/sources resource partial models, list request
2 parents d1bf3c1 + 10ec5dc commit b0a4c31

8 files changed

Lines changed: 209 additions & 1 deletion

File tree

lib/messages.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ part 'src/messages/requests/update_subscription.dart';
5353
part 'src/messages/requests/update_subscription_item.dart';
5454
part 'src/messages/requests/update_subscription_schedule.dart';
5555
part 'src/messages/shipping_specification.dart';
56+
part 'src/messages/source.dart';
5657
part 'src/messages/stripe_api_error.dart';
5758
part 'src/messages/subscription.dart';
5859
part 'src/messages/subscription_item.dart';

lib/messages.g.dart

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/messages/enums.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export 'enums/payment_behavior.dart';
44
export 'enums/proration_behavior.dart';
55
export 'enums/stripe_api_error_type.dart';
66
export 'enums/pause_collection_behavior.dart';
7+
export 'enums/source_type.dart';
8+
export 'enums/source_status.dart';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
@Deprecated('''Stripe doesn't recommend using the deprecated Sources API.
4+
We recommend that you adopt the PaymentMethods API.
5+
This newer API provides access to our latest features and payment method types.
6+
''')
7+
enum SourceStatus {
8+
@JsonValue('canceled')
9+
canceled,
10+
@JsonValue('chargeable')
11+
chargeable,
12+
@JsonValue('consumed')
13+
consumed,
14+
@JsonValue('failed')
15+
failed,
16+
@JsonValue('pending')
17+
pending,
18+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
@Deprecated('''Stripe doesn't recommend using the deprecated Sources API.
4+
We recommend that you adopt the PaymentMethods API.
5+
This newer API provides access to our latest features and payment method types.
6+
''')
7+
enum SourceType {
8+
@JsonValue('ach_credit_transfer')
9+
achCreditTransfer,
10+
@JsonValue('ach_debit')
11+
achDebit,
12+
@JsonValue('alipay')
13+
alipay,
14+
@JsonValue('bancontact')
15+
bancontact,
16+
@JsonValue('card')
17+
card,
18+
@JsonValue('card_present')
19+
cardPresent,
20+
@JsonValue('eps')
21+
eps,
22+
@JsonValue('giropay')
23+
giropay,
24+
@JsonValue('ideal')
25+
ideal,
26+
@JsonValue('multibanco')
27+
multibanco,
28+
@JsonValue('klarna')
29+
klarna,
30+
@JsonValue('p24')
31+
p24,
32+
@JsonValue('sepa_debit')
33+
sepaDebit,
34+
@JsonValue('sofort')
35+
sofort,
36+
@JsonValue('three_d_secure')
37+
threeDSecure,
38+
@JsonValue('wechat')
39+
wechat,
40+
}

lib/src/messages/source.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
part of '../../messages.dart';
2+
3+
/// Source objects allow you to accept a variety of payment methods.
4+
/// They represent a customer’s payment instrument,
5+
/// and can be used with the Stripe API just like a Card object:
6+
/// once chargeable, they can be charged, or can be attached to customers.
7+
@Deprecated('''Stripe doesn't recommend using the deprecated Sources API.
8+
We recommend that you adopt the PaymentMethods API.
9+
This newer API provides access to our latest features and payment method types.
10+
''')
11+
@JsonSerializable()
12+
class Source extends Message {
13+
final String id;
14+
final String object;
15+
final int? amount;
16+
17+
@TimestampConverter()
18+
final DateTime created;
19+
final String? currency;
20+
final String? customer;
21+
final String? flow;
22+
final bool livemode;
23+
final String? statementDescriptor;
24+
final String status;
25+
final SourceType type;
26+
final String usage;
27+
28+
const Source({
29+
required this.id,
30+
required this.object,
31+
required this.amount,
32+
required this.created,
33+
required this.currency,
34+
required this.customer,
35+
required this.flow,
36+
required this.livemode,
37+
required this.statementDescriptor,
38+
required this.status,
39+
required this.type,
40+
required this.usage,
41+
});
42+
43+
factory Source.fromJson(Map<String, dynamic> json) => _$SourceFromJson(json);
44+
45+
@override
46+
Map<String, dynamic> toJson() => _$SourceToJson(this);
47+
}

lib/src/resources/customer.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import 'dart:async';
22

33
import 'package:stripe/messages.dart';
4+
import 'package:stripe/src/resources/source.dart';
45

56
import '../client.dart';
67
import '_resource.dart';
78

89
class CustomerResource extends Resource<Customer> {
9-
CustomerResource(Client client) : super(client);
10+
final Client _client;
11+
12+
CustomerResource(Client client)
13+
: _client = client,
14+
super(client);
1015

1116
Future<Customer> create(CreateCustomerRequest request) async {
1217
final response = await post('customers', data: request.toJson());
@@ -40,4 +45,12 @@ class CustomerResource extends Resource<Customer> {
4045

4146
return customer;
4247
}
48+
49+
@Deprecated('''Stripe doesn't recommend using the deprecated Sources API.
50+
We recommend that you adopt the PaymentMethods API.
51+
This newer API provides access to our latest features and payment method types.
52+
''')
53+
SourceResource sources(String customerId) {
54+
return SourceResource(_client, customerId);
55+
}
4356
}

lib/src/resources/source.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:async';
2+
3+
import 'package:stripe/messages.dart';
4+
5+
import '../client.dart';
6+
import '_resource.dart';
7+
8+
/// Source objects allow you to accept a variety of payment methods.
9+
/// They represent a customer’s payment instrument,
10+
/// and can be used with the Stripe API just like a Card object:
11+
/// once chargeable, they can be charged, or can be attached to customers.
12+
@Deprecated('''Stripe doesn't recommend using the deprecated Sources API.
13+
We recommend that you adopt the PaymentMethods API.
14+
This newer API provides access to our latest features and payment method types.
15+
''')
16+
class SourceResource extends Resource<Subscription> {
17+
final String customerId;
18+
19+
String get _resourcePath => 'customers/$customerId/sources';
20+
21+
SourceResource(Client client, this.customerId) : super(client);
22+
23+
Future<DataList<Source>> list() async {
24+
final map = await get(_resourcePath);
25+
return DataList<Source>.fromJson(
26+
map, (value) => Source.fromJson(value as Map<String, dynamic>));
27+
}
28+
}

0 commit comments

Comments
 (0)