mad_pay 1.0.0 copy "mad_pay: ^1.0.0" to clipboard
mad_pay: ^1.0.0 copied to clipboard

outdated

Mad Pay will help you make payments through Apple Pay and Google Pay

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:mad_pay/mad_pay.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final MadPay pay = MadPay();
  final List<PaymentItem> items = <PaymentItem>[
    PaymentItem(name: 'T-Shirt', price: 2.98),
    PaymentItem(name: 'Trousers', price: 15.24),
  ];

  String result = 'Result will be shown here';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(result),
              FlatButton(
                onPressed: () async {
                  try {
                    final bool req = await pay.checkPayments();
                    setState(() {
                      result = 'Can make payments: $req';
                    });
                  } catch (e) {
                    setState(() {
                      result = 'Error:\n$e';
                    });
                  }
                },
                child: const Text('Can make payments?'),
              ),
              FlatButton(
                onPressed: () async {
                  try {
                    final bool req = await pay.checkActiveCard(
                      paymentNetworks: <PaymentNetwork>[
                        PaymentNetwork.visa,
                        PaymentNetwork.mastercard,
                      ],
                    );
                    setState(() {
                      result = 'Can make payments with verified card: $req';
                    });
                  } catch (e) {
                    setState(() {
                      result = 'Error:\n$e';
                    });
                  }
                },
                child: const Text('Can make payments with verified card?'),
              ),
              FlatButton(
                onPressed: () async {
                  try {
                    final Map<String, String> req = await pay.processingPayment(
                      google: GoogleParameters(
                        gatewayName: 'example',
                        gatewayMerchantId: 'example_id',
                      ),
                      apple: AppleParameters(
                        merchantIdentifier: 'example_id',
                      ),
                      currencyCode: 'USD',
                      countryCode: 'US',
                      paymentItems: items,
                      paymentNetworks: <PaymentNetwork>[
                        PaymentNetwork.visa,
                        PaymentNetwork.mastercard,
                      ],
                    );
                    setState(() {
                      result = 'Try to pay:\n$req';
                    });
                  } catch (e) {
                    setState(() {
                      result = 'Error:\n$e';
                    });
                  }
                },
                child: const Text('Try to pay?'),
              )
            ],
          ),
        ),
      ),
    );
  }
}
72
likes
40
pub points
82%
popularity

Publisher

verified publishermadbrains.ru

Mad Pay will help you make payments through Apple Pay and Google Pay

Homepage
Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

flutter, protobuf

More

Packages that depend on mad_pay