diff --git a/.gitignore b/.gitignore index 7793188..18ebf07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,137 @@ -*.pyc -.svn -.project -.pydevproject -.vscode -/dist -/build -/django_paypal.egg-info -*.swp -.tox -.idea/ -docs/_build -.DS_Store +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# vscode +.vscode/ diff --git a/docs/standard/ipn.rst b/docs/standard/ipn.rst index eb8f422..7b567c3 100644 --- a/docs/standard/ipn.rst +++ b/docs/standard/ipn.rst @@ -69,7 +69,7 @@ Using PayPal Standard IPN For a full list of variables that can be used in ``paypal_dict``, see - `PayPal HTML variables documentation `_. + `PayPal HTML variables documentation `_. .. note:: The names of these variables are not the same as the values returned on the IPN object. @@ -87,6 +87,18 @@ Using PayPal Standard IPN by subclassing ``PayPalPaymentsForm`` and overriding the ``get_image`` method. + **Submit button customisation** + The submit button used by the form is the standard PayPal payment button, but it's possible to customise it extending the form: + + .. code-block:: python + + from paypal.standard.forms import PayPalPaymentsForm + + class CustomPayPalPaymentsForm(PayPalPaymentsForm): + + def get_html_submit_element(self): + return """""" + 4. When someone uses this button to buy something PayPal makes a HTTP POST to your "notify_url". PayPal calls this Instant Payment Notification (IPN). The view ``paypal.standard.ipn.views.ipn`` handles IPN processing. To set the diff --git a/paypal/standard/forms.py b/paypal/standard/forms.py index 38cec99..66d3028 100644 --- a/paypal/standard/forms.py +++ b/paypal/standard/forms.py @@ -191,20 +191,26 @@ def get_login_url(self): else: return LOGIN_URL + def get_html(self): + return format_html( + """
{1}{2}
""", + self.get_login_url(), + self.as_p(), + self.get_html_submit_element(), + ) + + def get_html_submit_element(self): + return format_html( + """""", + self.get_image(), + ) + if DJANGO_FORM_HAS_RENDER_METHOD: def render(self, *args, **kwargs): if not args and not kwargs: # `form.render` usage from template - return format_html( - """
- {1} - -
""", - self.get_login_url(), - self.as_p(), - self.get_image(), - ) + return self.get_html() else: # Need to delegate to super. This provides # support for `as_p` method and for `BoundField.label_tag`, @@ -214,15 +220,7 @@ def render(self, *args, **kwargs): else: def render(self): - return format_html( - """
- {1} - -
""", - self.get_login_url(), - self.as_p(), - self.get_image(), - ) + return self.get_html() def get_image(self): return {