peachpayments_flutter 1.5.1
peachpayments_flutter: ^1.5.1 copied to clipboard
Peach Payments SDK for Flutter — accept card and alternative payments in your Flutter app with a prebuilt, customisable payment sheet.
example/README.md
peachpayments_flutter example #
A complete runnable app lives in
apps/example
in this repository, together with a sample backend for creating payment intents.
Note that the native artefacts require extra repository setup before the example will build — see the package README.
import 'package:flutter/material.dart';
import 'package:peachpayments_flutter/peachpayments_flutter.dart';
class CheckoutPage extends StatefulWidget {
const CheckoutPage({super.key});
@override
State<CheckoutPage> createState() => _CheckoutPageState();
}
class _CheckoutPageState extends State<CheckoutPage> {
final _peach = PeachPayments();
Session? _session;
String _status = '';
Future<void> _start(String publishableKey, String clientSecret) async {
_peach.init(PeachPaymentsConfig(publishableKey: publishableKey));
try {
_session = await _peach.initPaymentSession(
PaymentMethodParams(
clientSecret: clientSecret,
configuration: Configuration(
merchantDisplayName: 'My Store',
primaryButtonLabel: 'Pay',
),
),
);
} on PeachPaymentsException catch (e) {
setState(() => _status = e.message);
}
}
Future<void> _pay() async {
final session = _session;
if (session == null) return;
final result = await _peach.presentPaymentSheet(session);
setState(() {
_status = switch (result.status) {
Status.completed => 'Payment complete',
Status.cancelled => 'Cancelled',
Status.failed => result.error.message,
};
});
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(onPressed: _pay, child: const Text('Pay')),
Text(_status),
],
);
}
}