moneyhash_payment 2.2.1 moneyhash_payment: ^2.2.1 copied to clipboard
MoneyHash is a Super-API infrastructure for payment orchestration and revenue operations in emerging markets.
import 'package:flutter/material.dart';
import 'package:moneyhash_payment/data/card/card_field_type.dart';
import 'package:moneyhash_payment/data/google_pay/NativeGooglePayConfig.dart';
import 'package:moneyhash_payment/data/intent_methods.dart';
import 'package:moneyhash_payment/data/intent_type.dart';
import 'package:moneyhash_payment/data/methods/get_methods_params.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';
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> {
CardForm? _cardForm;
String paymentIntentId = "";
String cardIntentId = "";
String customerId = "";
String publicKey = "";
MoneyHashSDK moneyHashSDK = MoneyHashSDKBuilder()
.setNativeGooglePayConfig(NativeGooglePayConfig(
environment: GooglePayEnvironment.test,
allowedCards: [
AllowedCards.amex,
AllowedCards.visa,
AllowedCards.mastercard,
AllowedCards.jcb
],
supportedMethods: [
SupportedMethods.pan_only,
SupportedMethods.cryptogram_3ds
],
))
.build();
@override
void initState() {
moneyHashSDK.setLogLevel(LogLevel.debug);
_cardForm = 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}");
}).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",
cardForm: _cardForm!,
type: CardFieldType.cardNumber,
),
const SizedBox(height: 16),
SecureTextField(
label: "cvv",
placeholder: "cvv",
cardForm: _cardForm!,
type: CardFieldType.cvv,
),
const SizedBox(height: 16),
SecureTextField(
label: "expireMonth",
placeholder: "expireMonth",
cardForm: _cardForm!,
type: CardFieldType.expiryMonth,
),
const SizedBox(height: 16),
SecureTextField(
label: "cardHolderName",
placeholder: "cardHolderName",
cardForm: _cardForm!,
type: CardFieldType.cardHolderName,
),
SecureTextField(
label: "expireYear",
placeholder: "expireYear",
cardForm: _cardForm!,
type: CardFieldType.expiryYear,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
// moneyHashSDK.setPublicKey(publicKey);
var intentMethods = await moneyHashSDK.getMethods(GetMethodsParams.withIntent(paymentIntentId, IntentType.payment));
print("Methods: $intentMethods");
//
// var accountMethods = await moneyHashSDK.getMethods(
// GetMethodsParams.withCurrency(currency: "USD", customer: customerId, flowId: null, amount: null)
// );
// print("Methods: $accountMethods");
//
//
// var intentDetails = await moneyHashSDK.getIntentDetails(paymentIntentId, IntentType.payment);
// var intentAmount = intentDetails.intent?.amount;
// print("intentAmount: $intentAmount");
//
// var collectResult = await _cardForm?.collect();
// print("CollectResult: ${collectResult?.cardHolderName}");
// print("CollectResult: ${collectResult?.expiryMonth}");
// Set the intent method to Card before proceeding to payment
// await moneyHashSDK.proceedWithMethod(paymentIntentId, IntentType.payment, "CARD", MethodType.paymentMethod, null);
// var payResult = await _cardForm?.pay(
// paymentIntentId,
// collectResult!,
// true,
// null,
// null,
// );
// print("PayResult: ${payResult?.transaction?.amount}");
// print("PayResult: ${payResult?.transaction?.amountCurrency}");
// var cardTokenResult = await _cardForm?.createCardToken(cardIntentId, collectResult!);
// print("Card Token Result: $cardTokenResult");
/**
* Get the state of the current intent and check if it is NativePay and google pay
*/
/*
var currentIntent = await moneyHashSDK.getIntentDetails(intentId, IntentType.payment);
var state = (currentIntent.intentState as NativePay).nativePayData as GooglePayData;
var isReady = await moneyHashSDK.isReadyForGooglePay();
print("IsReady: $isReady");
print("currencyCode: ${state.currencyCode}");
print("amount: ${state.amount}");
print("countryCode: ${state.countryCode}");
print("gateway: ${state.gateway}");
print("gatewayMerchantId: ${state.gatewayMerchantId}");
print("merchantId: ${state.merchantId}");
print("merchantName: ${state.merchantName}");
var googlePayResult = await moneyHashSDK.proceedWithGooglePay(
"ZAK1PeL",
state.currencyCode!,
state.amount!,
state.countryCode!,
state.gateway!,
state.gatewayMerchantId!,
state.merchantId!,
state.merchantName!
);
print("googlePayResult: $googlePayResult");
*/
},
child: const Text("Submit"))
],
),
),
);
}
}