flutter_paymentez 0.0.11 copy "flutter_paymentez: ^0.0.11" to clipboard
flutter_paymentez: ^0.0.11 copied to clipboard

A new Flutter plugin to add credit cards using Android and iOS Paymentez SDK

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_paymentez/flutter_paymentez.dart';
import 'package:flutter_paymentez/models/addCardResponse.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  String _platformVersion = 'Unknown';

  final FlutterPaymentez _pymntz = FlutterPaymentez();

  TextEditingController _nameTextController = TextEditingController();
  TextEditingController _cardTextController = TextEditingController();
  TextEditingController _dateTextController = TextEditingController();
  TextEditingController _cvcTextController = TextEditingController();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterPaymentez.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Form(
            key: _formKey,
            child: Column(
              children: <Widget>[
                TextFormField(
                  controller: _nameTextController,
                  decoration: InputDecoration(
                      hintText: "Nombre Tarjeta",
                      icon: Icon(Icons.person),
                      border: InputBorder.none),
                  //obscureText: true,
                  validator: (value) {
                    if (value.isEmpty) {
                      return "Campo obligatorio";
                    }
                    /*else if (value.length < 6) {
                  return "the password has to be at least 6 characters long";
                }*/
                    return null;
                  },
                ),
                TextFormField(
                  inputFormatters: <TextInputFormatter>[
                    LengthLimitingTextInputFormatter(16),
                    WhitelistingTextInputFormatter.digitsOnly,
                    BlacklistingTextInputFormatter.singleLineFormatter
                  ],
                  controller: _cardTextController,
                  decoration: InputDecoration(
                      hintText: "Numero Tarjeta",
                      icon: Icon(Icons.credit_card),
                      border: InputBorder.none),
                  //obscureText: true,
                  validator: (value) {
                    if (value.isEmpty) {
                      return "Campo obligatorio";
                    }
                    /*else if (value.length < 6) {
                  return "the password has to be at least 6 characters long";
                }*/
                    return null;
                  },
                ),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: TextFormField(
                        inputFormatters: <TextInputFormatter>[
                          LengthLimitingTextInputFormatter(4),
                          WhitelistingTextInputFormatter.digitsOnly,
                          BlacklistingTextInputFormatter.singleLineFormatter
                        ],
                        controller: _dateTextController,
                        decoration: InputDecoration(
                            hintText: "Fecha Expiración",
                            icon: Icon(Icons.calendar_today),
                            border: InputBorder.none),
                        //obscureText: true,
                        validator: (value) {
                          if (value.isEmpty) {
                            return "Campo obligatorio";
                          }
                          /*else if (value.length < 6) {
                    return "the password has to be at least 6 characters long";
                  }*/
                          return null;
                        },
                      ),
                    ),
                    Expanded(
                      child: TextFormField(
                        inputFormatters: <TextInputFormatter>[
                          LengthLimitingTextInputFormatter(4),
                          WhitelistingTextInputFormatter.digitsOnly,
                          BlacklistingTextInputFormatter.singleLineFormatter
                        ],
                        controller: _cvcTextController,
                        decoration: InputDecoration(
                            hintText: "Código Seguridad",
                            icon: Icon(Icons.security),
                            border: InputBorder.none),
                        //obscureText: true,
                        validator: (value) {
                          if (value.isEmpty) {
                            return "Campo obligatorio";
                          }
                          /*else if (value.length < 6) {
                    return "the password has to be at least 6 characters long";
                  }*/
                          return null;
                        },
                      ),
                    ),
                  ],
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Material(
                    borderRadius: BorderRadius.circular(5.0),
                    color: Color.fromRGBO(0, 40, 75, 1.0),
                    elevation: 0.0,
                    child: MaterialButton(
                      onPressed: () async {
                        if (_formKey.currentState.validate()) {
                          _addCard();
                        }
                        //SystemChannels.textInput.invokeMethod('TextInput.hide');
                        //handlePayment(_nameTextController.text, _cardTextController.text, _dateTextController.text, _cvcTextController.text);
                      },
                      //minWidth: MediaQuery.of(context).size.width,
                      child: Text(
                        "Agregar Tarjeta",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.white, fontWeight: FontWeight.bold),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          )

          /*Center(
          child: Text('Running on: $_platformVersion\n'),
        ),*/

          ),
    );
  }

  void _addCard() async{
    final AddCardResponseModel response = await _pymntz.addCard(
      uid: "5ebc4016e273541f141c0171",
      email: "cart@test.com",
      name: _nameTextController.text,
      cardNumber: _cardTextController.text,
      expiryMonth: _dateTextController.text.substring(0,2),
      expiryYear: _dateTextController.text.substring(2),
      cvc: _cvcTextController.text,
      clientAppCode: "LUNA-EC-CLIENT",
      clientAppKey: "A5hVU9YkNdqMQNrr2b76yKTLu6xbdt",
      /*clientAppCode: "Client_App_Code",
      clientAppKey: "Client_App_Key",*/
      isTestMode: true.toString(),
    );

    print("Respuesta desde plugin: "+ response.status +" "+ response.message);

    //Fluttertoast.showToast(msg: "Error al iniciar sesión :'(",backgroundColor: Colors.black, textColor: Colors.white);
  }
}
4
likes
30
pub points
13%
popularity

Publisher

unverified uploader

A new Flutter plugin to add credit cards using Android and iOS Paymentez SDK

Homepage

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_paymentez