Skip to content

Commit

Permalink
Add model fields to PaymentTransaction Admin View (#4)
Browse files Browse the repository at this point in the history
* TCW add extra fields to PaymentTransaction Admin View

* Move safaricom-api to .env (#1)
  • Loading branch information
muneneevans authored Aug 26, 2020
1 parent 7bb6da6 commit 56ff29d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ venv.bak/
# mypy
.mypy_cache/
.idea*
.vscode
37 changes: 37 additions & 0 deletions api.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@host =http://localhost:8000
@phoneNumber=2547XXXXXXXX


###
# @name requestSTKPush
POST {{host}}/mpesa/submit/ HTTP/1.1
content-type: application/json

{
"phone_number":{{phoneNumber}},
"amount": 1,
"entity_id":1
}


###
# @name checkTransactionFromMPESA
POST {{host}}/mpesa/check-online/ HTTP/1.1
content-type: application/json

{
"transaction_id" : 4
}


###
# @name checkTransactionlocally
POST {{host}}/mpesa/check-transaction/ HTTP/1.1
content-type: application/json

{
"transaction_id" : 4
}



3 changes: 2 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONSUMER_KEY=[consumer_key]
CONSUMER_SECRET=[consumer secret from daraja]
HOST_NAME=[host name]
CERTIFICATE_FILE=[path to certifiate file]
CERTIFICATE_FILE=[path to certifiate file]
SAFARICOM_API=http://sandbox.safaricom.co.ke
7 changes: 6 additions & 1 deletion mpesa/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
from .models import PaymentTransaction, Wallet

# Register your models here.
admin.site.register(PaymentTransaction)

class PaymentTransactionAdmin(admin.ModelAdmin):
list_display = ("phone_number", "amount", "isFinished",
"isSuccessFull", "trans_id", 'date_created','date_modified')

admin.site.register(PaymentTransaction, PaymentTransactionAdmin)
admin.site.register(Wallet)
9 changes: 5 additions & 4 deletions mpesa/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
HOST_NAME = os.environ.get('HOST_NAME')
PASS_KEY = os.environ.get('PASS_KEY')
shortcode = os.environ.get('SHORT_CODE')
SAFARICOM_API = os.environ.get('SAFARICOM_API')


def encryptInitiatorPassword():
Expand All @@ -49,7 +50,7 @@ def generate_pass_key(cipher):


def get_token():
api_URL = "https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials"
api_URL = "{}/oauth/v1/generate?grant_type=client_credentials".format(SAFARICOM_API)

r = requests.get(api_URL, auth=HTTPBasicAuth(consumer_key, consumer_secret))
jonresponse = json.loads(r.content)
Expand All @@ -59,7 +60,7 @@ def get_token():


def register_url(access_token):
api_url = "http://sandbox.safaricom.co.ke/mpesa/c2b/v1/registerurl"
api_url = "{}/mpesa/c2b/v1/registerurl".format(SAFARICOM_API)
headers = {
"Authorization": "Bearer %s" % access_token,
"Content-Type": "application/json",
Expand All @@ -83,7 +84,7 @@ def sendSTK(phone_number, amount, orderId=0, transaction_id=None):
s = shortcode + PASS_KEY + time_now
encoded = b64encode(s.encode('utf-8')).decode('utf-8')

api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
api_url = "{}/mpesa/stkpush/v1/processrequest".format(SAFARICOM_API)
headers = {
"Authorization": "Bearer %s" % access_token,
"Content-Type": "application/json",
Expand Down Expand Up @@ -128,7 +129,7 @@ def check_payment_status(checkout_request_id):
s = shortcode + PASS_KEY + time_now
encoded = b64encode(s.encode('utf-8')).decode('utf-8')

api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpushquery/v1/query"
api_url = "{}/mpesa/stkpushquery/v1/query".format(SAFARICOM_API)
headers = {
"Authorization": "Bearer %s" % access_token,
"Content-Type": "application/json",
Expand Down

0 comments on commit 56ff29d

Please sign in to comment.