Giter Club home page Giter Club logo

django-getpaid-payu's Introduction

Latest PyPI version

Welcome to django-getpaid

django-getpaid is payment processing framework for Django

Documentation

The full documentation is at https://django-getpaid.readthedocs.io.

Features

  • support for multiple payment brokers at the same time
  • very flexible architecture
  • support for asynchronous status updates - both push and pull
  • support for modern REST-based broker APIs
  • support for multiple currencies (but one per payment)
  • support for global and per-plugin validators
  • easy customization with provided base abstract models and swappable mechanic (same as with Django's User model)

Quickstart

Install django-getpaid and at least one payment backend:

pip install django-getpaid
pip install django-getpaid-payu

Define an Order model by subclassing getpaid.abstracts.AbstractOrder and define some required methods:

from getpaid.abstracts import AbstractOrder

class MyCustomOrder(AbstractOrder):
    amount = models.DecimalField(decimal_places=2, max_digits=8)
    description = models.CharField(max_length=128)
    buyer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    def get_absolute_url(self):
        return reverse('order-detail', kwargs={"pk": self.pk})

    def get_total_amount(self):
        return self.amount

    def get_buyer_info(self):
        return {"email": self.buyer.email}

    def get_currency(self):
        return "EUR"

    def get_description(self):
        return self.description

Note

If you already have an Order model and don't want to subclass AbstractOrder just make sure you implement all methods.

Inform getpaid of your Order model in settings.py and provide settings for payment backends:

GETPAID_ORDER_MODEL = 'yourapp.MyCustomOrder'

GETPAID_BACKEND_SETTINGS = {
    "getpaid_payu": {
        # take these from your merchant panel:
        "pos_id": 12345,
        "second_key": "91ae651578c5b5aa93f2d38a9be8ce11",
        "oauth_id": 12345,
        "oauth_secret": "12f071174cb7eb79d4aac5bc2f07563f",
    },
}

Create a migration for your model BEFORE adding getpaid to INSTALLED_APPS:

./manage.py makemigrations

Add getpaid and broker plugin to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'getpaid',
    'getpaid_payu',  # one of plugins
    ...
]

Migrate the database:

./manage.py migrate

Add getpaid to URL patterns:

urlpatterns = [
    ...
    path('payments/', include('getpaid.urls')),
    ...
]

Write a view that will create the Payment.

An example view and its hookup to urls.py can look like this:

# orders/views.py
from getpaid.forms import PaymentMethodForm

class OrderView(DetailView):
    model = Order

    def get_context_data(self, **kwargs):
        context = super(OrderView, self).get_context_data(**kwargs)
        context["payment_form"] = PaymentMethodForm(
            initial={"order": self.object, "currency": self.object.currency}
        )
        return context

# main urls.py

urlpatterns = [
    # ...
    path("order/<int:pk>/", OrderView.as_view(), name="order_detail"),
]

You'll also need a template (order_detail.html in this case) for this view. Here's the important part:

<h2>Choose payment broker:</h2>
<form action="{% url 'getpaid:create-payment' %}" method="post">
    {% csrf_token %}
    {{ payment_form.as_p }}
    <input type="submit" value="Checkout">
</form>

Running Tests

poetry install
poetry run tox

Alternatives

Credits

Created by Krzysztof Dorosz. Redesigned and rewritten by Dominik Kozaczko.

Development of version 2.0 sponsored by SUNSCRAPERS

Disclaimer

This project has nothing in common with getpaid plone project.

django-getpaid-payu's People

Contributors

dekoza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-getpaid-payu's Issues

continueUrl not implemented

  • django-getpaid version: 2.2.1
  • django-getpaid-payu version: 0.2.0
  • Django version: 3.0.6
  • Python version: 3.6
  • Operating System: Ubuntu 18.04

Description

As far as I checked your code. continueUrl is not implemented at all.

It would be great to implement it. eg. 127.0.0.1:8000/order-complete/uuid:order_pk/ or something similar.

If it is implemented please share some information how to do it.

Thanks :)
Przemek

CredentialsError at /payments/new/

  • django-getpaid version: 2.2.0
  • django-getpaid-payu version: 0.2.0
  • Django version: 3.0.6
  • Python version: 3.7.5
  • Operating System: Ubuntu 19

I'm trying to finish the process of order with default settings of example app.
Action click on checkout button (http://127.0.0.1:8000/order/3/) does POST to http://127.0.0.1:8000/payments/new/ with data

{"csrfmiddlewaretoken":"2Nmmhzp4MXWaR5cZxdFTHBnrfWdK5Vk0BOmr05g43o6VZfytiV7I85IFmE8Yw0bH","backend":"getpaid_payu","order":"4","amount_required":"199.99","description":"Lock,+Stock+and+Two+Smoking+Barrels","currency":"EUR"}

But response is 500

Request Method: 	POST
Request URL: 	http://127.0.0.1:8000/payments/new/
Django Version: 	3.0.6
Exception Type: 	CredentialsError
Exception Value: 	Cannot authenticate.
Exception Location: 	/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid_payu/client.py in _authorize, line 78
Python Executable: 	/home/m/Desktop/localhost/django-getpaid/example/venv/bin/python3
Python Version: 	3.7.5


Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/payments/new/

Django Version: 3.0.6
Python Version: 3.7.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.admin',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.contenttypes',
 'django_fsm',
 'getpaid',
 'getpaid_payu',
 'orders',
 'paywall']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware']



Traceback (most recent call last):
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/views/generic/edit.py", line 172, in post
    return super().post(request, *args, **kwargs)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/django/views/generic/edit.py", line 142, in post
    return self.form_valid(form)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid/views.py", line 24, in form_valid
    return payment.prepare_transaction(request=self.request, view=self)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid/models.py", line 343, in prepare_transaction
    return self.processor.prepare_transaction(request=request, view=None, **kwargs)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid/models.py", line 199, in processor
    self._processor = self.get_processor()
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid/models.py", line 219, in get_processor
    return processor(self)
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid/processor.py", line 47, in __init__
    self.client = self.get_client()
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid/processor.py", line 60, in get_client
    return self.get_client_class()(**self.get_client_params())
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid_payu/client.py", line 60, in __init__
    self._authorize()
  File "/home/m/Desktop/localhost/django-getpaid/example/venv/lib/python3.7/site-packages/getpaid_payu/client.py", line 78, in _authorize
    "Cannot authenticate.", context={"raw_response": self.last_response}

Exception Type: CredentialsError at /payments/new/
Exception Value: Cannot authenticate.

Credentials to PayU is default to sandbox

GETPAID_BACKEND_SETTINGS = {
    "getpaid_payu": {
        "pos_id": 300746,
        "second_key": "b6ca15b0d1020e8094d9b5f8d163db54",
        "client_id": 300746,
        "client_secret": "2ee86a66e5d97e3fadc400c9f19b065d",
        "confirmation_method": "PULL",  # required for local testing
    },
}

I'm new one with PayU, then probably I don't know something about PayU setup process.

Not possible to set "continueUrl" parametr to PayU Rest API OrderCreateRequest

  • django-getpaid version: 2.3.0
  • django-getpaid-payu version: 0.2.1
  • Django version: 3.2.15
  • Python version: 3.8.10
  • Operating System: Ubuntu 22.04

Description

There is no possible to set "continueUrl" parametr to PayU Rest API OrderCreateRequest

What I Did

Order request look like this:

{"extOrderId": "86d19316-8c60-487d-bc82-xxx", "customerIp": "127.0.0.1", "merchantPosId": xxxx, "description": "[email protected]", "currencyCode": "PLN", "totalAmount": 27000, "products": [{"name": "[email protected]", "quantity": 1, "unitPrice": 27000}], "notifyUrl": "http://localhost:8000/payments/callback/86d19316-8c60-487d-bc82-xxx/"}

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.