adyen_client_side_encryption 0.0.1 copy "adyen_client_side_encryption: ^0.0.1" to clipboard
adyen_client_side_encryption: ^0.0.1 copied to clipboard

outdated

Adyen card client side encryption (CSE)

example/lib/main.dart

import 'package:adyen_client_side_encryption/card_encrypter.dart';
import 'package:adyen_client_side_encryption/unencrypted_card.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late String publicKey = throw 'Add your public key here';
  String _text = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String text;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      final unencryptedCard = UnencryptedCard(
        number: '123456789',
        expiryMonth: '12',
        expiryYear: '2025',
        cvc: '123',
      );
      text = (await CardEncrypter.encryptCard(unencryptedCard, publicKey)).toString();
    } on PlatformException {
      text = 'Failed to encrypt card.';
    }

    // 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(() => _text = text);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Adyen card encrypter'),
        ),
        body: Center(
          child: Text(_text),
        ),
      ),
    );
  }
}