Code Monkey home page Code Monkey logo

django-paystack's People

Contributors

mymi14s avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ajadi473

django-paystack's Issues

Paystack for Monthly subscription

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.