mymi14s / django-paystack Goto Github PK
View Code? Open in Web Editor NEWDjango Paystack Payment
Home Page: https://www.ghorz.com
License: MIT License
Django Paystack Payment
Home Page: https://www.ghorz.com
License: MIT License
I ask ChatGpt to write a program like this:
I want my customer to be able to pay 10,000 Naira every months, if they doesn't, I don't want them to use anything on the website, or if their bank card has expired, I want to shows them an error messages or redirecting them to a checkout page where they can add their active card information. Using django and paystack.
It's gives me this:
import paystack
from django.conf import settings
from django.shortcuts import redirect
from django.urls import reverse
from django.contrib import messages
paystack.api_key = settings.PAYSTACK_SECRET_KEY
def check_payment(request):
# Check if the user has paid for the current month
today = datetime.date.today()
amount = 10000
reference = f"{request.user.id}-{today.year}-{today.month}"
try:
transaction = paystack.Transaction.verify(reference)
if transaction['status'] == 'success' and transaction['amount'] == amount * 100:
return True
except paystack.Error:
pass
return False
def payment_required(view_func):
def wrapper(request, *args, **kwargs):
if check_payment(request):
return view_func(request, *args, **kwargs)
else:
messages.error(request, "You need to pay 10,000 Naira to access this page.")
return redirect(reverse('checkout'))
return wrapper
def checkout(request):
# Show a form for the user to enter their payment details
if request.method == 'POST':
card_number = request.POST['card_number']
expiry_month = request.POST['expiry_month']
expiry_year = request.POST['expiry_year']
cvv = request.POST['cvv']
amount = 10000
reference = f"{request.user.id}-{datetime.date.today().year}-{datetime.date.today().month}"
response = paystack.Transaction.initialize(
amount=amount*100,
email=request.user.email,
reference=reference,
metadata={
'user_id': request.user.id,
},
card={
'number': card_number,
'expiry_month': expiry_month,
'expiry_year': expiry_year,
'cvv': cvv,
},
)
return redirect(response['data']['authorization_url'])
else:
return render(request, 'checkout.html')```
As a developer, Using ChatGpt for coding is helpful sometimes, I knew chatGpt return a code that doesn't work sometimes. I want you to look at this code generated by chatGpt and told me where it is wrong sir.
I want to use paystack for subscription, but the one you gives doesn't match with what I want.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.