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

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

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:moneyhash_payment/data/apple_pay_configuration.dart';
import 'package:moneyhash_payment/data/card/card_field_type.dart';
import 'package:moneyhash_payment/data/card_form_configuration.dart';
import 'package:moneyhash_payment/data/intent_methods.dart';
import 'package:moneyhash_payment/data/intent_state.dart';
import 'package:moneyhash_payment/data/intent_type.dart';
import 'package:moneyhash_payment/data/methods/get_methods_params.dart';
import 'package:moneyhash_payment/data/render_strategy.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 = "gQnkDBq";
  String cardIntentId = "";
  String customerId = "";
  String publicKey = "public.zOr9kfOu.x2wFA9d9IDM4KVb5QEMXNvNf4Qify1s5348Xi9RB";

  MoneyHashSDK moneyHashSDK = MoneyHashSDKBuilder()
      // .setNativeGooglePayConfig(NativeGooglePayConfig(
      //   environment: GooglePayEnvironment.test,
      //   allowedCards: [
      //     AllowedCards.amex,
      //     AllowedCards.visa,
      //     AllowedCards.mastercard,
      //     AllowedCards.jcb
      //   ],
      //   supportedMethods: [
      //     SupportedMethods.pan_only,
      //     SupportedMethods.cryptogram_3ds
      //   ],
      // ))
      .setNativeApplePayConfig(ApplePayConfiguration(
        collectibleBillingData: [
          // CollectibleBillingData.email,
        ],
        merchantDisplayName: "Kero Store",
      ))
      .build();

  @override
  void initState() {
    _cardForm = CardFormBuilder()
        .setCardHolderNameField((state) {
          print("CardHolderName: ${state?.isValid}");
          print("CardHolderName: ${state?.errorMessage}");
        })
        .setCardNumberField((state) {
          print("CardNumber: ${state?.isValid}");
          print("CardNumber: ${state?.errorMessage}");
          print("CardNumber: ${state?.length}");
        })
        .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}");
        })
        .setConfiguration(CardFormConfiguration(
            isCardHolderNameRequired: true,
            // enableCardNumberValidation: false
    ))
        .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 {
                  var x = await _cardForm?.isValid();

                  print("kero");
                  moneyHashSDK.setPublicKey(publicKey);
                  moneyHashSDK.setLogLevel(LogLevel.verbose);
                  // var details = await moneyHashSDK.renderForm(
                  //     "Z00vWKJ", IntentType.payment, null);

                  // var intentDetail = await moneyHashSDK.getIntentDetails(paymentIntentId, IntentType.payment);
                  //
                  // // final state = intentDetail.intentState;
                  //
                  // var intentDetails = await moneyHashSDK.proceedWithMethod(paymentIntentId, IntentType.payment, "gjNX7yg", MethodType.savedCard, MethodMetaData(cvv: "123"), null);
                  //
                  // final state = intentDetails.details?.intentState;
                  //
                  //
                  // if (state is UrlToRender) {
                  //   final String? urlToOpen = state.url;           // <- the URL you need
                  //   final RenderStrategy? strategy = state.renderStrategy;
                  //
                  //   print('URL to render = $urlToOpen');
                  //
                  //   var details = await moneyHashSDK.renderURL(
                  //       urlToOpen!,
                  //       paymentIntentId,
                  //       IntentType.payment,
                  //       null
                  //   );
                  //   print("intentDetails $details");
                  //   // e.g. launchUrlString(urlToOpen!);
                  // } else {
                  //   // handle the other possible states here
                  //   print('Current intent state is ${state.runtimeType}, not UrlToRender');
                  // }

                  // var plans = await moneyHashSDK.getInstallmentPlans(50.0, "egp", null);
                  // print("plans: ${plans?.first.id}");
                  // print("plans: ${plans?.first.amount}");
                  // print("plans: ${plans?.first.installmentPeriod}");
                  // print("plans: ${plans?.first.interestRate}");
                  // print("plans: ${plans?.first.upfrontFees}");

                  // var methods = await moneyHashSDK.getMethods(GetMethodsParams.withCurrency(currency: "EGP", operation: IntentOperation.purchase));
                  // print(methods.toJson());
                  // await moneyHashSDK.renderForm(paymentIntentId, IntentType.payment, null);

                  // var intentDetails = await moneyHashSDK.getIntentDetails(paymentIntentId, IntentType.payment);
                  // print("intentDetails $intentDetails");
                  //
                  //
                  // var methods = await moneyHashSDK.getMethods(GetMethodsParams.withCurrency(currency: "EGP", operation: IntentOperation.purchase, customFields: customFields));
                  // print(methods.toJson());

                  // var recipt = await moneyHashSDK.generateApplePayReceipt(
                  //     40, "merchant.configuring.checkoutdotcom", "USD", "AE");
                  // print(recipt.toString());
                  // print(recipt?.receipt.toString());
                  // print(recipt?.receiptBillingData.toString());
                  //
                  // InstallmentPlanData plan = InstallmentPlanData(
                  //   id: "2407",
                  //   issuerCode: null,
                  // );
                  // var intentMethods = await moneyHashSDK.proceedWithMethod(
                  //     paymentIntentId,
                  //     IntentType.payment,
                  //     "CARD",
                  //     MethodType.paymentMethod,
                  //     null,
                  //     null);
                  // print(intentMethods);
                  // var customFields = {
                  //   'isActive': BooleanValue(true),
                  //   'score': FloatValue(3.14),
                  //   'rate': DoubleValue(42.0),
                  //   'name': StringValue('John Doe'),
                  //   "age": IntValue(25),
                  // };
                  // //
                  // //
                  var methods = await moneyHashSDK.getMethods(
                      GetMethodsParams.withCurrency(
                          amount: 10, currency: "AED", customer: "9db9b32c-8d0d-4937-a5cd-54ef1a38903d"));
                  print(methods.toJson());
                  var res = await moneyHashSDK.getIntentDetails(
                        "9ep3bJz", IntentType.payment);
                    print(res.intentState);

                  // var compatable = await moneyHashSDK.isDeviceCompatibleWithApplePay();
                  //
                  // print("is device compatabel ${compatable}");
                  // final applePayExpressMethod = methods.expressMethods
                  //     ?.firstWhere((em) => em.nativePayData is ApplePayData);
                  //
                  // final applePayData =
                  //     applePayExpressMethod?.nativePayData as ApplePayData;
                  //
                  // var recipt = await moneyHashSDK.generateApplePayReceipt(2, applePayData.merchantId!, applePayData.currencyCode!, applePayData.countryCode!);
                  // print(recipt.toString());
                  // print(recipt?.receipt.toString());
                  // print(recipt?.receiptBillingData.toString());
                  //
                  // var lookupData = await moneyHashSDK.getApplePayBinLookup(
                  //     recipt!, applePayData.methodID!);
                  // print(lookupData?.toJson());

                  // await moneyHashSDK.proceedWithMethod(
                  //     paymentIntentId,
                  //     IntentType.payment,
                  //     "APPLE_PAY",
                  //     MethodType.paymentMethod,
                  //     null,
                  //     null);
                  // var details = await moneyHashSDK.proceedWithApplePay(
                  //     paymentIntentId,
                  //     2,
                  //     applePayData.merchantId!,
                  //     applePayData.currencyCode!,
                  //     applePayData.countryCode!,
                  //     merchantCapabilities: applePayData.merchantCapabilities,
                  //     supportedNetworks: applePayData.supportedNetworks);
                  // print(details?.toString());

                  // InstallmentPlanData plan = InstallmentPlanData(
                  //   id: "2407",
                  //   issuerCode: null,
                  // );
                  // var intentMethods = await moneyHashSDK.proceedWithMethod(paymentIntentId, IntentType.payment, "APPLE_PAY", MethodType.paymentMethod, null, null);
                  // print(intentMethods);
                  //
                  // var intentDetails = await moneyHashSDK.submitPaymentReceipt("LP44VQL", recipt!);
                  // print(intentDetails);
                  // var intentID = 'LVmyom9';
                  // var res = await moneyHashSDK.getIntentDetails(
                  //     intentID, IntentType.payment);
                  // print(res.intentState);
                  //

                  // var res2 = await moneyHashSDK.selectInstallmentPlan(
                  //   intentID,
                  //   plan,
                  // );
                  //
                  // print(res2);

                  // .getMethods(GetMethodsParams.withIntent('948E769', IntentType.payment));
                  // 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");
                  //
                  // print("kero2");
                  // var collectResult = await _cardForm?.collect();
                  // print("kero4");
                  // 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}");
                  // print("PayResultState: ${payResult?.intentState}");
                  //
                  //
                  // var selectPlanRes = await moneyHashSDK.selectInstallmentPlan(paymentIntentId, plan);
                  // print("selectPlanRes: ${selectPlanRes?.transaction?.amount}");
                  // print("selectPlanRes: ${selectPlanRes?.transaction?.amountCurrency}");
                  // print("selectPlanRes: ${selectPlanRes?.intentState}");

                  // 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"))
          ],
        ),
      ),
    );
  }
}
4
likes
0
points
1.31k
downloads

Publisher

verified publishermoneyhash.io

Weekly Downloads

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

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on moneyhash_payment

Packages that implement moneyhash_payment