-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/flutter-stripe/flutter_stripe…
… into web_deffered_payment # Conflicts: # packages/stripe/CHANGELOG.md # packages/stripe/pubspec.yaml # packages/stripe_js/CHANGELOG.md # packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.freezed.dart # packages/stripe_js/lib/src/js/elements/elements.dart # packages/stripe_js/pubspec.yaml # packages/stripe_platform_interface/CHANGELOG.md # packages/stripe_web/CHANGELOG.md # packages/stripe_web/lib/src/widgets/payment_element.dart # packages/stripe_web/pubspec.yaml
- Loading branch information
Showing
81 changed files
with
6,782 additions
and
2,069 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
80 changes: 80 additions & 0 deletions
80
example/lib/screens/payment_sheet/express_checkout/express_checkout_element.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,80 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:stripe_example/config.dart'; | ||
import 'package:stripe_example/widgets/loading_button.dart'; | ||
|
||
import 'platforms/express_checkout_element.dart' | ||
if (dart.library.js) 'platforms/express_checkout_element_web.dart'; | ||
|
||
class ExpressCheckoutElementExample extends StatefulWidget { | ||
@override | ||
_ThemeCardExampleState createState() => _ThemeCardExampleState(); | ||
} | ||
|
||
class _ThemeCardExampleState extends State<ExpressCheckoutElementExample> { | ||
String? clientSecret; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
getClientSecret(); | ||
} | ||
|
||
Future<void> getClientSecret() async { | ||
try { | ||
final client = await createPaymentIntent(); | ||
setState(() { | ||
clientSecret = client; | ||
}); | ||
} catch (e) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text( | ||
e.toString(), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Flutter App'), | ||
), | ||
body: Center( | ||
child: Container( | ||
constraints: BoxConstraints(maxWidth: 600), | ||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 52), | ||
child: Column( | ||
children: [ | ||
SizedBox( | ||
child: clientSecret != null | ||
? ExpressCheckoutWidget(clientSecret) | ||
: Center(child: CircularProgressIndicator())), | ||
LoadingButton(onPressed: pay, text: 'Pay'), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Future<String> createPaymentIntent() async { | ||
final url = Uri.parse('$kApiUrl/create-payment-intent'); | ||
final response = await http.post( | ||
url, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: json.encode({ | ||
'currency': 'usd', | ||
'amount': 5099, | ||
}), | ||
); | ||
return json.decode(response.body)['clientSecret']; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
example/lib/screens/payment_sheet/express_checkout/platforms/express_checkout_element.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,16 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
Future<void> pay() async { | ||
throw UnimplementedError(); | ||
} | ||
|
||
class ExpressCheckoutWidget extends StatelessWidget { | ||
const ExpressCheckoutWidget(this.clientSecret); | ||
|
||
final String? clientSecret; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...le/lib/screens/payment_sheet/express_checkout/platforms/express_checkout_element_web.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,31 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_stripe_web/flutter_stripe_web.dart'; | ||
import 'package:web/web.dart' as web; | ||
|
||
String getUrlPort() => web.window.location.port; | ||
|
||
String getReturnUrl() => web.window.location.href; | ||
|
||
Future<void> pay() async { | ||
await WebStripe.instance.confirmPaymentElement( | ||
ConfirmPaymentElementOptions( | ||
confirmParams: ConfirmPaymentParams(return_url: getReturnUrl()), | ||
), | ||
); | ||
} | ||
|
||
class ExpressCheckoutWidget extends StatelessWidget { | ||
const ExpressCheckoutWidget(this.clientSecret); | ||
|
||
final String? clientSecret; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ExpressCheckoutElement( | ||
onConfirm: (value) { | ||
pay(); | ||
}, | ||
clientSecret: clientSecret ?? '', | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
example/lib/screens/payment_sheet/payment_element/platforms/stripe_checkout_web.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
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
Oops, something went wrong.