simpay 0.0.7 copy "simpay: ^0.0.7" to clipboard
simpay: ^0.0.7 copied to clipboard

outdated

SDK para la integración con la API de Simpay

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:simpay/simpay.dart';
import './const.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  _MyApp createState() => _MyApp();
}

class _MyApp extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Simpay',
      home: Pay(),
    );
  }
}

class Pay extends StatefulWidget {
  const Pay({Key? key}) : super(key: key);

  @override
  State<Pay> createState() => _PayState();
}

class _PayState extends State<Pay> {
  final sdk = Simpay(
      commerceCode: commerceCode,
      apiKey: apikey,
      secretKey: secretkey,
      production: true);

  DataPayments data = DataPayments(
    amount: 0,
    order: "",
    subject: "",
  );

  String? dv = "";

  void getVersionDevice() async {
    String? d = await Simpay.platformVersion;
    setState(() => dv = d);
  }

  bool active = false;
  ResponsePayment response = ResponsePayment(
      success: false, order: '', url: '', session: '', amount: 0);
  ListPayments _methods = ListPayments(list: []);
  int num = 0;

  @override
  void initState() {
    super.initState();
    Timer.run(() {
      simpayInit();
      getVersionDevice();
    });
  }

  void simpayInit() async {
    sdk.getMethodsPayments().then((ListPayments payments) {
      setState(() => _methods = payments);
    });

    sdk.success.stream.listen((ResPayment res) {
      switch (res.status) {
        case StatusPayment.AUTHORIZED:
          print("Transacción exitosa");
          break;
        case StatusPayment.FAILED:
          print("Transacción Fallida");
          break;
        case StatusPayment.CANCEL:
          print("CANCEL BY USER");
          break;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Integración Simpay'),
        ),
        body: SingleChildScrollView(
            child: Column(
          children: [
            Container(
              padding: const EdgeInsets.all(20),
              child: Column(
                children: [
                  Column(children: [
                    TextField(
                      onChanged: (v) {
                        if (v.isEmpty) {
                          setState(() => num = 0);
                        } else {
                          setState(() => num = int.parse(v));
                        }

                        setState(() => active = false);
                      },
                      decoration:
                          const InputDecoration(labelText: "Ingresa un monto"),
                      keyboardType:
                          const TextInputType.numberWithOptions(decimal: true),
                      inputFormatters: [
                        FilteringTextInputFormatter.allow(RegExp('[0-9]'))
                      ],
                    ),
                    Container(
                      height: 20,
                    ),
                    Container(
                      margin: const EdgeInsets.symmetric(vertical: 15),
                      child: const Text("Formas de pago"),
                    ),
                    Column(
                        children: _methods.list.map((PaymentMethods e) {
                      return GestureDetector(
                        onTap: () {
                          data.order = "O-002322";
                          data.subject = "Flutter";
                          data.method = e.code;
                          data.amount = num;

                          sdk.configViewPay(title: e.name);

                          sdk.createPay(data).then((ResponsePayment value) {
                            setState(() {
                              response = value;
                              active = true;
                            });
                          });
                        },
                        child: Card(
                          child: Container(
                            padding: const EdgeInsets.all(15),
                            child: Row(
                              children: [
                                Text(e.name),
                                Expanded(
                                  child: Container(
                                    alignment: Alignment.bottomRight,
                                    child: const Icon(Icons.chevron_right),
                                  ),
                                )
                              ],
                            ),
                          ),
                        ),
                      );
                    }).toList()),
                    Container(
                      height: 60,
                    ),
                    ElevatedButton(
                      child: const Text("Pagar"),
                      onPressed: () {
                        if (active) sdk.getPay(context, response);
                      },
                      style: ElevatedButton.styleFrom(
                        primary: active ? Colors.black : Colors.grey,
                        minimumSize: const Size(250, 50),
                      ),
                    ),
                    Container(height: 10),
                    ElevatedButton(
                      child: const Text("Conectar"),
                      onPressed: () => sdk.openConnect(),
                      style: ElevatedButton.styleFrom(
                        primary: Colors.lightBlue,
                        minimumSize: const Size(250, 50),
                      ),
                    ),
                    Container(height: 10),
                    ElevatedButton(
                      child: const Text("Desconectar"),
                      onPressed: () => sdk.closeConnection(),
                      style: ElevatedButton.styleFrom(
                        primary: Colors.red,
                        minimumSize: const Size(250, 50),
                      ),
                    ),
                  ])
                ],
              ),
            ),
          ],
        )),
      ),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisherbukitech.cl

SDK para la integración con la API de Simpay

Homepage

License

unknown (LICENSE)

Dependencies

crypto, device_info, flutter, http, socket_io_client, webview_flutter

More

Packages that depend on simpay