Git Product home page Git Product logo

pypaystack's Introduction

PyPaystack

Build Status

This is a reusable python library that makes it very easy to hook up Paystack purchase button to your site/app. Framework specific integration e.g Django and Starlette are provided by default. The library also helps with verification of transactions and is highly configurable.

Usage:

  1. Install pypaystack
pip install -e git+https://github.com/gbozee/pypaystack.git@master#egg=paystack

Django Specific Setup

  1. Add paystack to your settings module
INSTALLED_APPS = [
    ...,
    paystack,

]
  1. Add url(r'^paystack/', include('paystack.urls',namespace='paystack')) to your base urls.py file
urlpatterns = [
    ...,
    url(r'^paystack/', include('paystack.urls',namespace='paystack')),
]

NB: for django 2.0 and above, your urls.py would look like this

   from django.url import path, include
urlpatterns = [
   ...,
   path("paystack", include(('paystack.urls','paystack'),namespace='paystack')),
]
  1. Login to Paystack settings Dashboard and fetch your PUBLIC_KEY and SECRET_KEY. paste these keys in your settings.py
# settings.py

PAYSTACK_PUBLIC_KEY=******,
PAYSTACK_SECRET_KEY=******

alt text

  1. In the html where you want to insert the payment button
{% load paystack %}
...
{% paystack_button amount=3000 email="[email protected]" %}

  1. A signal is provided with the verified reference as well as the amount
from paystack.signals import payment_verified

from django.dispatch import receiver

@receiver(payment_verified)
def on_payment_verified(sender, ref,amount, **kwargs):
    """
    ref: paystack reference sent back.
    amount: amount in Naira.
    """
    pass

Starlette Specific setup

Configurations

Required

PAYSTACK_PUBLIC_KEY

PAYSTACK_SECRET_KEY

Optional

PAYSTACK_FAILED_URL # Redirect url when payment fails, default is paystack:failed_url

PAYSTACK_SUCCESS_URL # Redirect url when payment is successful, default is paystack:success_url

PAYSTACK_LIB_MODULE # module directory to overide default implemenation of library that calls paystack api, default is paystack.utils

Template Tag Usage

the template tag paystack_button takes the following argument

button_class: css class to style the button

button_id: id name for the button: default is "django-paystack-button"

email: a required field representing the email

amount: a required the amount to be paid in Naira. `

ref: an optional field representing the reference of the transaction`

redirect_url: an optional field representing the redirect url after payment has been made, defaults to paystack:verify_payment

NB: *If you prefer using css to style html tags, the id of the button is *

To view the sample test project, do the following

$ git clone https://github.com/gbozee/django-paystack.git
$ git checkout develop
$ pip install -r requirements.txt
$ pip install -e .

NB: If you use pipenv, do the following

$ pipenv install

To run the project

$ cd django_paystack
$ python manage.py runserver

alt text

alt text

alt text

Extending

The default templates used can be extended to include your custom content.

  1. Create a paystack directory in your templates folder.

The templates used are as follows.

paystack/failed-page.html
paystack/success-page.html

Webhook.

In order to listen and respond to events that happen from the paystack dashboard on your site, you are required as a developer to provide a publicly available url as a webhook.

This library provides the webhook url and exposes a signal for you to listen to and respond to any event sent by paystack

from paystack.signals import event_signal
from django.dispatch import receiver

@reciever(event_signal)
def on_event_received(sender, event, data):
   # sender is the raw request
   # event is the event name that was passed https://developers.paystack.co/docs/events
   # data is the available data tied to the event
   pass

You would need to register the following url http://<domain_name>/paystack/webhook/

whatever your <domain_name> is, you would need to set it to PAYSTACK_WEBHOOK_DOMAIN in your settings.py

for example, assuming you are using ngrok during development, in your settings.py add the following config

PAYSTACK_WEBHOOK_DOMAIN=13232323.ngrok.io

and your webhook url that you would paste at paystack dashboard would be http://13232323.ngrok.io/paystack/webhook/

pypaystack's People

Contributors

akohrr avatar gbozee avatar olamyy avatar timtech4u avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pypaystack's Issues

How to track item being paid for

Good day.. i love the django-paytsack app you made, it makes it pretty easy to use paystack with django, i have just one issue. how do i know the item that's being paid for on my site. is there a provision for that in your code?

Pypaystack verification fails.

After making a successful payment with paystack test accounts and api, the verification fails and results in me getting redirected to the failed page.

However, when I try to manually verify the payment, it works successfully and I even receive emails and see the transaction in my dashboard.

How do i fix this

Successful Payment raises a DisallowedRedirect error.

After successful payments, the success page redirect seems to get stuck at a point and raises a

DisallowedRedirect at /payment/successful-verification/2ZDJZRF5VF5N/

error.
My current paystack settings contains:
PAYSTACK_SECRET_KEY = env("PAYSTACK_SECRET_KEY", default="default_private_key")

PAYSTACK_PUBLIC_KEY = env("PAYSTACK_PUBLIC_KEY", default="default_public_key")

PAYSTACK_FAILED_URL = "dashboard:billing_failure"

PAYSTACK_SUCCESS_URL = "dashboard:billing_success"

djangopaystack

ModuleNotFoundError: No module named 'paystack.frameworks'

i got a ModuleNotFoundError: No module named 'paystack.frameworks' and ModuleNotFoundError: No module named 'paystack'

while follow previous suggestions and your blog site.seems this package has not been updated for the past 14 months now.is this package still ideal to be used??

Webhook error

i tried to use the webhook as given in the readme, got this error below, how do i fix this.
KeyError at /paystack/webhook/
'HTTP_X_PAYSTACK_SIGNATURE'

ModuleNotFoundError: No module named 'paystack.urls'

Hello,
I've followed the steps listed in the README, but, I can't seem to get it properly installed. I have tried the pip install way, and I have tried to install using the setup.py, but it does not work. I have also included it in my urls and settings file.

Any help would be appreciated.

ModuleNotFoundError: No module named 'paystack.urls'

Hello, i have done everything in the ReadMe and still get this error, i am using a virtual environment and i have also swapped ' paystack ' to ' paystack.frameworks.django ' in the settings.py. I have also started a new project and used pipenv to install instead of pip in the documentation but i still get this error. Thanks in advance

I am encountering problems installing this module

WARNING: Generating metadata for package paystack produced metadata for project name pypaystack. Fix your #egg=paystack fragments.
WARNING: Discarding git+https://github.com/gbozee/pypaystack.git@master#egg=paystack. Requested pypaystack from git+https://github.com/gbozee/pypaystack.git@master#egg=paystack has inconsistent name: filename has 'paystack', but metadata has 'pypaystack'
ERROR: Could not find a version that satisfies the requirement paystack (unavailable)
ERROR: No matching distribution found for paystack (unavailable)

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.