pesepay 0.3.2 copy "pesepay: ^0.3.2" to clipboard
pesepay: ^0.3.2 copied to clipboard

Pesepay helps businesses in Africa get paid by anyone, anywhere in the world

Pesepay #

style: very good analysis Powered by Mason License: MIT

Pesepay helps businesses in Africa get paid by anyone, anywhere in the world

This is still WIP! Try out and contribute where you can.

Installation 💻 #

❗ In order to start using Pesepay you must have the Dart SDK installed on your machine.

Add pesepay to your pubspec.yaml:

dependencies:
  pesepay:

Install it:

dart pub get

Usage 🔥 #

Import package #

  import 'package:pesepay/pesepay.dart';

Declare and initialize #

final pesepay = Pesepay(
  integrationKey: '',
  encryptionKey: '',
  resultUrl: '',
  returnUrl: '',
);

Get list of active currencies #

final List<Currency> currencies = await Pesepay.getActiveCurrencies();

Sample Currency

Currency(
    name: Zimbabwe Dollar, 
    description: Zimbabwe Dollar, 
    code: ZWL, 
    defaultCurrency: false,
    rateToDefault: 604.25,
    active: true
)

Get list of payment methods for selected currency #

final List<PaymentMethod> methods = await Pesepay.getPaymentMethodsByCurrency(currency);

Sample PaymentMethod

PaymentMethod(
  active: true,
  code: PZW201,
  currencies: [ZWL], 
  description: Make payment directly from your mobile phone.,
  id: 1,
  maximumAmount: 50000.0,
  minimumAmount: 2.0, 
  name: Ecocash, 
  processingPaymentMessage: Please enter PIN on the phone that is making the payment.,
  redirectRequired: false, 
  redirectURL: null, 
  requiredFields: [
    RequiredField(
      displayName: Phone Number, 
      fieldType: TEXT, 
      name: customerPhoneNumber, 
      optional: false
    )
  ]
)

Perform Web Transaction #

This relies on the returned web redirectUrl that customers can use to complete the transaction

First step would be to create the transaction:

final Transaction transaction = pesepay.createTransaction(
  amount: 1,
  currencyCode: 'ZWL',
  transactionDescription: 'Bag of potatoes',
  transactionReference: '111-222-333'
)

Then process the transaction:

final TransactionResponse response = await pesepay.initiateWebTransaction(transaction);

If the above execution results in any error either within the package itself or from the Pesepay server side you should except a PesepayException. So it would be helpful to handle that.

Perform Seamless Transaction #

First step here would be to create the transaction:

final SeamlessTransaction seamlessTransaction = pesepay.createSeamlessTransaction(
  customerName: 'Cool Name',
  customerEmail: 'yourmail@email.com',
  customerPhone: '0777111111',
  amount: 1,
  currencyCode: 'ZWL',
  transactionDescription: 'Banana Peel',
  transactionReference: '111-222-333',
  paymentMethodCode: paymentMethodCode,
);

Process the seamless transaction:

final TransactionResponse response = await pesepay.initiateSeamlessTransaction(transaction);

Check transaction status #

final TransactionResponse response = await pesepay.checkTransactionStatus(pollUrl);

Serverless Checkout ? #

Instead of using delays to check transaction status you can also stream the TransactionResponse using the poll url.

  • pesepay.streamTransactionResponse(..) takes a required pollUrl string and optional streamInterval in seconds which is the interval to poll the url, default to 20 sec
  • You can stream status and show current transaction status on UI to user with a StreamBuilder(..) like below:
final String pollUrl = response.pollUrl;

// in Widget build(..) method
// you can do something like
StreamBuilder(
  stream: pesepay.streamTransactionResponse(pollUrl),
  builder: (context, AsyncSnapshot<TransactionResponse> snapshot) {
    if(snapshot.hasData) {
      final TransactionResponse response = snapshot.data!;
      return response.paid ? SuccessWidget() : OtherWidgetsForErrorOrWaiting();
    } else {
      return CircularProgressIndicator();
    }
  }
)

Full Usage Example #

void main() async {
  try {
    final pesepay = Pesepay(
      integrationKey: '',
      encryptionKey: '',
      resultUrl: '',
      returnUrl: '',
    );

    final Transaction transaction = pesepay.createTransaction(
      amount: 1,
      currencyCode: 'ZWL',
      transactionDescription: 'Bag of potatoes',
      transactionReference: '111-222-333'
    );

    final TransactionResponse response = await pesepay.initiateWebTransaction(transaction);

    // Add a delay before checking status, maybe 20-30 seconds
    await Future.delayed(const Duration(seconds: 30))

    // Check status
    final TransactionResponse pollResponse = await pesepay.checkTransactionStatus(response.pollUrl);

    if (pollResponse.paid) {
      // well you've done it
      print('I deserve drinks 🍻');
    } else {
      // not yet pal
      print('👎🏿')
    }

  } on PesepayException catch (e) {
    print(e.message);
  } catch (e) {
    // hell
  }
}

4
likes
130
pub points
0%
popularity

Publisher

verified publisheriamngoni.co.zw

Pesepay helps businesses in Africa get paid by anyone, anywhere in the world

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

dio, encrypt, freezed_annotation, json_annotation, localregex

More

Packages that depend on pesepay