diff --git a/README.md b/README.md index eccfc47..764cc24 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,12 @@ An example, to send an STK push prompt to customer phone, then display response amount = 1 account_reference = 'reference' transaction_desc = 'Description' - callback_url = request.build_absolute_uri(reverse('mpesa_stk_push_callback')) + callback_url = 'https://api.darajambili.com/express-payment' response = cl.stk_push(phone_number, amount, account_reference, transaction_desc, callback_url) return HttpResponse(response) ``` -On your browser, you will receive a message `Success. Request accepted for processing` on success of the STK push. You will also receive a notification on the callback endpoint (In this case the URL with the name `mpesa_stk_push_callback`), having the results of the STK push. +On your browser, you will receive a message `Success. Request accepted for processing` on success of the STK push, and on the phone number specified you will receive an MPESA PIN prompt. Once the transaction is complete, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. https://api.darajambili.com/express-payment), you can head over to https://darajambili.com to view the notification received ### B2C Payment @@ -57,16 +57,12 @@ An example, to perform a BusinessPayment B2C (Business to Customer) transaction amount = 1 transaction_desc = 'Business Payment Description' occassion = 'Test business payment occassion' - callback_url = request.build_absolute_uri(reverse('mpesa_business_payment_callback')) + callback_url = 'https://api.darajambili.com/b2c/result' response = cl.business_payment(phone_number, amount, transaction_desc, callback_url, occassion) return HttpResponse(response) ``` -On your browser, you will receive a message `Accept the service request successfully.` on success of the transaction. You will also receive a notification on the callback endpoint (In this case the URL with the name `mpesa_business_payment_callback`), having the results of the Business Payment Transaction. - -## Note - -You need a callback URL connected to the internet to receive the asynchronous result. In case you don't have one you can head over to https://darajambili.com and grab a callback URL to test the result. +On your browser, you will receive a message `Accept the service request successfully.` on success of the transaction. Once the transaction is complete, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. https://api.darajambili.com/b2c/result), you can head over to https://darajambili.com to view the notification received The full documentation of all supported API's can be found at https://django-daraja.readthedocs.io diff --git a/docs/pages/apis/b2c_payment.rst b/docs/pages/apis/b2c_payment.rst index e768e3f..9923b23 100644 --- a/docs/pages/apis/b2c_payment.rst +++ b/docs/pages/apis/b2c_payment.rst @@ -25,7 +25,7 @@ Business Payment amount = 1 transaction_desc = 'Description' occassion = 'Occassion' - callback_url = request.build_absolute_uri(reverse('mpesa_business_payment_callback')) + callback_url = 'https://api.darajambili.com/b2c/result' response = self.cl.business_payment(phone_number, amount, transaction_desc, self.callback_url, occassion) Salary Payment @@ -39,7 +39,7 @@ Salary Payment amount = 1 transaction_desc = 'Description' occassion = 'Occassion' - callback_url = request.build_absolute_uri(reverse('mpesa_salary_payment_callback')) + callback_url = 'https://api.darajambili.com/b2c/result' response = self.cl.business_payment(phone_number, amount, transaction_desc, self.callback_url, occassion) Promotion Payment @@ -53,7 +53,7 @@ Promotion Payment amount = 1 transaction_desc = 'Description' occassion = 'Occassion' - callback_url = request.build_absolute_uri(reverse('mpesa_promotion_payment_callback')) + callback_url = 'https://api.darajambili.com/b2c/result' response = self.cl.promotion_payment(phone_number, amount, transaction_desc, self.callback_url, occassion) @@ -62,4 +62,4 @@ This will assign the ``response`` variable with an ``MpesaResponse`` object cont .. note:: - Test credentials to use for this scenario can be found at the developer portal (https://developer.safaricom.co.ke/test_credentials) - Use `shortcode 1` as the shortcode, and the test MSISDN as the B2C phone number - - This example will work if your site is already hosted, since the callback URL needs to be accessible via internet. For local testing purposes, you can use an endpoint hosted outside your site to check the notification received on the callback URL. There is a test listener hosted at https://darajambili.com, which you can use to view logs of notifications received. You can head over there to pick a callback URL to use for B2C Payments. \ No newline at end of file + - Once the transaction is complete, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. https://api.darajambili.com/b2c/result), you can head over to https://darajambili.com to view the notification received \ No newline at end of file diff --git a/docs/pages/apis/stk_push.rst b/docs/pages/apis/stk_push.rst index 8bfdcff..07523fb 100644 --- a/docs/pages/apis/stk_push.rst +++ b/docs/pages/apis/stk_push.rst @@ -15,12 +15,11 @@ Example: amount = 1 account_reference = 'reference' transaction_desc = 'Description' - callback_url = request.build_absolute_uri(reverse('mpesa_stk_push_callback')) + callback_url = 'https://api.darajambili.com/express-payment' response = cl.stk_push(phone_number, amount, account_reference, transaction_desc, callback_url) This will assign the ``response`` variable with an ``MpesaResponse`` object containing the response returned from the STK Push API call. .. note:: - - Use a Safaricom number that you have access to for the ``phone_number`` parameter, so as to be able to receive the prompt on your phone. - - You will need to define a url with the name ``mpesa_stk_push_callback``, and this is where MPESA will send the results of the STK push once the customer enters the PIN or cancels the transaction, or in case the prompt times out. - - This example will work if your site is already hosted, since the callback URL needs to be accessible via internet. For local testing purposes, you can use an endpoint hosted outside your site to check the notification received on the callback URL. There is a test listener hosted at https://darajambili.com, which you can use to view logs of notifications received. You can head over there to pick a callback URL to use for STK push. \ No newline at end of file + - Use a Safaricom number that you have access to for the ``phone_number`` parameter, so as to be able to receive the M-PESA prompt on your phone. + - Once you have entered the PIN, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. https://api.darajambili.com/express-payment), you can head over to https://darajambili.com to view the notification received. \ No newline at end of file diff --git a/docs/pages/introduction.rst b/docs/pages/introduction.rst index 9734bdc..64e7f03 100644 --- a/docs/pages/introduction.rst +++ b/docs/pages/introduction.rst @@ -30,8 +30,8 @@ An example, to send an STK push prompt to customer phone, then display response amount = 1 account_reference = 'reference' transaction_desc = 'Description' - callback_url = request.build_absolute_uri(reverse('mpesa_stk_push_callback')) + callback_url = 'https://api.darajambili.com/express-payment' response = cl.stk_push(phone_number, amount, account_reference, transaction_desc, callback_url) return HttpResponse(response) -On your browser, you will receive the API response message. You will also receive a notification on the callback endpoint (In this case the URL with the name ``mpesa_stk_push_callback``), having the results of the STK push. \ No newline at end of file +On your browser, you will receive the API response message and on the phone number specified you will receive an MPESA PIN prompt. Once you have entered the PIN, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. https://api.darajambili.com/express-payment), you can head over to https://darajambili.com to view the notification received. \ No newline at end of file diff --git a/docs/pages/quick_start.rst b/docs/pages/quick_start.rst index ec9bce7..d8baaa0 100644 --- a/docs/pages/quick_start.rst +++ b/docs/pages/quick_start.rst @@ -137,12 +137,12 @@ Python 2: :caption: my_app/urls.py :name: my_app_urls_python_2 - from django.urls import re_path as url, include + from django.urls import re_path as url + from . import views urlpatterns = [ - url(r'^$', views.index, name='index'), - url(r'^daraja/stk-push$', views.stk_push_callback, name='mpesa_stk_push_callback'), + url(r'^$', views.index, name='index') ] Python 3: @@ -150,12 +150,11 @@ Python 3: :caption: my_app/urls.py :name: my_app_urls_python_3 - from django.urls import path, include + from django.urls import path from . import views urlpatterns = [ - path('', views.index, name='index'), - path('daraja/stk-push', views.stk_push_callback, name='mpesa_stk_push_callback'), + path('', views.index, name='index') ] 7. Create a view @@ -178,18 +177,13 @@ In ``my_app/views.py`` Create a test index view amount = 1 account_reference = 'reference' transaction_desc = 'Description' - callback_url = request.build_absolute_uri(reverse('mpesa_stk_push_callback')) + callback_url = 'https://api.darajambili.com/express-payment' response = cl.stk_push(phone_number, amount, account_reference, transaction_desc, callback_url) return HttpResponse(response) - def stk_push_callback(request): - data = request.body - # You can do whatever you want with the notification received from MPESA here. - .. note:: - - Use a Safaricom number that you have access to for the ``phone_number`` parameter, so as to be able to receive the prompt on your phone. - - You will need to define a url with the name ``mpesa_stk_push_callback``, and this is where MPESA will send the results of the STK push once the customer enters the PIN or cancels the transaction, or in case the prompt times out. - - This example will work if your site is already hosted, since the callback URL needs to be accessible via internet. For local testing purposes, you can use an endpoint hosted outside your site to check the notification received on the callback URL. There is a test listener hosted at https://darajambili.com, which you can use to view logs of notifications received. You can head over there to pick a callback URL to use for STK push. + - Use a Safaricom number that you have access to for the ``phone_number`` parameter, so as to be able to receive the M-PESA prompt on your phone. + - Once you have entered the PIN, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. https://api.darajambili.com/express-payment), you can head over to https://darajambili.com to view the notification received. 8. Run Migrations -----------------