flutter_stripe_basic 0.0.7 flutter_stripe_basic: ^0.0.7 copied to clipboard
A new flutter plugin project.
import 'package:flutter/material.dart';
import 'package:flutter_stripe_basic/flutter_stripe_basic.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _error;
ScrollController _controller = ScrollController();
final CreditCard testCard = CreditCard(
number: '4000002760003184',
expMonth: 12,
expYear: 21,
);
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
@override
initState() {
super.initState();
StripePayment.setOptions(StripeOptions(
publishableKey: "pk_test_aSaULNS8cJU6Tvo20VAXy6rp",
merchantId: "Test",
androidPayMode: 'test'));
}
void setError(dynamic error) {
_scaffoldKey.currentState
.showSnackBar(SnackBar(content: Text(error.toString())));
setState(() {
_error = error.toString();
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text('Plugin example app'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.clear),
onPressed: () {},
)
],
),
body: ListView(
controller: _controller,
padding: const EdgeInsets.all(20),
children: <Widget>[
RaisedButton(
child: Text("Create Token with Card"),
onPressed: () {
StripePayment.createTokenWithCard(
testCard,
).then((token) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text('Received ${token.tokenId}')));
}).catchError(setError);
},
),
Divider(),
RaisedButton(
child: Text("Basic Integration"),
onPressed: () {
StripePayment.openBasicIntent(
testCard,
).then((token) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text('Received ${token.tokenId}')));
}).catchError(setError);
},
),
Divider(),
Text('Current error: $_error'),
],
),
),
);
}
}