【问题标题】:Django MPESA integration with C2B Till Number Payment and STK PushDjango MPESA 与 C2B Till Number Payment 和 STK Push 集成
【发布时间】:2019-10-27 15:28:39
【问题描述】:

我希望能够将 MPESA API C2B Till Number Payment 功能与 STK 推送集成到我正在开发的 Django Web 应用程序中,这样平台的用户就会收到一个 STK Push 通知来支付到till number 和事务通过模型存储在数据库中。

我看到人们在网上开发了一些框架,但大多数似乎都是为了满足支付账单而不是直到。任何可以帮助我做到这一点的框架帮助将不胜感激。

我发现 django 的官方文档很庞大,而且有点难以使用。

【问题讨论】:

    标签: python django api mpesa


    【解决方案1】:

    Paybill 号码和 Till 号码之间没有太大区别。根据 Safaricom 文档,对于 C2B Safaricom C2B API,paybill 短代码的命令 ID 是 CustomerPayBillOnline,而购买商品和服务的命令 ID 是 CustomerBuyGoodsOnline

    话虽如此,您可以在 Django 中为 STK 推送做这样的事情:

    def lipa_na_mpesa_online(request):
        access_token = MpesaAccessToken.validated_mpesa_access_token
        api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
        headers = {"Authorization": "Bearer %s" % access_token}
        request = {
            "BusinessShortCode": LipanaMpesaPpassword.Business_short_code,
            "Password": LipanaMpesaPpassword.decode_password,
            "Timestamp": LipanaMpesaPpassword.lipa_time,
            "TransactionType": "CustomerBuyGoodsOnline",
            "Amount": 1,
            "PartyA": 254708374149,  # replace with your phone number to get stk push
            "PartyB": LipanaMpesaPpassword.Business_short_code,
            "PhoneNumber": 254708374149,  # replace with your phone number to get stk push
            "CallBackURL": "https://sandbox.safaricom.co.ke/mpesa/",
            "AccountReference": "Henry",
            "TransactionDesc": "Testing stk push"
         }
    
         response = requests.post(api_url, json=request, headers=headers)
         return HttpResponse('success')
    

    【讨论】:

    • 在遇到教程 5 的错误后,您完成教程系列了吗?我有点放弃 STK 推送,因为我刚刚意识到它锁定了 android
    • 是的,我为 Paybill 做了一个教程,看看下面的内容,它会给你一个洞察力。 Python/Django Mpesa API Integration
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 2011-07-20
    • 2023-03-23
    • 2021-03-21
    • 2017-03-18
    • 2015-09-05
    相关资源
    最近更新 更多