moneyhash_payment 1.0.4 copy "moneyhash_payment: ^1.0.4" to clipboard
moneyhash_payment: ^1.0.4 copied to clipboard

MoneyHash is a Super-API infrastructure for payment orchestration and revenue operations in emerging markets.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:moneyhash_payment/data/intent_details.dart';
import 'package:moneyhash_payment/data/intent_type.dart';
import 'package:moneyhash_payment/moneyhash_payment.dart';
import 'package:moneyhash_payment/style/embed_button_style.dart';
import 'package:moneyhash_payment/style/embed_button_view_style.dart';
import 'package:moneyhash_payment/style/embed_input_style.dart';
import 'package:moneyhash_payment/style/embed_input_view_style.dart';
import 'package:moneyhash_payment/style/embed_loader_style.dart';
import 'package:moneyhash_payment/style/embed_style.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: "gyv4BdZ");
  String? errorText;

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

  EmbedStyle embedStyle = EmbedStyle(
    submitButton: EmbedButtonStyle(
      base: EmbedButtonViewStyle(
        color: "red",
        fontSmoothing: "antialiased",
        fontSize: "16px",
        fontWeight: "bold",
        fontFamily: "Arial",
        letterSpacing: "0.5px",
        lineHeight: "24px",
        textTransform: "uppercase",
        background: "#FF0000",
        padding: "10px 20px",
        borderRadius: "4px",
        boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
        borderStyle: "none",
        borderColor: "#FF0000",
        borderWidth: "1px",
      ),
      hover: EmbedButtonViewStyle(
        color: "red",
        fontSmoothing: "antialiased",
        fontSize: "16px",
        fontWeight: "bold",
        fontFamily: "Arial",
        letterSpacing: "0.5px",
        lineHeight: "24px",
        textTransform: "uppercase",
        background: "#FF0000",
        padding: "10px 20px",
        borderRadius: "4px",
        boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
        borderStyle: "none",
        borderColor: "#FF0000",
        borderWidth: "1px",
      ),
      focus: EmbedButtonViewStyle(
        color: "red",
        fontSmoothing: "antialiased",
        fontSize: "16px",
        fontWeight: "bold",
        fontFamily: "Arial",
        letterSpacing: "0.5px",
        lineHeight: "24px",
        textTransform: "uppercase",
        background: "#FF0000",
        padding: "10px 20px",
        borderRadius: "4px",
        boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
        borderStyle: "none",
        borderColor: "#FF0000",
        borderWidth: "1px",
      ),
    ),
    loader: EmbedLoaderStyle(
      backgroundColor: "black",
      color: "white",
    ),
    input: EmbedInputStyle(
      base: EmbedInputViewStyle(
        height: "40px",
        padding: "10px",
        background: "#FFFFFF",
        borderRadius: "4px",
        boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
        borderStyle: "none",
        borderColor: "red",
        borderWidth: "1px",
        color: "red",
        fontFamily: "Arial",
        fontWeight: "normal",
        fontSize: "16px",
        fontSmoothing: "antialiased",
        lineHeight: "24px",
      ),
      error: EmbedInputViewStyle(
        height: "40px",
        padding: "10px",
        background: "red",
        borderRadius: "4px",
        boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
        borderStyle: "none",
        borderColor: "#FF0000",
        borderWidth: "1px",
        color: "red",
        fontFamily: "Arial",
        fontWeight: "normal",
        fontSize: "16px",
        fontSmoothing: "antialiased",
        lineHeight: "24px",
      ),
      focus: EmbedInputViewStyle(
        height: "40px",
        padding: "10px",
        background: "red",
        borderRadius: "4px",
        boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
        borderStyle: "none",
        borderColor: "red",
        borderWidth: "1px",
        color: "red",
        fontFamily: "Arial",
        fontWeight: "normal",
        fontSize: "16px",
        fontSmoothing: "antialiased",
        lineHeight: "24px",
      ),
    ),
  );

  // 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,
          embedStyle
      );
    } 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'),
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
130
points
64
downloads

Publisher

verified publishermoneyhash.io

Weekly Downloads

MoneyHash is a Super-API infrastructure for payment orchestration and revenue operations in emerging markets.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on moneyhash_payment