webirr 1.1.1 copy "webirr: ^1.1.1" to clipboard
webirr: ^1.1.1 copied to clipboard

Official Dart Client Library for WeBirr Payment Gateway APIs. This Library provides convenient access to WeBirr Payment Gateway APIs from Dart/Flutter Apps.

example/lib/example.dart

import 'dart:io';

import 'package:webirr/webirr.dart';

/// Creating a new Bill / Updating an existing Bill on WeBirr Servers
void main() async {
  final apiKey =
      Platform.environment['WEBIRR_TEST_ENV_API_KEY'] ?? 'YOUR_API_KEY';
  final merchantId =
      Platform.environment['WEBIRR_TEST_ENV_MERCHANT_ID'] ?? 'YOUR_MERCHANT_ID';

  final api =
      WeBirrClient(merchantId: merchantId, apikey: apiKey, isTestEnv: true);

  final bill = Bill(
    amount: '270.90',
    customerCode:
        'cc01', // it can be email address or phone number if you dont have customer code
    customerName: 'Elias Haileselassie',
    customerPhone: '0911000000',
    time: '2021-07-22 22:14', // your bill time, always in this format
    description: 'hotel booking',
    billReference: 'drt/2021/125', // your unique reference number
    extras: <String, dynamic>{},
  );

  print('Creating Bill...');
  var res = await api.createBill(bill);

  var paymentCode = '';

  if (res.error == null) {
    // success
    paymentCode = res.res ?? ''; // returns paymentcode such as 429 723 975
    print(
        'Payment Code = $paymentCode'); // we may want to save payment code in local db.
  } else {
    // fail
    print('error: ${res.error}');
    print(
        'errorCode: ${res.errorCode}'); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT_DUP_REF
  }

  // update existing bill if it is not paid
  bill.amount = '278.00';
  bill.customerName = 'Elias dart';
  //bill.billReference = "WE CAN NOT CHANGE THIS";

  print('Updating Bill...');
  res = await api.updateBill(bill);

  if (res.error == null) {
    // success
    print(
        'bill is updated succesfully'); //res.res will be 'OK'  no need to check here!
  } else {
    // fail
    print('error: ${res.error}');
    print(
        'errorCode: ${res.errorCode}'); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
  }

  api.close();
}
3
likes
0
points
776
downloads

Publisher

unverified uploader

Weekly Downloads

Official Dart Client Library for WeBirr Payment Gateway APIs. This Library provides convenient access to WeBirr Payment Gateway APIs from Dart/Flutter Apps.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http

More

Packages that depend on webirr