Skip to content

Commit

Permalink
Update URLs in documentation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmogusu committed Jan 3, 2023
1 parent 1159a26 commit 9b2d959
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
8 changes: 4 additions & 4 deletions docs/pages/apis/b2c_payment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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.
- 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
7 changes: 3 additions & 4 deletions docs/pages/apis/stk_push.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
4 changes: 2 additions & 2 deletions docs/pages/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
22 changes: 8 additions & 14 deletions docs/pages/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,24 @@ 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:
.. code-block:: python
: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
Expand All @@ -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
-----------------
Expand Down

0 comments on commit 9b2d959

Please sign in to comment.