dart_mpesa

该库包含易于使用 Mpesa API 的方法。它是跨平台的,支持 CLI、服务器、移动、桌面和浏览器。

可用的方法/API 包括

  • [x] LIPA NA MPESA
  • [x] STKPUSH 查询
  • [x] C2BSIMULATE
  • [x] B2B
  • [x] B2C
  • [x] C2B
  • [x] 交易状态
  • [x] 账户余额
  • [x] 撤销

用法

创建 Mpesa 实例,然后使用其方法来使用 API

import 'package:dart_mpesa/dart_mpesa.dart';

main() {
  var mpesa = Mpesa(
    shortCode: "",
    consumerKey: "",
    consumerSecret: "",
    initiatorName: "",
    securityCredential: "",
    passKey: "",
    identifierType: IdentifierType.OrganizationShortCode, // Type of organization, options, OrganizationShortCode, TillNumber, OrganizationShortCode
    applicationMode: ApplicationMode.test
  );
}

在线支付(lipa na mpesa online)

在线支付 API(LIPA NA M-PESA ONLINE API),也称为 M-PESA Express(STK Push),是由商家/企业发起的 C2B(客户到企业)支付。

  MpesaResponse _res = await mpesa.lipanaMpesaOnline(
    phoneNumber: "",
    amount: 0,
    accountReference: "",
    transactionDesc: "",
    callBackURL: "", 
  );

  print(_res.statusCode);
  print(_res.rawResponse);
  print(_res.responseDescription);

B2B

企业对企业 (B2B) API 用于将资金从一个企业转移到另一个企业。

  _res = await mpesa.b2bTransaction(
    shortCode: "",
    amount: 0,
    remarks: "",
    accountReference: "", // optional
    resultURL: "", 
    queueTimeOutURL: "",
    identifierType: IdentifierType.OrganizationShortCode, // options, OrganizationShortCode, TillNumber, OrganizationShortCode
    commandID: BbCommandId.BusinessToBusinessTransfer, // options, BusinessToBusinessTransfer, BusinessPayBill, BusinessBuyGoods, DisburseFundsToBusiness, MerchantToMerchantTransfer
  );

B2B 购物

将资金从一个组织的运营账户转移到另一个组织的商家账户。

  _res = await mpesa.b2bBuyGoodsTransaction(
    shortCode: "",
    amount: 0,
    remarks: "",
    resultURL: "", 
    queueTimeOutURL: "",
  );

获取 token

  try{
    _res = await mpesa.fetchToken;
    print(_res['token'])
  }catch(e){
    print(e)
  }

有关更多信息,请参阅示例或文档

GitHub

https://github.com/EddieKamau/dart_mpesa