Pagseguro Payment Tech

PagSeguro

Sobre   |   Tecnologias   |   Requisitos   |   Configuração   |  


⚠️ Plugin não oficial!

🎯 Sobre

Este projeto visa facilitar a integração com o SDK PagSeguro Smart no Flutter. Compatível apenas com máquinas POS Smart da PagSeguro.

PlugPagServiceWrapper: 1.30.52

🔐 Licenciamento

Para adquirir uma licença, cadastre-se no site Licença JY Labtech.
Cada licença é válida por terminal. Após a compra, será gerada uma chave licenceKey vinculada ao terminal.

Inicialização com licença

 PagseguroPaymentTech.initPayment(
  handler: controller,
);

 PagseguroPaymentTech.initNfc(
  handler: nfcHandler,
);

A partir da versão 2.0.0 é necessário adicionar as chaves no seu arquivo local.properties na raiz da pasta android.

licenceKey=<sua_licenca>
licenceInternalKey=aHR0cHM6Ly9wb3MtcGF5bWVudHMtYXBpLTU3NzQ2NDIzNTQwOC5zb3V0aGFtZXJpY2EtZWFzdDEucnVuLmFwcC9wb3MtcGF5bWVudHMvbGljZW5jZS9jaGVjay9pbnZvaWNl

⚙️ Requisitos do Projeto

Para utilizar este plugin, seu projeto Flutter precisa atender aos seguintes requisitos:

Versões Mínimas

  • Flutter SDK: >= 3.0.0
  • Dart SDK: >= 3.0.0
  • Gradle: >= 8.12
  • Android Gradle Plugin (AGP): >= 8.12.1
  • Kotlin: >= 2.1.21
  • compileSdk: >= 35
  • minSdk: >= 23
  • Java: >= 17 (para o projeto do exemplo)

Configuração do Gradle

1. android/gradle/wrapper/gradle-wrapper.properties

Certifique-se de que seu projeto está usando o Gradle 8.12 ou superior:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2. android/gradle.properties

Adicione as seguintes configurações ao seu arquivo gradle.properties:

android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options="-Xmx2048M"

3. android/build.gradle (raiz do projeto)

No arquivo build.gradle na raiz do seu projeto Android, configure:

buildscript {
    ext {
        kotlin_version = '2.1.21'
        // ... outras configurações
    }

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.12.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://github.com/pagseguro/PlugPagServiceWrapper/raw/master'
        }
    }
}

4. android/app/build.gradle (módulo app)

Configure o módulo app com as versões corretas:

android {
    namespace = "com.seu.pacote.app"
    compileSdk = 35

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    defaultConfig {
        minSdk = 23
        targetSdk = 35
        // ... outras configurações
    }
}

5. android/settings.gradle (para projetos que usam o novo sistema de plugins)

Se você estiver usando a nova sintaxe de plugins do Flutter, seu settings.gradle deve seguir este padrão:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.13.0" apply false
    id "org.jetbrains.kotlin.android" version "2.1.21" apply false
}

include ":app"

Verificação

Após configurar seu projeto, execute:

cd android
./gradlew --version

Certifique-se de que a versão do Gradle exibida seja 8.12 ou superior.

🚀 Tecnologias

  • Flutter
  • PlugPagServiceWrapper (Android)

🏁 Configuração

pubspec.yaml

dependencies:
  pagseguro_payment_tech: any

Android Manifest

<uses-permission android:name="br.com.uol.pagseguro.permission.MANAGE_PAYMENTS"/>

Intent-filter

<intent-filter>
 <action android:name="br.com.uol.pagseguro.PAYMENT"/>
 <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

build.gradle (app level)

defaultConfig {
  applicationId "com.exemplo.pagamento"
  minSdkVersion 23
  targetSdkVersion flutter.targetSdkVersion
  ...
}

📦 Implementação

Criar Handler

class PaymentController extends PaymentHandler {
  // implementação omitida para brevidade
}

Métodos principais do Handler

  • onTransactionSuccess() — Transação aprovada
  • onError(String) — Erro na transação
  • onMessage(String) — Mensagem da PagSeguro
  • onTransactionInfo(...) — Detalhes da transação
  • writeToFile(...) — Personalizável

Iniciando transações

PagseguroPaymentTech.I.payment.activePinpad('CODIGO_ATIVACAO');

// Exemplos de pagamento:
PagseguroPaymentTech.I.payment.creditPayment(12.50);
PagseguroPaymentTech.I.payment.creditPaymentParc(1250, 2);
PagseguroPaymentTech.I.payment.debitPayment(12.50);
PagseguroPaymentTech.I.payment.pixPayment(12.50);
PagseguroPaymentTech.I.payment.voucherPayment(12.50);
PagseguroPaymentTech.I.payment.lastTransaction();

Estorno e cancelamento

PagseguroPaymentTech.I.payment.refund(
  transactionCode: controller.transactionCode,
  transactionId: controller.transactionId,
);

PagseguroPaymentTech.I.payment.abortTransaction();

Impressão

PagseguroPaymentTech.I.payment.printerfromFile('path/to/file.pdf');

PrintRenderWidget.print(
  context,
  pagseguroPaymentInstance: pagseguroPayment,
  child: MyCustomWidget(),
);

📡 NFC Smart

Inicialização

 PagseguroPaymentTech.initNfc(
  handler: SeuNfcHandler(),
);

Principais métodos NFC

await NfcSmart.instance.readNfc(idEvento);
await NfcSmart.instance.writeNfc(valor, nome, cpf, numeroTag, celular, aberto, idEvento);
await NfcSmart.instance.refundNfc(valor, idEvento);
await NfcSmart.instance.formatNfc();
await NfcSmart.instance.debitNfc(idEvento, valor);
await NfcSmart.instance.closeMethodCallHandler();
await NfcSmart.instance.lastTransaction();

Pagina automatizada

final result = await Navigator.push<PagseguroResponseModel?>(
  context,
  MaterialPageRoute(
    builder: (context) => PagseguroPage(
      params: PagseguroPageParams(
        amount: 100,
        type: PagseguroPaymentType.credit,
        options: PagseguroOptions(
          activationCode: '123456',
          isPrinterEstablishment: false,
        ),
      ),
    ),
  ),
);

Neste exemplo acima a váriavel result é do tipo PagseguroResponseModel.


JY Labtech

⬆️ Voltar ao topo