bex_flutter_plugin 0.0.1-dev.1 copy "bex_flutter_plugin: ^0.0.1-dev.1" to clipboard
bex_flutter_plugin: ^0.0.1-dev.1 copied to clipboard

outdated

BKM Express Flutter plugin.

example/lib/main.dart

import 'dart:async';

import 'package:bex_flutter_plugin/BexListener.dart';
import 'package:bex_flutter_plugin/BexPosResult.dart';
import 'package:bex_flutter_plugin/BexStarter.dart';
import 'package:bex_flutter_plugin_example/BexNetwork.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> implements BexPairingListener, BexPaymentListener {
  String _response = 'Unknown';
  TextEditingController consumerIdController = TextEditingController();

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

  Future<void> initPlatformState() async {
    String platformVersion;
    BexSdk.init(true);

    // 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(() {
      _response = platformVersion;
    });
  }

  _submitConsumer() async {
    BexNetwork.requestGetConsumerId().then((token) async {
      BexSdk.submitConsumer(token, this);
    }).catchError((e) {
      setError(e.toString());
    });
  }

  _resubmitConsumer() async {
    if (consumerIdController.text.isNotEmpty) {
      BexNetwork.requestGetReSubmitTicket(consumerIdController.text).then((ticket) {
        if (ticket == null) {
          setError("Ticket null olamaz!");
          return;
        }
        BexSdk.resubmitConsumer(ticket, this);
      }).catchError((e) {
        setError(e.toString());
      });
    } else {
      setError("Consumer ID null olamaz");
    }
  }

  _payment() async {
    BexNetwork.requestGetTokenForInitPayment().then((token) {
      BexSdk.payment(token, this);
    }).catchError((e) {
      setError(e.toString());
    });
  }

  void setError(String message) {
    setState(() {
      _response = "Error: " + message;
    });
  }

  @override
  void onPairingCancelled() {
    setState(() {
      _response = "Pairing Cancelled!";
    });
  }

  @override
  void onPairingFailure(int errorId, String errorMsg) {
    setState(() {
      _response = "Pairing Failure - errorId: " + errorId.toString() + ", errorMsg: " + errorMsg;
    });
  }

  @override
  void onPairingSuccess(String first6, String last2) {
    setState(() {
      _response = "Success - first6: " + first6 + ", last2: " + last2;
    });
  }

  @override
  void onPaymentCancelled() {
    setState(() {
      _response = "Payment Cancelled!";
    });
  }

  @override
  void onPaymentFailure(int errorId, String errorMsg) {
    setState(() {
      _response = "Payment Failure - errorId: " + errorId.toString() + ", errorMsg: " + errorMsg;
    });
  }

  @override
  void onPaymentSuccess(BexPosResult posResult) {
    setState(() {
      _response = "Payment Success - posResult.token: " + posResult.token;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Bex Flutter Plugin'),
          ),
          body: Padding(
            padding: const EdgeInsets.only(left: 30.0, right: 30.0),
            child: Column(
              children: [
                SizedBox(
                    width: double.infinity, // match_parent
                    child: RaisedButton(
                      child: Text('Ödeme Yap'),
                      onPressed: _payment,
                    )),
                SizedBox(
                    width: double.infinity, // match_parent
                    child: RaisedButton(
                      child: Text('Kart Eşleştir'),
                      onPressed: _submitConsumer,
                    )),
                SizedBox(
                    width: double.infinity, // match_parent
                    child: TextField(
                      controller: consumerIdController,
                      decoration: InputDecoration(labelText: 'Consumer ID'),
                    )),
                SizedBox(
                    width: double.infinity, // match_parent
                    child: RaisedButton(
                      child: Text('Kart Değiştir'),
                      onPressed: _resubmitConsumer,
                    )),
                Text('Response: $_response\n'),
              ],
            ),
          )),
    );
  }
}
4
likes
0
pub points
35%
popularity

Publisher

unverified uploader

BKM Express Flutter plugin.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, http

More

Packages that depend on bex_flutter_plugin