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

Invoquez le guichet de paiement de CinetPay, effectuez un paiement et attendez le statut du paiement initié à la seconde près après la fin du paiement.

example/example.md

import 'dart:async';
import 'dart:math';
import 'package:cinetpay/cinetpay.dart';
import 'package:flutter/material.dart';
import 'package:get/get.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) {
    final String title = 'CinetPay Demo';
    return GetMaterialApp(
      title: title,
      theme: ThemeData(
        primarySwatch: Colors.green,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
          appBar: AppBar(
              title: Text(title),
            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) {
                              // Mettre une alerte
                              return;
                            }
                            double _amount;
                            try {
                              _amount = double.parse(amount);

                              if (_amount < 100) {
                                // Mettre une alerte
                                return;
                              }

                              if (_amount > 1500000) {
                                // Mettre une alerte
                                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: 'Payment Checkout',
                              titleStyle: TextStyle(
                                  fontSize: 30,
                                  fontWeight: FontWeight.bold
                              ),
                              titleBackgroundColor: Colors.green,
                              configData: <String, dynamic> {
                                'apikey': 'API_KEY',
                                'site_id': SITE_ID,
                                'notify_url': 'NOTIFY_URL'
                              },
                              paymentData: <String, dynamic> {
                                'transaction_id': transactionId,
                                'amount': _amount,
                                'currency': 'XOF',
                                'channels': 'ALL',
                                'description': 'Payment test',
                              },
                              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();
                                  });
                                }
                              },
                            ));
                          },
                        )
                      ],
                    ),
                  ],
                )
              )
          )
      ),
    );
  }
}
31
likes
140
pub points
95%
popularity

Publisher

unverified uploader

Invoquez le guichet de paiement de CinetPay, effectuez un paiement et attendez le statut du paiement initié à la seconde près après la fin du paiement.

Homepage

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_inappwebview

More

Packages that depend on cinetpay