Flutter

Easily implement Ivorypay for crypto payments in your Flutter applications. This library supports both Android and iOS.

More details can be found at https://pub.dev/packages/ivorypay_flutter

To use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add ivorypay_flutter

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  ivorypay_flutter: ^0.0.6

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:ivorypay_flutter/ivorypay_flutter.dart';

Public Key

In order to use this library you are required to use your ivorypay public key and not the secret key. See how to get your API Keys here

Usage

Below is an example showcasing how you can use the library to implement payment in your Flutter app.

How to use it for iOS and Android

import 'package:ivorypay_flutter/ivorypay_flutter.dart';


///Initialize IvorypayFlutter account for the diffrent states of the transactions
///Error,Success and Loading
final ivoryService = IvorypayFlutter(
  context: context,
  data: InitiateIvorypayTransaction(
    baseFiat: "NGN",
    amount: 4000,
    crypto: "USDC",
    email: 'EMAIL',
    authorization: 'PUBLIC_API_KEY',
  ),
  onError: (value, e) {},
  onSuccess: (res) {},
  onLoading: (valueLoading) {
    setState(() {
      isLoading = valueLoading;
    });
  },
);

///After initializing IvorypayFlutter you can call the run method to trigger the transactions
///NB: The loading state is triggered when run() is called.

ivoryService.run();

How to use it for Web

import 'package:ivorypay_flutter/ivorypay_flutter.dart';
import 'package:ivorypay_flutter/ivorypay_flutter_alt_web.dart';


///Initialize IvorypayFlutterWeb account for the diffrent states of the transactions
///Error,Success and Loading
  final ivorypayWebService = IvorypayFlutterWeb();
  
  //Call the ivorypayWebService.run, using the ivorypay button an example would look like this

              IvorypayButton(
                      option: IvorypayButtonOption.two,
                      onTap: () async {
                        ///Flutter Web only implementation
                        ivorypayWebService.run(
                          isDev: true,
                          context: context,
                          data: InitiateIvorypayTransaction(
                            baseFiat: "NGN",
                            amount: int.tryParse(amountCtrl.text.trim()),
                            crypto: crypto.text,
                            email: email.text,
                            authorization: authCtrl.text,
                          ),
                          onError: (value, e) {
                            ScaffoldMessenger.of(context).showSnackBar(
                                SnackBar(content: Text(e.toString())));
                          },
                          onSuccess: (res) {
                            // Navigator.of(context).pop();
                            ScaffoldMessenger.of(context).showSnackBar(
                                SnackBar(content: Text(res.toString())));
                          },
                          onLoading: (valueLoading) {
                            setState(() {
                              isLoading = valueLoading;
                            });
                          },
                        );
                      },
                    ),


//Calling run will open a new teb with the wallet address for the user to perform the tranasaction
//You may show a dialog on your web app for the user to confirm paymnet on return, when a user clicks on the dialog you an then call verify which will
//return the transaction details if it was successful or an error message if the action failed

           ivorypayWebService.verifyStatus(
                          isDev: true,
                          onError: (value, e) {
                            ScaffoldMessenger.of(context).showSnackBar(
                                SnackBar(content: Text(e.toString())));
                          },
                          onSuccess: (res) {
                            // Navigator.of(context).pop();
                            ScaffoldMessenger.of(context).showSnackBar(
                                SnackBar(content: Text(res.toString())));
                          },
                        );

Last updated