vinidpay_sdk 0.0.1 vinidpay_sdk: ^0.0.1 copied to clipboard
VinIDPay Flutter SDK helps you handle payments with VinID iOS and Android app.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:vinidpay_sdk/vinidpay_sdk.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _paymentStatus = 'Unknown';
final _orderIdController = TextEditingController();
final _signatureController = TextEditingController();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('VinIDPay SDK'),
),
body: Padding(
padding: EdgeInsets.all(16),
child: Column(
children: <Widget>[
TextField(
controller: _orderIdController,
decoration: InputDecoration(
labelText: 'Order ID',
),
),
TextField(
controller: _signatureController,
decoration: InputDecoration(
labelText: 'Signature',
),
),
FlatButton(
color: Colors.red,
onPressed: () {
if (_orderIdController.text == '' ||
_signatureController.text == '') {
return;
}
final String _orderId = _orderIdController.text;
final String _signature = _signatureController.text;
final bool _sandboxMode = false;
proceedPayment(
_orderId,
_signature,
_sandboxMode,
);
},
child: Text(
'Proceed Payment',
style: TextStyle(color: Colors.white),
),
),
Text(_paymentStatus),
],
),
),
),
);
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> proceedPayment(
String orderId, String signature, bool sandboxMode) async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion =
await VinidpaySdk.proceedPayment(orderId, signature, sandboxMode);
} on PlatformException {
platformVersion = 'Failed to get payment status.';
}
// 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(() {
_paymentStatus = platformVersion;
});
}
}