-
-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * add confirm setup * confirm setup * add confirm to api * wip * exports * wip * add_confirm_setup * changelog & versioning" * changelog and versioning * add example * fix return body of create setup * fix web example * fix example * fix comments * version --------- Co-authored-by: cedvandenbosch <[email protected]>
- Loading branch information
Showing
19 changed files
with
763 additions
and
257 deletions.
There are no files selected for viewing
239 changes: 0 additions & 239 deletions
239
example/lib/screens/others/setup_future_payment_screen.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
30 changes: 30 additions & 0 deletions
30
example/lib/screens/setup_future_payments/_create_setup_intent.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,30 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:stripe_example/config.dart'; | ||
|
||
typedef SetupKeys = ({ | ||
String clientSecret, | ||
String customerId, | ||
}); | ||
|
||
Future<SetupKeys> createSetupIntent() async { | ||
final url = Uri.parse('$kApiUrl/create-setup-intent'); | ||
final response = await http.post( | ||
url, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: json.encode({ | ||
'payment_method_types': ['card', 'sepa_debit'], | ||
}), | ||
); | ||
final body = json.decode(response.body); | ||
if (body['error'] != null) { | ||
throw Exception(body['error']); | ||
} | ||
return ( | ||
clientSecret: body['clientSecret'] as String, | ||
customerId: body['customerId'] as String | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
example/lib/screens/setup_future_payments/add_payment_method_button.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,42 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'add_payment_method_screen_loader.dart' | ||
if (dart.library.js) 'add_payment_method_screen_loader_web.dart' | ||
if (dart.library.io) 'add_payment_method_screen_loader_mobile.dart'; | ||
|
||
class AddPaymentMethodButton extends StatefulWidget { | ||
const AddPaymentMethodButton({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
State<AddPaymentMethodButton> createState() => _AddPaymentMethodButtonState(); | ||
} | ||
|
||
class _AddPaymentMethodButtonState extends State<AddPaymentMethodButton> { | ||
bool isLoading = false; | ||
|
||
void _onAddPaymentMethodPressed() async { | ||
setState(() => isLoading = true); | ||
try { | ||
AddPaymentMethodScreenLoader().display( | ||
context: context, | ||
); | ||
} finally { | ||
setState(() => isLoading = false); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListTile( | ||
leading: isLoading | ||
? SizedBox( | ||
height: 16, width: 16, child: const CircularProgressIndicator()) | ||
: const Icon(Icons.credit_card), | ||
title: Text('Add payment method'), | ||
trailing: const Icon(Icons.chevron_right), | ||
onTap: isLoading ? null : _onAddPaymentMethodPressed, | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
example/lib/screens/setup_future_payments/add_payment_method_screen_loader.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,11 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class AddPaymentMethodScreenLoader { | ||
const AddPaymentMethodScreenLoader(); | ||
|
||
Future<void> display({ | ||
required BuildContext context, | ||
}) { | ||
throw UnimplementedError(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
example/lib/screens/setup_future_payments/add_payment_method_screen_loader_abstract.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,8 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// abstract class so both mobile and web use the same constructor | ||
abstract class AddPaymentMethodScreenLoaderAbstract { | ||
const AddPaymentMethodScreenLoaderAbstract(); | ||
|
||
Future<void> display({required BuildContext context}); | ||
} |
Oops, something went wrong.