Cielo SDK for Flutter

Pub page link -- version License

An unofficial Flutter SDK for Cielo/Braspag.

Disclaimer

This SDK is created for personal use and the functionality is limited to the needs of my projects. You are more than welcome to contribute the code you need as soon as it follows the same code style. Fortunately, this is a very simple SDK, so it should be easy to understand and extend.

Getting Started

Installation

flutter pub add cielo_flutter

Configuration

import 'package:cielo_flutter/cielo_flutter.dart';

// Init core
const options = CieloOptions(
  environment: CieloEnvironment.sandbox,
  provider: CieloProvider.braspag,
  language: CieloLanguage.pt,
);
Cielo.init(options);

// Initialize Silent Order Post
const sop = CieloSOPOptions(enableTokenize: true);
Cielo.initSOP(sop);

Usage

Silent Order Post

Learn More:

import 'package:cielo_flutter/cielo_flutter.dart';

String accessToken = "<SOP access token generated by your backend>";
CieloCard card = CieloCard(
  cardNumber: '0000000000000001',
  holder: 'John Doe',
  expirationDate: '12/2021',
  securityCode: '123',
);
await Cielo.sop.sendCard(card, accessToken: accessToken);

Errors

try {
  Cielo.sop.sendCard(brokenCard, accessToken: accessToken);
} on CieloCardValidationException catch (e) {
  // Handle card validation errors.
  print(e.field); // Name of the field that caused the error.
  print(e.code); // The code of the error for dev use.
  print(e.message); // User-friendly message, localized according to core options.
} on CieloException catch (e) {
  // Handle SDK errors.
  // Currently, only thrown for invalid accessToken in SOP.
  print(e.code); // The code of the error for dev use.
  print(e.message); // The error message for dev use.
} on CieloAPIException catch (e) {
  // Handle API errors returned by the provider.
  print(e.code); // The code of the error for dev use.
  print(e.message); // The error message for dev use.
}

Other

// To reset SDK from all configurations.
Cielo.dispose();

License

Licensed under the MIT license, see LICENSE.

Libraries

cielo_flutter