moneyhash_payment 2.0.5 moneyhash_payment: ^2.0.5 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/card/card_field_type.dart';
import 'package:moneyhash_payment/data/discount/discount_item.dart';
import 'package:moneyhash_payment/data/discount/discount_type.dart';
import 'package:moneyhash_payment/data/fee/fee_item.dart';
import 'package:moneyhash_payment/data/intent_details.dart';
import 'package:moneyhash_payment/data/intent_methods.dart';
import 'package:moneyhash_payment/data/intent_type.dart';
import 'package:moneyhash_payment/data/language/language.dart';
import 'package:moneyhash_payment/data/tokenize_card_info.dart';
import 'package:moneyhash_payment/data/vault_data.dart';
import 'package:moneyhash_payment/log/log_level.dart';
import 'package:moneyhash_payment/vault/card_collector.dart';
import 'package:moneyhash_payment/vault/widget/secure_text_field.dart';
import 'package:moneyhash_payment/vault/card_form_builder.dart';
import 'package:moneyhash_payment/moneyhash_payment.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
CardCollector? _cardCollector;
String intentId = "ZvEXDGg";
String accessToken = "token";
MoneyHashSDK moneyHashSDK = MoneyHashSDKBuilder.build();
@override
void initState() {
moneyHashSDK.setLogLevel(LogLevel.verbose);
_cardCollector = CardFormBuilder()
.setCardHolderNameField((state) {
print("CardHolderName: ${state?.isValid}");
print("CardHolderName: ${state?.errorMessage}");
})
.setCardNumberField((state) {
print("CardNumber: ${state?.isValid}");
print("CardNumber: ${state?.errorMessage}");
})
.setCVVField((state) {
print("CVV: ${state?.isValid}");
print("CVV: ${state?.errorMessage}");
})
.setExpiryMonthField((state) {
print("ExpireMonth: ${state?.isValid}");
print("ExpireMonth: ${state?.errorMessage}");
})
.setExpiryYearField((state) {
print("ExpireYear: ${state?.isValid}");
print("ExpireYear: ${state?.errorMessage}");
})
.setCardBrandChangeListener((cardBrand) {
print("CardBrand: ${cardBrand?.brand}");
print("CardBrand: ${cardBrand?.brandIconUrl}");
print("CardBrand: ${cardBrand?.first6Digits}");
})
.setTokenizeCardInfo(TokenizeCardInfo(
accessToken: accessToken,
isLive: true,
saveCard: true,
saveCardCheckbox:
SaveCardCheckbox()
))
.build();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text("Testing card"),
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SecureTextField(
label: "cardNumber",
placeholder: "cardNumber",
cardFormCollector: _cardCollector!,
type: CardFieldType.cardNumber,
),
const SizedBox(height: 16),
SecureTextField(
label: "cvv",
placeholder: "cvv",
cardFormCollector: _cardCollector!,
type: CardFieldType.cvv,
),
const SizedBox(height: 16),
SecureTextField(
label: "expireMonth",
placeholder: "expireMonth",
cardFormCollector: _cardCollector!,
type: CardFieldType.expiryMonth,
),
const SizedBox(height: 16),
SecureTextField(
label: "cardHolderName",
placeholder: "cardHolderName",
cardFormCollector: _cardCollector!,
type: CardFieldType.cardHolderName,
),
SecureTextField(
label: "expireYear",
placeholder: "expireYear",
cardFormCollector: _cardCollector!,
type: CardFieldType.expiryYear,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
await _cardCollector?.collect("intentId", false);
// moneyHashSDK.setLogLevel(LogLevel.verbose);
// moneyHashSDK.setLocale(Language.arabic);
// var result = await moneyHashSDK.renderForm(intentId, IntentType.payment, null);
// print("Result: $result");
// print("Result: ${result?.transaction?.providerTransactionFields}");
// var discountData = await moneyHashSDK.updateDiscount(intentId, DiscountItem(
// title: {
// Language.english: "Discount",
// Language.arabic: "خصم",
// },
// type: DiscountType.percentage,
// value: "15",
// )
// );
//
// print("DiscountData: ${discountData?.discount?.title}");
// print("DiscountData: ${discountData?.discount?.type}");
// print("DiscountData: ${discountData?.discount?.value}");
// var fees = await moneyHashSDK.updateFees(intentId, [FeeItem(
// title: {
// Language.english: "zeiny fee",
// Language.arabic: "مصاريف",
// },
// value: "25",
// discount: DiscountItem(
// title: {
// Language.english: "Discount",
// Language.arabic: "خصم",
// },
// type: DiscountType.percentage,
// value: "5",
// )
// )
// ]
// );
// //
// print("FeesData: ${fees?.fees?.first?.title}");
// print("FeesData: ${fees?.fees?.first?.value}");
// print("FeesData: ${fees?.fees?.first?.discount?.type}");
// print("FeesData: ${fees?.amount}");
// var details = await moneyHashSDK.getIntentDetails(intentId, IntentType.payment);
// print(details.intent?.amount?.currency);
// print(details.intent?.fees?.first.value);
// await moneyHashSDK.proceedWithMethod(
// "glD8Emg",
// IntentType.payment,
// "gymYxdg",
// MethodType.savedCard,
// null,
// );
},
child: const Text("Submit"))
],
),
),
);
}
}