Flutter OpenMoney

Flutter plugin for OpenMoney SDK.

Getting Started

This flutter plugin is a wrapper around openmoney Android SDK.

The following documentation is only focused on the wrapper around native Android SDK. To know more about this SDKs and how to link them within the projects, refer to the following documentation:

Android: https://github.com/eshantmittal/open-payment-android-aar

To initiate payment paymentToken and accessKey are mandatory variables. paymentToken - Generated in server side. Know more accessKey - Get from openmoney dashboard

Installation

This plugin is available on Pub: https://pub.dev/packages/flutter_openmoney

Add this to dependencies in your app's pubspec.yaml

flutter_openmoney: ^0.0.1

Note for Android: Make sure that the minimum API level for your app is 19 or higher.

Usage

Sample code to integrate can be found in example/lib/main.dart.

Import package

import 'package:flutter_openmoney/flutter_openmoney.dart';

Create FlutterOpenmoney instance

_flutterOpenmoney = FlutterOpenmoney();

Attach event listeners

The plugin uses event-based communication, and emits events when payment fails or succeeds.

The event names are exposed via the constants eventPaymentSuccess, eventPaymentError from the FlutterOpenmoney class.

Use the on(String event, Function handler) method on the FlutterOpenmoney instance to attach event listeners.


_flutterOpenmoney.on(FlutterOpenmoney.eventPaymentSuccess, _handlePaymentSuccess);
_flutterOpenmoney.on(FlutterOpenmoney.eventPaymentError, _handlePaymentError);

The handlers would be defined somewhere as


void _handlePaymentSuccess(PaymentSuccessResponse response) {
  // Do something when payment succeeds
}

void _handlePaymentError(PaymentFailureResponse response) {
  // Do something when payment fails
}

To clear event listeners, use the clear method on the FlutterOpenmoney instance.

_flutterOpenmoney.clear(); // Removes all listeners

Setup options

var options = PaymentOptions('<ACCESS_KEY_HERE>', '<PAYMENT_TOKEN_HERE>', PaymentMode.sandbox);

Checkout

_flutterOpenmoney.initPayment(options.toMap());

API

initPayment(Map<String, String> options)

The options is instance of PaymentOptions class The options has paymentToken and accessKey as a required property Convert options to Map object using options.toMap() method

on(String eventName, Function listener)

Register event listeners for payment events.

  • eventName: The name of the event.
  • listener: The function to be called. The listener should accept a single argument of the following type:

clear()

Clear all event listeners.

Error Codes

The error codes have been exposed as integers by the FlutterOpenmoney class.

The error code is available as the code field of the PaymentFailureResponse instance passed to the callback.

Error CodeDescription
invalidOptionsAn issue with options passed in FlutterOpenmoney.initPayment
paymentCancelledUser cancelled the payment
paymentFailedPayment process failed
unknownErrorAn unknown error occurred.

Event names

The event names have also been exposed as Strings by the Razorpay class.

Event NameDescription
eventPaymentSuccessThe payment was successful.
eventPaymentErrorThe payment was not successful.

PaymentSuccessResponse

Field NameTypeDescription
paymentIdStringThe ID for the payment.
paymentTokenIdStringThe payment token id.

To confirm payment details refer this link https://docs.bankopen.com/reference/status-check-api-with-token-id

PaymentFailureResponse

Field NameTypeDescription
codeintThe error code.
messageStringThe error message.

Libraries

flutter_openmoney
payment_options
payment_responses