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

outdated

Effectuez vos paiements en ligne avec CinetPay.

example/example.md

import 'dart:async';
import 'dart:math';
import 'package:cinetpay/cinetpay.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:socket/Constants.dart';

Future main() async {
  runApp(new MyApp());
}

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

class _MyAppState extends State<MyApp> {
  TextEditingController amountController = new TextEditingController();
  Map<String, dynamic>? response;
  Color? color;
  IconData? icon;
  bool show = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'CinetPay Demo',
      theme: ThemeData(
        primarySwatch: Colors.green,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
          appBar: AppBar(
              title: Text("CinetPay Demo"),
            centerTitle: true,
          ),
          body: SafeArea(
              child: Center(
                child: ListView(
                  shrinkWrap: true,
                  children: [
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        show ? Icon(icon, color: color, size: 150) : Container(),
                        show ? SizedBox(height: 50.0) : Container(),
                        Text(
                          "Example integration Package for Flutter",
                          style: TextStyle(
                              fontSize: 30,
                              fontWeight: FontWeight.bold
                          ),
                          textAlign: TextAlign.center,
                        ),
                        SizedBox(height: 50.0),
                        Text(
                          "Cart informations.",
                          style: Theme.of(context).textTheme.headline4,
                        ),
                        SizedBox(height: 50.0),
                        new Container(
                          padding: EdgeInsets.symmetric(horizontal: 20.0),
                          margin: EdgeInsets.symmetric(horizontal: 50.0),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(12.0),
                            border: Border.all(color: Colors.green),
                          ),
                          child: new TextField(
                            controller: amountController,
                            decoration: InputDecoration(
                              hintText: "Amount",
                              border: InputBorder.none,
                            ),
                            keyboardType: TextInputType.number,
                          ),
                        ),
                        SizedBox(height: 40.0),
                        ElevatedButton(
                          child: Text("Pay with CinetPay"),
                          onPressed: () async {
                            String amount = amountController.text;
                            if(amount.isEmpty) {
                              return;
                            }
                            double _amount;
                            try {
                              _amount = double.parse(amount);

                              if (_amount < 100) {
                                return;
                              }

                              if (_amount > 1500000) {
                                return;
                              }
                            }

                            catch (exception) {
                              return;
                            }

                            amountController.clear();

                            final String transactionId = Random().nextInt(100000000).toString(); // Mettre en place un endpoint à contacter cêté serveur pour générer des ID unique dans votre BD

                            await Get.to(CinetPayCheckout(
                              title: 'Guichet de paiement',
                              configData: <String, dynamic> {
                                'apikey': Constants().API_KEY,
                                'site_id': Constants().SITE_ID,
                                'notify_url': Constants().NOTIFY_URL,
                                'mode':Constants().MODE
                              },
                              paymentData: <String, dynamic> {
                                'transaction_id': transactionId,
                                'amount': _amount,
                                'currency': 'XOF',
                                'channels': 'CREDIT_CARD',
                                'description': 'Test de paiement',
                              },
                              waitResponse: (data) {
                                if (mounted) {
                                  setState(() {
                                    response = data;
                                    print(response);
                                    icon = data['status'] == 'ACCEPTED' ? Icons.check_circle : Icons.mood_bad_rounded;
                                    color = data['status'] == 'ACCEPTED' ? Colors.green : Colors.redAccent;
                                    show = true;
                                    Get.back();
                                  });
                                }
                              },
                              onError: (data) {
                                if (mounted) {
                                  setState(() {
                                    response = data;
                                    print(response);
                                    icon = Icons.warning_rounded;
                                    color = Colors.yellowAccent;
                                    show = true;
                                    Get.back();
                                  });
                                }
                              },
                            ));
                          },
                        )
                      ],
                    ),
                  ],
                )
              )
          )
      ),
    );
  }
}
35
likes
0
pub points
95%
popularity

Publisher

unverified uploader

Effectuez vos paiements en ligne avec CinetPay.

Homepage

License

unknown (license)

Dependencies

flutter, flutter_inappwebview

More

Packages that depend on cinetpay