duticotac_flutter 0.2.3 copy "duticotac_flutter: ^0.2.3" to clipboard
duticotac_flutter: ^0.2.3 copied to clipboard

Payment using Duticotac.

Duticotac Flutter #

A Flutter library for integrating Duticotac payments into your application. This package supports Mobile Money (Orange Money, MTN, Moov, Wave), Credit Cards, and In-App Purchases (IAP).

Features #

  • Mobile Money: Support for Orange Money CI, MTN CI, Moov CI, and Wave CI.
  • Credit Card: Secure credit card payments.
  • In-App Purchases: Integration with store IAP.
  • Offer Management: easy payment flow for pre-configured offers via payAnOffer.
  • Direct Payment: Flexible payment flow for custom amounts via payWithDuticotac.

Prerequisites & Installation #

1. Add Dependency #

Add duticotac_flutter to your pubspec.yaml:

dependencies:
  duticotac_flutter: ^0.2.1
  hive_ce_flutter: ^2.0.0 # Required for local DB

2. Important Build Setup #

Due to specific dependencies, you may need to run the following commands to ensure everything builds creates correctly:

Fix in_app_purchase_storekit version (if needed):

rm -r ~/.pub-cache/hosted/pub.flutter-io.cn/in_app_purchase_storekit-0.4.0 && flutter pub get

Generate Code (Required for Models): This package relies on generated code. Run the following command:

dart run build_runner clean && dart run build_runner build --delete-conflicting-outputs --build-filter="lib/src/models/**/**.dart"

Setup & Initialization #

Before using the library, you need to initialize Flutter bindings and Hive in your main.dart.

import 'package:flutter/material.dart';
import 'package:hive_ce_flutter/hive_flutter.dart';
import 'package:duticotac_flutter/duticotac_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize Hive
  await Hive.initFlutter();

  // Initialize Duticotac Hive Adapters
  await initDuticotacHiveAdapters();

  // Open the local database box
  await Hive.openBox('duticotac_imp_db');

  runApp(const MyApp());
}

Usage Guide #

You can accept payments in two ways: paying for a specific offer defined in your Duticotac dashboard, or initiating a direct payment with custom parameters.

Option 1: Pay An Offer (payAnOffer) #

This is the recommended method if you have offers configured in the Duticotac system.

import 'package:duticotac_flutter/duticotac_flutter.dart';
import 'package:hive_ce_flutter/hive_flutter.dart';

// ... inside your widget ...

final result = await payAnOffer(
  context,
  apiKey: "YOUR_API_KEY",
  reference: "OFFER_REFERENCE_ID",
  localDB: Hive.box('duticotac_imp_db'),
  getTransactionId: () async {
    // Return a unique transaction ID for this payment
    return "UNIQUE_TRANSACTION_ID_${DateTime.now().millisecondsSinceEpoch}";
  },
  // Optional parameters
  baseUrl: "https://api.duticotac.com", // If using a custom endpoint
  initialPhoneNumber: PhoneNumber.parse('+2250707070707'),
  email: "client@example.com",
  name: "Client Name",
  onTransactionCompleted: (transactionId) {
    print("Transaction Completed: $transactionId");
  },
);

print("Payment Result: $result");

Option 2: Direct Payment (payWithDuticotac) #

Use this method if you need to charge a dynamic amount or don't use pre-configured offers.

import 'package:duticotac_flutter/duticotac_flutter.dart';

// ... inside your widget ...

await payWithDuticotac(
  context,
  apiKey: "YOUR_API_KEY",
  amount: 1000.0, // Amount to charge
  productReference: "YOUR_PRODUCT_REF",
  getTransactionId: () async {
    return "UNIQUE_TRANSACTION_ID";
  },
  // Optional parameters
  title: "Payment Title",
  description: "Payment Description",
  email: "client@example.com",
  name: "Client Name",
  initialPhoneNumber: PhoneNumber.parse('+2250707070707'),
  selectedProviders: [
    PaymentProvider.orangeMoneyCI,
    PaymentProvider.mtnCI,
    PaymentProvider.waveCI,
    PaymentProvider.creditCard,
  ],
);

Platform Specific Configuration #

Android & iOS #

This package uses url_launcher for redirection and in_app_purchase for IAP.

  • Android: Ensure your AndroidManifest.xml has the INTERNET permission.
  • iOS:
    • Add LSApplicationQueriesSchemes to your Info.plist if you need to launch specific external apps.
    • For IAP, ensure you have configured your products in App Store Connect.

Refer to the official documentation for more details: