将Mpesa和AirtelMoney等移动货币与Android应用程序整合

在肯尼亚,现在蔓延到非洲和世界其他地方,我们有一种惊人的方式,通过手机创造移动货币来发送和接收资金。 两家领先的服务提供商Safaricom和Airtel分别拥有移动货币平台Mpesa和AirtelMoney。

由于肯尼亚没有Google Merchant服务,并且使用它们会使潜在消费者望而却步,我一直在考虑使用Mpesa和AirtelMoney将我的应用程序卖给用户。 现在,只要发生交易,Mobile Money服务都会向发送方和接收方发送确认文本消息。

现在我将如何在我的应用程序上使用此服务,因为我没有成功使用可用的api,其中使用web平台和其他技术。 并非我的所有用户每天都使用互联网,因为我的用户是教会成员使用的应用程序。 但他们肯定会每天使用手机钱。 我将不胜感激。

我希望我的应用程序能够在用户通过Mpesa付款时从试用版更改为高级版,因为与web apis相比,它似乎更容易使用短信

我遇到了类似的问题,并决定使用短信来实现这一目标。 首先,我使用权限允许我这样做:

         

在我的IncomingMessage活动中,我添加了以下代码:

 package com.example.myapp; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.util.Log; import android.widget.Toast; @SuppressLint("ShowToast") public class IncomingMessage extends BroadcastReceiver { final SmsManager sms = SmsManager.getDefault(); public void onReceive(Context paramContext, Intent paramIntent) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(paramContext.getApplicationContext()).edit(); if (!PreferenceManager.getDefaultSharedPreferences(paramContext.getApplicationContext()).getBoolean("js_vsb_is_paid", false)) { Bundle localBundle = paramIntent.getExtras(); if (localBundle != null) {} for (;;) { int i; String sender; String message; try { Object[] arrayOfObject = (Object[])localBundle.get("pdus"); i = 0; if (i >= arrayOfObject.length) { return; } SmsMessage localSmsMessage = SmsMessage.createFromPdu((byte[])arrayOfObject[i]); sender = localSmsMessage.getDisplayOriginatingAddress(); message = localSmsMessage.getDisplayMessageBody(); Log.i("SmsReceiver", "senderNum: " + sender + "; message: " + message); if (sender.equalsIgnoreCase("MPESA")) { if (message.contains("JACKSON SIRO")) { editor.putBoolean("app_is_paid", true); editor.commit(); //Toast.makeText(paramContext, "App Has been Activated!", Toast.LENGTH_LONG).show(); } } else if (sender.equalsIgnoreCase("AirtelMoney")) { if (message.contains("JACKSON SIRO")) { editor.putBoolean("app_is_paid", true); editor.commit(); //Toast.makeText(paramContext, "App Has been Activated!", Toast.LENGTH_LONG).show(); } } } catch (Exception localException) { Log.e("SmsReceiver", "Exception smsReceiver" + localException); return; } } } } 

我希望这有帮助。 代码很简单,也许你会修改它以满足你的需要

Safaricom已将M-Pesa API作为RESTful API发布,可通过其开发人员门户访问。

Safaricom github 存储库 ,有一个使用“Lipa na M-Pesa Online” API的示例android应用程序 。 此API代表应用用户启动M-Pesa交易,用户只需输入其M-Pesa PIN即可完成交易。