pub package

Flutter MobilePay payment

A Flutter plugin for integrating Scandinavian payment provider MobilePay.

Only Android support for now.

Usage

Install the package by adding the line flutter_mobilepay_payment: ^0.1.0 to pubspec.yaml and run flutter packages get.

Import it in main.dart;

import 'package:flutter_mobilepay_payment/flutter_mobilepay_payment.dart';

and once in your app, initialize a AppSwitchPayment instance:

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  static AppSwitchPayment _mobilePay = AppSwitchPayment(
      "APPDK0000000000", Country.Denmark,
      captureType: CaptureType.Reserve);

  @override
  _MyAppState createState() => _MyAppState(_mobilePay);
}

Then do a payment like this:

final payment = await mobilePay.pay("86715c57-8840-4a6f-af5f-07ee89107ece", 10.0);

If payment is null, that means that the payment was cancelled, i.e. the user backed out. If an error occurs, an exception will be thrown with the corresponding error code. Otherwise, the payment object will contain the paid amount and the transaction ID.

At this point you would want to process the payment, e.g. by sending the order ID and transaction ID to your backend. When the process completes succesfully, call

await payment.complete();

If the app fails to process the payment, or even if it crashes after returning from AppSwitch, the uncompleted payment will be accessible through

final payment = await incompletePayment();

You should check for that when your app starts, and if it is non-null, resume the app in the state where it is processing the payment.

MobilePay

The plugin has MobilePay AppSwitch SDK v. 1.8.1 built in. See here if it's the latest one.

Troubleshooting

Q: I got a lovely java.lang.AbstractMethodError (no error message) from gradle after installing the package. A: That's been seen when using Kotlin 1.2.50, and it was fixed by upgrading to 1.2.60.

Flutter

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Libraries

flutter_mobilepay_payment

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]