flutter_pay 0.9.0 flutter_pay: ^0.9.0 copied to clipboard
Flutter plugin that help you make payments through Apple and Google Pay
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_pay/flutter_pay.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
FlutterPay flutterPay = FlutterPay();
String result = "Result will be shown here";
@override
void initState() {
super.initState();
}
void makePayment() async {
List<PaymentItem> items = [
PaymentItem(name: "Маргарита 30 см", price: 30.0)
];
flutterPay.makePayment(
merchantIdentifier: "merchant.flutterpay.example",
currencyCode: "RUB",
countryCode: "RU",
paymentItems: items,
merchantName: "-",
gatewayName: "_");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Container(
padding: EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
this.result,
style: TextStyle(
fontSize: 16.0,
),
),
FlatButton(
child: Text("Can make payments?"),
onPressed: () async {
try {
bool result = await flutterPay.canMakePayments;
setState(() {
this.result = "Can make payments: $result";
});
} catch (e) {
setState(() {
this.result = "$e";
});
}
},
),
FlatButton(
child: Text("Can make payments with verified card: $result"),
onPressed: () async {
try {
bool result =
await flutterPay.canMakePaymentsWithActiveCard(
allowedPaymentNetworks: [
PaymentNetwork.visa,
PaymentNetwork.masterCard,
],
);
setState(() {
this.result = "$result";
});
} catch (e) {
setState(() {
this.result = "Error: $e";
});
}
},
),
FlatButton(
child: Text("Try to pay?"),
onPressed: () {
makePayment();
})
]),
),
),
);
}
}