django-payments-payu


Namedjango-payments-payu JSON
Version 1.5.0 PyPI version JSON
download
home_pagehttps://github.com/PetrDlouhy/django-payments-payu
SummaryPayU payments provider for django-payments
upload_time2024-08-16 07:15:16
maintainerNone
docs_urlNone
authorPetr Dlouhý
requires_pythonNone
licenseMIT
keywords django-payments-payu
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            =============================
Django payments payu
=============================

.. image:: https://badge.fury.io/py/django-payments-payu.svg
    :target: https://badge.fury.io/py/django-payments-payu

.. image:: https://travis-ci.org/PetrDlouhy/django-payments-payu.svg?branch=master
    :target: https://travis-ci.org/PetrDlouhy/django-payments-payu

.. image:: https://codecov.io/gh/PetrDlouhy/django-payments-payu/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/PetrDlouhy/django-payments-payu


NOTE: This project is still in development, so use with extreme caution.

PayU payments provider for django-payments. Uses the new PayU REST API. Supports normal, express and recurring payments.

Documentation
-------------

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

Quickstart
----------

Install `django-payments <https://github.com/mirumee/django-payments>`_ and set up PayU payment provider backend according to `django-payments documentation <https://django-payments.readthedocs.io/en/latest/modules.html>`_:

.. class:: payments_payu.provider.PayuProvider(client_secret, second_key, pos_id, get_refund_description, [sandbox=False, endpoint="https://secure.payu.com/", recurring_payments=False, express_payments=False, widget_branding=False, get_refund_ext_id=_DEFAULT_GET_REFUND_EXT_ID])

   This backend implements payments using `PayU.com <https://payu.com>`_.

Set up the payment provider:

Example::

      # use sandbox
      PAYMENT_VARIANTS = {
          'payu': ('payments_payu.provider.PayuProvider', {
              'pos_id': '123456',
              'second_key': 'iseedeadpeople',
              'client_secret': 'peopleiseedead',
              'sandbox': True,
              'capture': False,
              'get_refund_description': lambda payment, amount: 'My refund',
              'get_refund_ext_id': lambda payment, amount: str(uuid.uuid4()),
          }),
      }

Here are valid parameters for the provider:
   :client_secret:          PayU OAuth protocol client secret
   :pos_id:                 PayU POS ID
   :second_key:             PayU second key (MD5)
   :shop_name:              Name of the shop send to the API
   :sandbox:                if ``True``, set the endpoint to sandbox
   :endpoint:               endpoint URL, if not set, the will be automatically set based on `sandbox` settings
   :recurring_payments:     enable recurring payments, only valid with ``express_payments=True``, see bellow for additional setup, that is needed
   :express_payments:       use PayU express form
   :widget_branding:        tell express form to show PayU branding
   :store_card:             (default: False) whether PayU should store the card
   :get_refund_description: An optional callable that is called with two keyword arguments `payment` and `amount` in order to get the string description of the particular refund whenever ``provider.refund(payment, amount)`` is called. The callable is optional because of backwards compatibility. However, if it is not set, an attempt to refund raises an exception. A default value of `get_refund_description` is deprecated.
   :get_refund_ext_id:      An optional callable that is called with two keyword arguments `payment` and `amount` in order to get the External string refund ID of the particular refund whenever ``provider.refund(payment, amount)`` is called. If ``None`` is returned, no External refund ID is set. An External refund ID is not necessary if partial refunds won't be performed more than once per second. Otherwise, a unique ID is recommended since `PayuProvider.refund` is idempotent and if exactly same data will be provided, it will return the result of the already previously performed refund instead of performing a new refund. Defaults to a random UUID version 4 in the standard form.


   NOTE: notifications about the payment status from PayU are requested to be sent to `django-payments` `process_payment` url. The request from PayU can fail for several reasons (i.e. it can be blocked by proxy). Use "Show reports" page in PayU administration to get more information about the requests.


**Recurring payments**:
   If recurring payments are enabled, the PayU card token needs to be stored in your application for usage in next payments. The next payments can be either initiated by user through (user will be prompted only for payment confirmation by the express form) or by server.
   To enable recurring payments, you will need to set additional things:

   NOTE: Recurring payments are not enabled by default even in Sandbox, you sould consult their helpdesk to enable this.

   * In order to make payments recurring, the card token needs to be stored for the ``Payment``'s user (not just the payment itself). Implement the ``Payment.set_renew_token()`` and ``Payment.get_renew_token()``.
   * Implement ``Payment.get_payment_url()``.
   * For the server initiated recurring payments you will need to create the new payment and then call ``payment.auto_complete_recurring()``.
      * The method returns either string 'success' or url where the user can provide his CVV2 or 3D secure information.
      * The ``'success'`` string means, that the payment is waiting for notification from PayU, but no further user action is required.


Example of triggering recurring payment::

       payment = Payment.objects.create(...)
       redirect_url = payment.auto_complete_recurring()
       if redirect_url != 'success':
           send_mail(
               'Recurring payment - action required',
               'Please renew your CVV2/3DS at %s' % redirect_url,
               'noreply@test.com',
               [user.email],
               fail_silently=False,
           )

Running Tests
-------------

Does the code actually work?

::

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install tox
    (myenv) $ tox

Credits
-------

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage




History
-------

1.5.0 (2024-08-16)
******************
* log warning when status changes out from confirmed
* fix problem with form in Django 5.0
* support Django 5.1

1.4.6 (2024-07-23)
******************
* remove debug code committed by mistake

1.4.5 (2024-07-23)
******************
* fix safestring in Django 5.0

1.4.4 (2024-06-27)
******************
* fix PayuApiError: invalid response to refund

1.4.3 (2024-05-15)
******************
* fix "AttributeError: Manager isn't accessible via Payment instances" introduced in 1.4.1

1.4.2 (2024-05-14)
******************
* fix multiple deduction of the refund amount from `payment.captured_amount`
* change statuses of payments refunded with an amount greater than `payment.captured_amount` to `REFUNDED` instead of just deducing `captured_amount`

1.4.1 (2024-05-14)
******************
* fix captured_amount not being saved when processing data

1.4.0 (2024-04-12)
******************
* fix backward compatibility by making PayuProvider's get_refund_description argument optional
* add `renewal_triggered_by` parameter to `payment.set_renew_token`
* make PayuProvider.refund fail if get_refund_description is not provided
* make PayuProvider.refund raise PayuApiError if an unexpected response is received
* deprecate the default value of get_refund_description; set it to a callable instead
* deprecate `automatic_renewal` parameter of `payment.set_renew_token`; use `renewal_triggered_by` parameter instead
* deprecate `None` value of `renewal_triggered_by` parameter of `payment.set_renew_token`; set `"user"`/`"task"`/`"other"` instead

1.3.1 (2024-03-19)
******************
* Fix description on PyPI

1.3.0 (2024-03-19)
******************
* add get_refund_description and get_refund_ext_id arguments to PayuProvider
* add PayuProvider.refund
* update payment.captured_amount only when order is completed
* subtract refunds from payment.captured_amount rather than from payment.total
* rename PayuProvider.payu_api_order_url to payu_api_orders_url
* tests for Django 2.2-5.0 Python 3.7-3.12

1.2.4 (2022-03-17)
******************
* treat partial refunds
* tests for Django 2.2-4.0 Python 3.7-3.10


1.2.3 (2022-01-25)
******************
* better distinct PayU API errors

1.2.2 (2021-11-30)
******************
* solve the duplicate order case that errored already confirmed payment

1.2.1 (2021-10-29)
******************
* set fraud status if PayU anti-froud error
* store PayU error on payment

1.2.0 (2021-10-11)
******************
* user Payment.billing_* correctly - the functions like ``get_user`` or ``get_user_email``, ``get_user_first_name`` and ``get_user_last_name`` were redundant and are not called anymore.
* Shop name is taken from provider configuration variable ``shop_name``

1.1.0 (2021-10-05)
******************
* redirect to payment.get_failure_url() after API error, log the error

1.0.0 (2020-10-21)
******************
* first major release
* many fixes
* recurring payments working
* proved by production environment

0.3.0 (2020-05-30)
******************
* fix amount quantization
* add store_card parameter
* fix base url parameter for express form

0.2.0 (2020-04-13)
******************
* Second release
* Fixed testing matrix

0.1.0 (2020-04-06)
******************

* First release on PyPI.
* Still in development.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PetrDlouhy/django-payments-payu",
    "name": "django-payments-payu",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django-payments-payu",
    "author": "Petr Dlouh\u00fd",
    "author_email": "petr.dlouhy@email.cz",
    "download_url": "https://files.pythonhosted.org/packages/a7/1d/89f45f8c8053a0104d76079ae35fe66fcb62788e2f6b0aa6f7d27a127249/django_payments_payu-1.5.0.tar.gz",
    "platform": null,
    "description": "=============================\nDjango payments payu\n=============================\n\n.. image:: https://badge.fury.io/py/django-payments-payu.svg\n    :target: https://badge.fury.io/py/django-payments-payu\n\n.. image:: https://travis-ci.org/PetrDlouhy/django-payments-payu.svg?branch=master\n    :target: https://travis-ci.org/PetrDlouhy/django-payments-payu\n\n.. image:: https://codecov.io/gh/PetrDlouhy/django-payments-payu/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/PetrDlouhy/django-payments-payu\n\n\nNOTE: This project is still in development, so use with extreme caution.\n\nPayU payments provider for django-payments. Uses the new PayU REST API. Supports normal, express and recurring payments.\n\nDocumentation\n-------------\n\nThe full documentation is at https://django-payments-payu.readthedocs.io.\n\nQuickstart\n----------\n\nInstall `django-payments <https://github.com/mirumee/django-payments>`_ and set up PayU payment provider backend according to `django-payments documentation <https://django-payments.readthedocs.io/en/latest/modules.html>`_:\n\n.. class:: payments_payu.provider.PayuProvider(client_secret, second_key, pos_id, get_refund_description, [sandbox=False, endpoint=\"https://secure.payu.com/\", recurring_payments=False, express_payments=False, widget_branding=False, get_refund_ext_id=_DEFAULT_GET_REFUND_EXT_ID])\n\n   This backend implements payments using `PayU.com <https://payu.com>`_.\n\nSet up the payment provider:\n\nExample::\n\n      # use sandbox\n      PAYMENT_VARIANTS = {\n          'payu': ('payments_payu.provider.PayuProvider', {\n              'pos_id': '123456',\n              'second_key': 'iseedeadpeople',\n              'client_secret': 'peopleiseedead',\n              'sandbox': True,\n              'capture': False,\n              'get_refund_description': lambda payment, amount: 'My refund',\n              'get_refund_ext_id': lambda payment, amount: str(uuid.uuid4()),\n          }),\n      }\n\nHere are valid parameters for the provider:\n   :client_secret:          PayU OAuth protocol client secret\n   :pos_id:                 PayU POS ID\n   :second_key:             PayU second key (MD5)\n   :shop_name:              Name of the shop send to the API\n   :sandbox:                if ``True``, set the endpoint to sandbox\n   :endpoint:               endpoint URL, if not set, the will be automatically set based on `sandbox` settings\n   :recurring_payments:     enable recurring payments, only valid with ``express_payments=True``, see bellow for additional setup, that is needed\n   :express_payments:       use PayU express form\n   :widget_branding:        tell express form to show PayU branding\n   :store_card:             (default: False) whether PayU should store the card\n   :get_refund_description: An optional callable that is called with two keyword arguments `payment` and `amount` in order to get the string description of the particular refund whenever ``provider.refund(payment, amount)`` is called. The callable is optional because of backwards compatibility. However, if it is not set, an attempt to refund raises an exception. A default value of `get_refund_description` is deprecated.\n   :get_refund_ext_id:      An optional callable that is called with two keyword arguments `payment` and `amount` in order to get the External string refund ID of the particular refund whenever ``provider.refund(payment, amount)`` is called. If ``None`` is returned, no External refund ID is set. An External refund ID is not necessary if partial refunds won't be performed more than once per second. Otherwise, a unique ID is recommended since `PayuProvider.refund` is idempotent and if exactly same data will be provided, it will return the result of the already previously performed refund instead of performing a new refund. Defaults to a random UUID version 4 in the standard form.\n\n\n   NOTE: notifications about the payment status from PayU are requested to be sent to `django-payments` `process_payment` url. The request from PayU can fail for several reasons (i.e. it can be blocked by proxy). Use \"Show reports\" page in PayU administration to get more information about the requests.\n\n\n**Recurring payments**:\n   If recurring payments are enabled, the PayU card token needs to be stored in your application for usage in next payments. The next payments can be either initiated by user through (user will be prompted only for payment confirmation by the express form) or by server.\n   To enable recurring payments, you will need to set additional things:\n\n   NOTE: Recurring payments are not enabled by default even in Sandbox, you sould consult their helpdesk to enable this.\n\n   * In order to make payments recurring, the card token needs to be stored for the ``Payment``'s user (not just the payment itself). Implement the ``Payment.set_renew_token()`` and ``Payment.get_renew_token()``.\n   * Implement ``Payment.get_payment_url()``.\n   * For the server initiated recurring payments you will need to create the new payment and then call ``payment.auto_complete_recurring()``.\n      * The method returns either string 'success' or url where the user can provide his CVV2 or 3D secure information.\n      * The ``'success'`` string means, that the payment is waiting for notification from PayU, but no further user action is required.\n\n\nExample of triggering recurring payment::\n\n       payment = Payment.objects.create(...)\n       redirect_url = payment.auto_complete_recurring()\n       if redirect_url != 'success':\n           send_mail(\n               'Recurring payment - action required',\n               'Please renew your CVV2/3DS at %s' % redirect_url,\n               'noreply@test.com',\n               [user.email],\n               fail_silently=False,\n           )\n\nRunning Tests\n-------------\n\nDoes the code actually work?\n\n::\n\n    source <YOURVIRTUALENV>/bin/activate\n    (myenv) $ pip install tox\n    (myenv) $ tox\n\nCredits\n-------\n\nTools used in rendering this package:\n\n*  Cookiecutter_\n*  `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n\n\n\n\nHistory\n-------\n\n1.5.0 (2024-08-16)\n******************\n* log warning when status changes out from confirmed\n* fix problem with form in Django 5.0\n* support Django 5.1\n\n1.4.6 (2024-07-23)\n******************\n* remove debug code committed by mistake\n\n1.4.5 (2024-07-23)\n******************\n* fix safestring in Django 5.0\n\n1.4.4 (2024-06-27)\n******************\n* fix PayuApiError: invalid response to refund\n\n1.4.3 (2024-05-15)\n******************\n* fix \"AttributeError: Manager isn't accessible via Payment instances\" introduced in 1.4.1\n\n1.4.2 (2024-05-14)\n******************\n* fix multiple deduction of the refund amount from `payment.captured_amount`\n* change statuses of payments refunded with an amount greater than `payment.captured_amount` to `REFUNDED` instead of just deducing `captured_amount`\n\n1.4.1 (2024-05-14)\n******************\n* fix captured_amount not being saved when processing data\n\n1.4.0 (2024-04-12)\n******************\n* fix backward compatibility by making PayuProvider's get_refund_description argument optional\n* add `renewal_triggered_by` parameter to `payment.set_renew_token`\n* make PayuProvider.refund fail if get_refund_description is not provided\n* make PayuProvider.refund raise PayuApiError if an unexpected response is received\n* deprecate the default value of get_refund_description; set it to a callable instead\n* deprecate `automatic_renewal` parameter of `payment.set_renew_token`; use `renewal_triggered_by` parameter instead\n* deprecate `None` value of `renewal_triggered_by` parameter of `payment.set_renew_token`; set `\"user\"`/`\"task\"`/`\"other\"` instead\n\n1.3.1 (2024-03-19)\n******************\n* Fix description on PyPI\n\n1.3.0 (2024-03-19)\n******************\n* add get_refund_description and get_refund_ext_id arguments to PayuProvider\n* add PayuProvider.refund\n* update payment.captured_amount only when order is completed\n* subtract refunds from payment.captured_amount rather than from payment.total\n* rename PayuProvider.payu_api_order_url to payu_api_orders_url\n* tests for Django 2.2-5.0 Python 3.7-3.12\n\n1.2.4 (2022-03-17)\n******************\n* treat partial refunds\n* tests for Django 2.2-4.0 Python 3.7-3.10\n\n\n1.2.3 (2022-01-25)\n******************\n* better distinct PayU API errors\n\n1.2.2 (2021-11-30)\n******************\n* solve the duplicate order case that errored already confirmed payment\n\n1.2.1 (2021-10-29)\n******************\n* set fraud status if PayU anti-froud error\n* store PayU error on payment\n\n1.2.0 (2021-10-11)\n******************\n* user Payment.billing_* correctly - the functions like ``get_user`` or ``get_user_email``, ``get_user_first_name`` and ``get_user_last_name`` were redundant and are not called anymore.\n* Shop name is taken from provider configuration variable ``shop_name``\n\n1.1.0 (2021-10-05)\n******************\n* redirect to payment.get_failure_url() after API error, log the error\n\n1.0.0 (2020-10-21)\n******************\n* first major release\n* many fixes\n* recurring payments working\n* proved by production environment\n\n0.3.0 (2020-05-30)\n******************\n* fix amount quantization\n* add store_card parameter\n* fix base url parameter for express form\n\n0.2.0 (2020-04-13)\n******************\n* Second release\n* Fixed testing matrix\n\n0.1.0 (2020-04-06)\n******************\n\n* First release on PyPI.\n* Still in development.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PayU payments provider for django-payments",
    "version": "1.5.0",
    "project_urls": {
        "Homepage": "https://github.com/PetrDlouhy/django-payments-payu"
    },
    "split_keywords": [
        "django-payments-payu"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e3071f4d584ab3c30de3af0b99376de8fbae4eaab3fdf73990d4df9ea529985",
                "md5": "55a15d56b9677db2fda50ef05d306c4a",
                "sha256": "3c68dbed319ca7b1946031acb7b03ff572e9ce19023b559fd4f7f3ee1d52fedc"
            },
            "downloads": -1,
            "filename": "django_payments_payu-1.5.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "55a15d56b9677db2fda50ef05d306c4a",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 13593,
            "upload_time": "2024-08-16T07:15:14",
            "upload_time_iso_8601": "2024-08-16T07:15:14.847713Z",
            "url": "https://files.pythonhosted.org/packages/5e/30/71f4d584ab3c30de3af0b99376de8fbae4eaab3fdf73990d4df9ea529985/django_payments_payu-1.5.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a71d89f45f8c8053a0104d76079ae35fe66fcb62788e2f6b0aa6f7d27a127249",
                "md5": "8fa3618078e2e0ffcac2dbc6aea6d9e7",
                "sha256": "72bcd32d7039ed2dae56cf5d87117b57d99952fb49b8f51481203647076100db"
            },
            "downloads": -1,
            "filename": "django_payments_payu-1.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8fa3618078e2e0ffcac2dbc6aea6d9e7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22603,
            "upload_time": "2024-08-16T07:15:16",
            "upload_time_iso_8601": "2024-08-16T07:15:16.380324Z",
            "url": "https://files.pythonhosted.org/packages/a7/1d/89f45f8c8053a0104d76079ae35fe66fcb62788e2f6b0aa6f7d27a127249/django_payments_payu-1.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-16 07:15:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PetrDlouhy",
    "github_project": "django-payments-payu",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "django-payments-payu"
}
        
Elapsed time: 0.33387s