Skip to content

Commit

Permalink
Merge pull request #258 from fabiocaccamo/master
Browse files Browse the repository at this point in the history
Simplified payment button customisation. #196
  • Loading branch information
spookylukey committed Jul 21, 2022
2 parents 5785164 + 0130b4d commit 59c9a92
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 32 deletions.
150 changes: 137 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
14 changes: 13 additions & 1 deletion docs/standard/ipn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/>`_.
`PayPal HTML variables documentation <https://developer.paypal.com/api/nvp-soap/paypal-payments-standard/integration-guide/Appx-websitestandard-htmlvariables/>`_.

.. note:: The names of these variables are not the same as the values
returned on the IPN object.
Expand All @@ -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 """<button type="submit">Continue on PayPal website</button>"""
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
Expand Down
34 changes: 16 additions & 18 deletions paypal/standard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,26 @@ def get_login_url(self):
else:
return LOGIN_URL

def get_html(self):
return format_html(
"""<form action="{0}" method="post">{1}{2}</form>""",
self.get_login_url(),
self.as_p(),
self.get_html_submit_element(),
)

def get_html_submit_element(self):
return format_html(
"""<input type="image" src="{0}" name="submit" alt="Buy it Now" />""",
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(
"""<form action="{0}" method="post">
{1}
<input type="image" src="{2}" name="submit" alt="Buy it Now" />
</form>""",
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`,
Expand All @@ -214,15 +220,7 @@ def render(self, *args, **kwargs):
else:

def render(self):
return format_html(
"""<form action="{0}" method="post">
{1}
<input type="image" src="{2}" name="submit" alt="Buy it Now" />
</form>""",
self.get_login_url(),
self.as_p(),
self.get_image(),
)
return self.get_html()

def get_image(self):
return {
Expand Down

0 comments on commit 59c9a92

Please sign in to comment.