Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
godfredtenkorang committed Dec 18, 2024
1 parent 2f4a445 commit 98c5dc9
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 42 deletions.
Binary file modified payment/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified ussd/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified ussd/__pycache__/views.cpython-312.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion ussd/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
urlpatterns = [
path('ussd/', views.ussd_api, name='ussd'),
path('callback/', views.payment_callback, name='payment_callback'),
path('paystack/webhook/', views.paystack_webhook, name='paystack_webhook'),
]
40 changes: 0 additions & 40 deletions ussd/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,43 +235,3 @@ def payment_callback(request):

return JsonResponse({'status': 'error', 'message': 'Invalid request method'}, status=405)



import json
import hashlib
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .models import PaymentTransaction

@csrf_exempt
def paystack_webhook(request):
if request.method == 'POST':
try:
# Parse the JSON payload from Paystack
payload = json.loads(request.body.decode('utf-8'))
event = payload.get('event') # The event type (e.g., charge.success)
data = payload.get('data') # Payment data

if event == 'charge.success':
transaction_id = data.get('reference') # Paystack reference
amount_paid = data.get('amount') / 100 # Convert to original currency (in cedis)
customer_email = data.get('customer', {}).get('email', None)
status = data.get('status') # Should be 'success'

# Update your PaymentTransaction model
PaymentTransaction.objects.filter(transaction_id=transaction_id).update(
status=status,
amount=amount_paid
)

# You could perform additional actions like sending notifications

return JsonResponse({'status': 'success'}, status=200)
else:
# Handle other Paystack events like 'charge.failed', etc.
return JsonResponse({'status': 'ignored', 'message': 'Unhandled event'}, status=400)

except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)}, status=400)

return JsonResponse({'status': 'error', 'message': 'Invalid request method'}, status=405)
Binary file modified votehere/__pycache__/settings.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion votehere/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
# proxies = {
# "http": QUOTAGUARDSTATIC_URL,
# "https": QUOTAGUARDSTATIC_URL
# }
#

# res = requests.get("http://us-east-static-09.quotaguard.com", proxies=proxies)
# print(res.text)
Expand Down

0 comments on commit 98c5dc9

Please sign in to comment.