moneyhash_payment 1.0.3 moneyhash_payment: ^1.0.3 copied to clipboard
MoneyHash is a Super-API infrastructure for payment orchestration and revenue operations in emerging markets.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:moneyhash_payment/data/intent_detais.dart';
import 'package:moneyhash_payment/data/intent_type.dart';
import 'package:moneyhash_payment/moneyhash_payment.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> {
MoneyHashSDK moneyhashSDK = MoneyHashSDKBuilder.build();
IntentDetails? _result;
TextEditingController? paymentIdTextEditController =
TextEditingController(text: "gwz1EDL");
String? errorText;
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
IntentDetails? result;
try {
result = await moneyhashSDK.renderForm(
paymentIdTextEditController!.text, IntentType.payment);
} catch (e) {
// handle the error
}
// 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(() {
_result = result;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('MoneyHash Example App'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextField(
onChanged: (value) {
setState(() {
errorText = null;
});
},
controller: paymentIdTextEditController,
decoration: InputDecoration(
errorText: errorText,
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)))),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
if (paymentIdTextEditController!.text.isNotEmpty) {
initPlatformState();
} else {
setState(() {
errorText = "Please enter payment id";
});
}
},
child: const Text("Click"),
),
const SizedBox(height: 32),
Text(
'Amount is: ${_result?.intent?.amount?.formatted ?? "no amount added"}\n'),
],
),
),
),
);
}
}