pix_flutter 2.0.0 copy "pix_flutter: ^2.0.0" to clipboard
pix_flutter: ^2.0.0 copied to clipboard

outdated

Wrapper para usar o API PIX, compatível com a maioria do PSPs. Para mais informações, acesse a documentação do PSP de sua escolha.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pix_flutter/pix_flutter.dart';
import 'package:qr_flutter/qr_flutter.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pix Flutter',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Exemplo API Pix Flutter'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var query;

  /// As informações solicitadas a seguir estão disponíveis no seu PSP ou instituição financeira.
  PixFlutter pixFlutter = PixFlutter(
      api: Api(
          baseUrl: 'SEU_BASE_URL',
          authUrl: 'SEU_AUTH_URL',
          certificate: 'SEU_CODIGO_BASIC',
          appKey: 'SEU_APP_KEY',
          permissions: [], // Lista das permissoes, use PixPermissions,
          isBancoDoBrasil: false // Use true se estiver usando API do BB,
          // Se voce estiver usando um certificado P12, utilize desta forma:
          // certificatePath:
          // e inclua o destino para o arquivo ;)
          ),

      // Essas informações a seguir somente são necessárias se você deseja utilizar o QR Code Estático
      payload: Payload(
          pixKey: 'SUA_CHAVE_PIX',

          /// Há um erro no API que impede o uso de descrição, ela não será inserida. Assim que o bug for consertado, o código voltará ao funcionamento completo.
          description: 'DESCRIÇÃO_DA_COMPRA',
          merchantName: 'MERCHANT_NAME',
          merchantCity: 'CITY_NAME',
          txid: 'TXID', // Até 25 caracteres para o QR Code estático
          amount: 'AMOUNT'));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Center(
            child: Padding(
              padding: const EdgeInsets.all(10.0),
              child: Container(
                height: 255,
                width: 255,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  border: Border.all(color: Colors.black, width: 5),
                ),
                child: query != null
                    ? QrImage(
                        data: query,
                        version: QrVersions.auto,
                        size: 250.0,
                      )
                    : Center(
                        child: Text(
                          'Crie uma compra para que o QR apareça aqui',
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontWeight: FontWeight.w500, fontSize: 16),
                        ),
                      ),
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 8.0),
            child: Text(
              'QR Code Estático',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              TextButton(
                  onPressed: () async {
                    query = pixFlutter.getQRCode();
                    setState(() {});
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.lightGreenAccent,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Criar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(left: 8.0),
            child: Text(
              'Cobrança Imediata',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              TextButton(
                  onPressed: () async {
                    var request = {
                      "calendario": {"expiracao": "36000"},
                      "devedor": {
                        "cpf": "12345678909",
                        "nome": "Francisco da Silva"
                      },
                      "valor": {"original": "130.44"},
                      "chave": "7f6844d0-de89-47e5-9ef7-e0a35a681615",
                      "solicitacaoPagador": "Cobrança dos serviços prestados."
                    };

                    query = await pixFlutter.createCobTxid(
                        request: request,
                        txid: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');

                    var payloadDinamico = PixFlutter(
                        payload: Payload(
                      merchantName: 'SEU_MERCHANT_NAME',
                      merchantCity: 'SEU_MERCHANT_CITY',
                      txid: query['txid'],
                      url: query['location'],
                      isUniquePayment: true,
                    ));

                    query = payloadDinamico.getQRCode();

                    setState(() {});
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.lightGreenAccent,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Criar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () async {
                    var request = {
                      "loc": {"id": "7768"},
                      "devedor": {
                        "cpf": "12345678909",
                        "nome": "Francisco da Silva"
                      },
                      "valor": {"original": "123.45"},
                      "solicitacaoPagador": "Cobrança dos serviços prestados."
                    };

                    query = await pixFlutter.reviewCob(
                        request: request,
                        txid: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');

                    query = query['location'];

                    setState(() {});
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.orange,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Revisar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () {
                    pixFlutter.checkCob(
                        txid: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.blue,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Consultar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () {
                    // Atenção! Siga o padrao RFC 3339 para a data

                    pixFlutter.checkCobList(
                        queryParameters:
                            'inicio=2021-05-10T00:00:00Z&fim=2021-08-14T23:59:59Z');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.brown,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Consultar lista',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(left: 8.0),
            child: Text(
              'Cobrança com Vencimento',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              TextButton(
                  onPressed: () async {
                    var request = {
                      "calendario": {
                        "dataDeVencimento": "2020-12-31",
                        "validadeAposVencimento": 30
                      },
                      "loc": {"id": "789"},
                      "devedor": {
                        "logradouro": "Alameda Souza, Numero 80, Bairro Braz",
                        "cidade": "Recife",
                        "uf": "PE",
                        "cep": "70011750",
                        "cpf": "12345678909",
                        "nome": "Francisco da Silva"
                      },
                      "valor": {
                        "original": "123.45",
                        "multa": {"modalidade": "2", "valorPerc": "15.00"},
                        "juros": {"modalidade": "2", "valorPerc": "2.00"},
                        "desconto": {
                          "modalidade": "1",
                          "descontoDataFixa": [
                            {"data": "2020-11-30", "valorPerc": "30.00"}
                          ]
                        }
                      },
                      "chave": "5f84a4c5-c5cb-4599-9f13-7eb4d419dacc",
                      "solicitacaoPagador": "Cobrança dos serviços prestados."
                    };

                    query = await pixFlutter.createCobV(
                        request: request,
                        txid: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');

                    query = query['location'];

                    setState(() {});
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.lightGreenAccent,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Criar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () async {
                    var request = {
                      "loc": {"id": "7768"},
                      "devedor": {
                        "cpf": "12345678909",
                        "nome": "Francisco da Silva"
                      },
                      "valor": {"original": "123.45"},
                      "solicitacaoPagador": "Cobrança dos serviços prestados."
                    };

                    query = await pixFlutter.reviewCobV(
                        request: request,
                        txid: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');

                    query = query['location'];

                    setState(() {});
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.orange,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Revisar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () {
                    pixFlutter.checkCobV(
                        txid: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.blue,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Consultar',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () {
                    // Atenção! Siga o padrao RFC 3339 para a data

                    pixFlutter.checkCobVList(
                        queryParameters:
                            'inicio=2021-05-10T00:00:00Z&fim=2021-08-14T23:59:59Z');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.brown,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Consultar lista',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(left: 8.0),
            child: Text(
              'Cobrança com Vencimento em Lote',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextButton(
                  onPressed: () {
                    var request = {
                      "descricao": "Cobranças dos alunos do turno vespertino",
                      "cobsv": [
                        {
                          "calendario": {
                            "dataDeVencimento": "2020-12-31",
                            "validadeAposVencimento": 30
                          },
                          "txid": "fb2761260e554ad593c7226beb5cb650",
                          "loc": {"id": "789"},
                          "devedor": {
                            "logradouro":
                                "Alameda Souza, Numero 80, Bairro Braz",
                            "cidade": "Recife",
                            "uf": "PE",
                            "cep": "70011750",
                            "cpf": "08577095428",
                            "nome": "João Souza"
                          },
                          "valor": {"original": "100.00"},
                          "chave": "7c084cd4-54af-4172-a516-a7d1a12b75cc",
                          "solicitacaoPagador": "Informar matrícula"
                        },
                        {
                          "calendario": {
                            "dataDeVencimento": "2020-12-31",
                            "validadeAposVencimento": 30
                          },
                          "txid": "7978c0c97ea847e78e8849634473c1f1",
                          "loc": {"id": "57221"},
                          "devedor": {
                            "logradouro":
                                "Rua 15, Numero 1, Bairro Campo Grande",
                            "cidade": "Recife",
                            "uf": "PE",
                            "cep": "70055751",
                            "cpf": "15311295449",
                            "nome": "Manoel Silva"
                          },
                          "valor": {"original": "100.00"},
                          "chave": "7c084cd4-54af-4172-a516-a7d1a12b75cc",
                          "solicitacaoPagador": "Informar matrícula"
                        }
                      ]
                    };

                    pixFlutter.createLoteCobV(
                        request: request,
                        id: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.lightGreenAccent,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Criar lote',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () {
                    pixFlutter.checkLoteCobV(
                        id: 'uFtsUPrY1dVV8oLshK1DLsRbYrbZ9UfRouW');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.blue,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Consultar lote',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
              TextButton(
                  onPressed: () {
                    // Atenção! Siga o padrao RFC 3339 para a data

                    pixFlutter.checkLoteCobVList(
                        queryParameters:
                            'inicio=2021-05-10T00:00:00Z&fim=2021-08-14T23:59:59Z');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.brown,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(11.0),
                      child: Center(
                        child: Text(
                          'Consultar lista de lotes',
                          style: TextStyle(
                            fontSize: 13,
                            color: Colors.black54,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  )),
            ],
          ),
        ],
      )),
    );
  }
}
38
likes
0
points
808
downloads

Publisher

verified publisherhuodelivery.com

Weekly Downloads

Wrapper para usar o API PIX, compatível com a maioria do PSPs. Para mais informações, acesse a documentação do PSP de sua escolha.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter

More

Packages that depend on pix_flutter