From 98a5ed08c4f90718c3392ac3daf0707f44c82121 Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Fri, 25 Oct 2024 20:34:02 -0300 Subject: [PATCH 01/15] Issue #425 --- docs/webhooks.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 44afcdee4..fdf22d761 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -33,7 +33,7 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: * In the "Endpoint URL" field, enter the URL for the Stripe variant in your Django Payments application. This URL should be the endpoint where Stripe will send the webhook events. Make sure the URL is accessible from the - internet. Example: ``https://your-app.com/payments/stripe/``. + internet. Example: ``https://your-app.com/payments/process/stripe/``. * From the "Events to send" dropdown, choose the specific events you want to receive notifications for. You need (at least) these events: * checkout.session.async_payment_failed @@ -55,7 +55,7 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: the events sent by Stripe. It's it not recomended to use `secure_endpoint` set to false in production. -Make sure to replace **https://your-app.com/payments/stripe/** with the actual +Make sure to replace **https://your-app.com/payments/process/stripe/** with the actual URL for your Stripe webhook endpoint. In this case, ``stripe`` is the `variant` of the configured provider. E.g.: From cc6415ae74a0cee011ec5f463529bfb3798c3a3a Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Fri, 25 Oct 2024 20:36:12 -0300 Subject: [PATCH 02/15] New repo for CL --- docs/backends.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/backends.rst b/docs/backends.rst index d7cf1c806..2a65d704e 100644 --- a/docs/backends.rst +++ b/docs/backends.rst @@ -312,12 +312,9 @@ These are the community providers compatible with ``django-payments`` * - `RazorPay `_ - IN - `NyanKiyoshi/django-payments-razorpay `_ - * - `Flow Chile `_ + * - `Multiple Providers from Chile`_ - CL - - `mariofix/django-payments-flow `_ - * - `Khipu `_ - - CL - - `mariofix/django-payments-khipu `_ + - `mariofix/django-payments-chile `_ Creating a New Provider Backend From 5fa2b9312b432aa741609db623942bf25468335d Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Fri, 25 Oct 2024 20:37:56 -0300 Subject: [PATCH 03/15] Update backends.rst --- docs/backends.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/backends.rst b/docs/backends.rst index 2a65d704e..83d74fc53 100644 --- a/docs/backends.rst +++ b/docs/backends.rst @@ -312,7 +312,7 @@ These are the community providers compatible with ``django-payments`` * - `RazorPay `_ - IN - `NyanKiyoshi/django-payments-razorpay `_ - * - `Multiple Providers from Chile`_ + * - Common providers from Chile - CL - `mariofix/django-payments-chile `_ From ba8d0b848e112a67b11f7050e92743cf064edb8f Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Sun, 17 Nov 2024 16:13:35 -0300 Subject: [PATCH 04/15] Improved webhooks.rst --- docs/webhooks.rst | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index fdf22d761..e52b1de08 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -3,7 +3,6 @@ Webhooks ================= - Webhooks are a crucial component in connecting your Django Payments application with external payment gateways like Stripe, PayPal, or Braintree. They enable real-time notifications or events from the payment gateway to be sent to your @@ -31,9 +30,10 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: * In the left sidebar, click on **Developers** and then select **Webhooks**. * Click on the "+ Add endpoint" button to create a new webhook listener. * In the "Endpoint URL" field, enter the URL for the Stripe variant in your - Django Payments application. This URL should be the endpoint where Stripe - will send the webhook events. Make sure the URL is accessible from the - internet. Example: ``https://your-app.com/payments/process/stripe/``. + Django Payments application. This URL should follow the pattern: + ``https://your-app.com/payments/process/{variant}/``, where ``{variant}`` is + the name you've configured in your PAYMENT_VARIANTS setting. + For example: ``https://your-app.com/payments/process/stripe/`` * From the "Events to send" dropdown, choose the specific events you want to receive notifications for. You need (at least) these events: * checkout.session.async_payment_failed @@ -52,17 +52,30 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: .. note:: It's essential to secure your webhook endpoint and verify the authenticity of - the events sent by Stripe. It's it not recomended to use `secure_endpoint` + the events sent by Stripe. It's not recommended to use `secure_endpoint` set to false in production. -Make sure to replace **https://your-app.com/payments/process/stripe/** with the actual -URL for your Stripe webhook endpoint. In this case, ``stripe`` is the `variant` -of the configured provider. E.g.: +.. warning:: + + Remember to setup ``PAYMENT_HOST`` and ``PAYMENT_PROTOCOL`` in your settings file, + otherwise the webhooks won't work, as defined in :ref:`settings`. + +URL Structure +------------ +The webhook URL structure in django-payments follows this pattern: +``{protocol}://{host}/payments/process/{variant}/`` + +Where: +* ``{protocol}``: Configured in ``PAYMENT_PROTOCOL`` (typically "http" or "https") +* ``{host}``: Configured in ``PAYMENT_HOST`` +* ``{variant}``: The name you've configured in PAYMENT_VARIANTS + +For example, with this configuration: .. code-block:: python PAYMENT_VARIANTS = { - 'stripe': ( # <-- This value + 'stripe': ( # <-- This is your variant name 'payments.stripe.StripeProviderV3', { 'api_key': 'sk_test_123456', @@ -72,3 +85,14 @@ of the configured provider. E.g.: } ) } + + PAYMENT_HOST = 'your-app.com' + PAYMENT_PROTOCOL = 'https' + +Your webhook URL would be: +``https://your-app.com/payments/process/stripe/`` + +.. note:: + + Make sure the URL matches exactly, including the trailing slash. A common source + of 404 errors is using the wrong URL pattern or forgetting the trailing slash. \ No newline at end of file From 34ab1ba4e3285b7485490522fc27df9c73dfe730 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:13:57 +0000 Subject: [PATCH 05/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/webhooks.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index e52b1de08..4012bfd9f 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -57,7 +57,7 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: .. warning:: - Remember to setup ``PAYMENT_HOST`` and ``PAYMENT_PROTOCOL`` in your settings file, + Remember to setup ``PAYMENT_HOST`` and ``PAYMENT_PROTOCOL`` in your settings file, otherwise the webhooks won't work, as defined in :ref:`settings`. URL Structure @@ -85,7 +85,7 @@ For example, with this configuration: } ) } - + PAYMENT_HOST = 'your-app.com' PAYMENT_PROTOCOL = 'https' @@ -95,4 +95,4 @@ Your webhook URL would be: .. note:: Make sure the URL matches exactly, including the trailing slash. A common source - of 404 errors is using the wrong URL pattern or forgetting the trailing slash. \ No newline at end of file + of 404 errors is using the wrong URL pattern or forgetting the trailing slash. From 133c9e9658d741a1de7c62b0e4ad00bf31c9be8b Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Sun, 17 Nov 2024 16:20:05 -0300 Subject: [PATCH 06/15] Stripe CLI testing --- docs/webhooks.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 4012bfd9f..24e80bb6d 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -49,6 +49,21 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: ensure your endpoint is correctly configured and can receive and process events from Stripe. + +Testing with Stripe CLI +---------------------- + +The `Stripe CLI `_ provides a simple way to test webhooks during local development by forwarding Stripe events to your local server. After installing and running ``stripe login``, you can start forwarding events to your local Django server with ``stripe listen --forward-to localhost:8000/payments/process/stripe/``. Use the webhook signing secret provided by the CLI in your development settings. + +.. code-block:: bash + + # Start webhook forwarding + stripe listen --forward-to localhost:8000/payments/process/stripe/ + + # In another terminal, trigger test events + stripe trigger checkout.session.completed + + .. note:: It's essential to secure your webhook endpoint and verify the authenticity of From aea6dc504451188293d0f17755b0d1b7b3d9dbda Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:22:02 +0000 Subject: [PATCH 07/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/webhooks.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 24e80bb6d..9056cd800 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -59,7 +59,7 @@ The `Stripe CLI `_ provides a simple # Start webhook forwarding stripe listen --forward-to localhost:8000/payments/process/stripe/ - + # In another terminal, trigger test events stripe trigger checkout.session.completed From 63b8c8a909b71614434e1227deb889555d59342e Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Sun, 17 Nov 2024 16:29:52 -0300 Subject: [PATCH 08/15] New Structure --- docs/webhooks.rst | 130 ++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 9056cd800..f2e2a3df2 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -1,7 +1,8 @@ .. _webhooks: +********* Webhooks -================= +********* Webhooks are a crucial component in connecting your Django Payments application with external payment gateways like Stripe, PayPal, or Braintree. They enable @@ -19,71 +20,16 @@ application's internal state, trigger actions, or send user notifications based on payment-related events. -Stripe -------- - -Setting up Webhooks in Stripe -To receive payment notifications and updates from Stripe, you need to set up -webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: - -* Log in to your `Stripe Dashboard `_. -* In the left sidebar, click on **Developers** and then select **Webhooks**. -* Click on the "+ Add endpoint" button to create a new webhook listener. -* In the "Endpoint URL" field, enter the URL for the Stripe variant in your - Django Payments application. This URL should follow the pattern: - ``https://your-app.com/payments/process/{variant}/``, where ``{variant}`` is - the name you've configured in your PAYMENT_VARIANTS setting. - For example: ``https://your-app.com/payments/process/stripe/`` -* From the "Events to send" dropdown, choose the specific events you want to - receive notifications for. You need (at least) these events: - * checkout.session.async_payment_failed - * checkout.session.async_payment_succeeded - * checkout.session.completed - * checkout.session.expired -* Click on the "Add endpoint" button to save your webhook listener. -* Once the webhook is created, you will see its details in the "Webhooks" - section. Take note of the "Signing secret" provided by Stripe as you will - need it later when configuring the webhook handler in your Django application -* Test the webhook by sending a test event to your endpoint. Stripe provides a - "Send test webhook" button on the webhook details page. Use this feature to - ensure your endpoint is correctly configured and can receive and process - events from Stripe. - - -Testing with Stripe CLI ----------------------- - -The `Stripe CLI `_ provides a simple way to test webhooks during local development by forwarding Stripe events to your local server. After installing and running ``stripe login``, you can start forwarding events to your local Django server with ``stripe listen --forward-to localhost:8000/payments/process/stripe/``. Use the webhook signing secret provided by the CLI in your development settings. - -.. code-block:: bash - - # Start webhook forwarding - stripe listen --forward-to localhost:8000/payments/process/stripe/ - - # In another terminal, trigger test events - stripe trigger checkout.session.completed - - -.. note:: - - It's essential to secure your webhook endpoint and verify the authenticity of - the events sent by Stripe. It's not recommended to use `secure_endpoint` - set to false in production. - -.. warning:: - - Remember to setup ``PAYMENT_HOST`` and ``PAYMENT_PROTOCOL`` in your settings file, - otherwise the webhooks won't work, as defined in :ref:`settings`. - URL Structure ------------- +============= The webhook URL structure in django-payments follows this pattern: + ``{protocol}://{host}/payments/process/{variant}/`` Where: -* ``{protocol}``: Configured in ``PAYMENT_PROTOCOL`` (typically "http" or "https") -* ``{host}``: Configured in ``PAYMENT_HOST`` -* ``{variant}``: The name you've configured in PAYMENT_VARIANTS +- ``{protocol}``: Configured in ``PAYMENT_PROTOCOL`` (typically "http" or "https") +- ``{host}``: Configured in ``PAYMENT_HOST`` +- ``{variant}``: The name you've configured in PAYMENT_VARIANTS For example, with this configuration: @@ -111,3 +57,65 @@ Your webhook URL would be: Make sure the URL matches exactly, including the trailing slash. A common source of 404 errors is using the wrong URL pattern or forgetting the trailing slash. + + +Stripe +====== + +Setting up Webhooks in Stripe +To receive payment notifications and updates from Stripe, you need to set up +webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: + +1. Log in to your `Stripe Dashboard `_. +#. In the left sidebar, click on **Developers** and then select **Webhooks**. +#. Click on the "+ Add endpoint" button to create a new webhook listener. +#. In the "Endpoint URL" field, enter the URL for the Stripe variant in your + Django Payments application. This URL should follow the pattern: + ``https://your-app.com/payments/process/{variant}/``, where ``{variant}`` is + the name you've configured in your PAYMENT_VARIANTS setting. + For example: ``https://your-app.com/payments/process/stripe/`` +#. From the "Events to send" dropdown, choose the specific events you want to + receive notifications for. You need (at least) these events: + - checkout.session.async_payment_failed + - checkout.session.async_payment_succeeded + - checkout.session.completed + - checkout.session.expired +#. Click on the "Add endpoint" button to save your webhook listener. +#. Once the webhook is created, you will see its details in the "Webhooks" + section. Take note of the "Signing secret" provided by Stripe as you will + need it later when configuring the webhook handler in your Django application +#. Test the webhook by sending a test event to your endpoint. Stripe provides a + "Send test webhook" button on the webhook details page. Use this feature to + ensure your endpoint is correctly configured and can receive and process + events from Stripe. + + +Testing with Stripe CLI +---------------------- + +The `Stripe CLI `_ provides a simple +way to test webhooks during local development by forwarding Stripe events to +your local server. After installing and running ``stripe login``, you can start +forwarding events to your local Django server with +``stripe listen --forward-to localhost:8000/payments/process/stripe/`` +Use the webhook signing secret provided by the CLI in your development settings. + +.. code-block:: bash + + # Start webhook forwarding + stripe listen --forward-to localhost:8000/payments/process/stripe/ + + # In another terminal, trigger test events + stripe trigger checkout.session.completed + + +.. note:: + + It's essential to secure your webhook endpoint and verify the authenticity of + the events sent by Stripe. It's not recommended to use `secure_endpoint` + set to false in production. + +.. warning:: + + Remember to setup ``PAYMENT_HOST`` and ``PAYMENT_PROTOCOL`` in your settings file, + otherwise the webhooks won't work, as defined in :ref:`settings`. From d97f3595284a61250bae10c3aa5ced34cb2354ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:30:02 +0000 Subject: [PATCH 09/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/webhooks.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index f2e2a3df2..00282d47b 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -94,9 +94,9 @@ Testing with Stripe CLI ---------------------- The `Stripe CLI `_ provides a simple -way to test webhooks during local development by forwarding Stripe events to +way to test webhooks during local development by forwarding Stripe events to your local server. After installing and running ``stripe login``, you can start -forwarding events to your local Django server with +forwarding events to your local Django server with ``stripe listen --forward-to localhost:8000/payments/process/stripe/`` Use the webhook signing secret provided by the CLI in your development settings. From f0582d45cd13a59375412931d4ce7efdcf08311e Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Sun, 17 Nov 2024 16:33:25 -0300 Subject: [PATCH 10/15] Lists --- docs/webhooks.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 00282d47b..208feb661 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -27,10 +27,12 @@ The webhook URL structure in django-payments follows this pattern: ``{protocol}://{host}/payments/process/{variant}/`` Where: + - ``{protocol}``: Configured in ``PAYMENT_PROTOCOL`` (typically "http" or "https") - ``{host}``: Configured in ``PAYMENT_HOST`` - ``{variant}``: The name you've configured in PAYMENT_VARIANTS + For example, with this configuration: .. code-block:: python @@ -76,10 +78,12 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: For example: ``https://your-app.com/payments/process/stripe/`` #. From the "Events to send" dropdown, choose the specific events you want to receive notifications for. You need (at least) these events: + - checkout.session.async_payment_failed - checkout.session.async_payment_succeeded - checkout.session.completed - checkout.session.expired + #. Click on the "Add endpoint" button to save your webhook listener. #. Once the webhook is created, you will see its details in the "Webhooks" section. Take note of the "Signing secret" provided by Stripe as you will From dc4049a0be037f1003f0f911b67d96a5f2890b88 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:33:35 +0000 Subject: [PATCH 11/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/webhooks.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 208feb661..179568efe 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -78,7 +78,7 @@ webhooks. Follow these steps to configure webhooks in your Stripe Dashboard: For example: ``https://your-app.com/payments/process/stripe/`` #. From the "Events to send" dropdown, choose the specific events you want to receive notifications for. You need (at least) these events: - + - checkout.session.async_payment_failed - checkout.session.async_payment_succeeded - checkout.session.completed From afa3e3d05f55af8db2459c2dd784a01fa3e57859 Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Wed, 11 Dec 2024 23:02:57 -0300 Subject: [PATCH 12/15] Update docs/webhooks.rst Co-authored-by: Hugo --- docs/webhooks.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/webhooks.rst b/docs/webhooks.rst index 179568efe..541929688 100644 --- a/docs/webhooks.rst +++ b/docs/webhooks.rst @@ -1,6 +1,5 @@ .. _webhooks: -********* Webhooks ********* From 2e4b09d63d0a3d149fbb86b7f2d55f5d24857f3b Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Sat, 14 Dec 2024 18:25:36 -0300 Subject: [PATCH 13/15] Python Deprecation set min python to 3.9, target on ruff to 3.9 --- pyproject.toml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 772a0b5c4..4e5e94419 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,13 +8,11 @@ authors = [ ] description = "Universal payment handling for Django" readme = "README.rst" -requires-python = ">=3.7" +requires-python = ">=3.9" keywords = ["payments"] license = {text = "BSD"} classifiers = [ "Environment :: Web Environment", - "Framework :: Django :: 3.2", - "Framework :: Django :: 4.1", "Framework :: Django :: 4.2", "Framework :: Django :: 5.0", "Framework :: Django :: 5.1", @@ -22,16 +20,16 @@ classifiers = [ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Framework :: Django", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ - "Django>=3.2", + "Django>=4.2", "requests>=1.2.0", "django-phonenumber-field[phonenumberslite]>=5.0.0", ] @@ -89,7 +87,7 @@ DJANGO_SETTINGS_MODULE = "test_settings" pythonpath = "." [tool.ruff] -target-version = "py38" +target-version = "py39" [tool.ruff.lint] select = [ From 20d306e59aede715808f81684e65347a4b9f6934 Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Sat, 14 Dec 2024 18:26:55 -0300 Subject: [PATCH 14/15] tox env updates Deprecate old python and old django --- tox.ini | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tox.ini b/tox.ini index 4ade0527b..23e4611ea 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,6 @@ [tox] envlist = - py{38,39}-dj32 - py{38,39,310,311}-dj{41,42} + py{39,310,311}-dj{41,42} py{311,312}-dj{50,51} py{310,311,312}-djmain skip_missing_interpreters = true @@ -13,8 +12,6 @@ ignore_outcome = ignore_errors = djmain: True deps= - dj32: Django>=3.2,<3.3 - dj41: Django>=4.1,<4.2 dj42: Django>=4.2,<5.0 dj50: Django>=5.0,<5.1 dj51: Django>=5.1,<5.2 @@ -33,7 +30,6 @@ commands= [gh-actions] python = - 3.8: py38 3.9: py39 3.10: py310 3.11: py311 @@ -48,8 +44,6 @@ commands = mypy . [gh-actions:env] DJANGO = - 3.2: dj32 - 4.1: dj41 4.2: dj42 5.0: dj50 5.1: dj51 From 1a4cd7c551dd4fc8fdeae70e9aa65913359f4ca4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:29:39 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- payments/mercadopago/test_mercadopago.py | 92 ++++++++++++++---------- payments/models.py | 2 +- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/payments/mercadopago/test_mercadopago.py b/payments/mercadopago/test_mercadopago.py index 7a0527ec8..a5111dc61 100644 --- a/payments/mercadopago/test_mercadopago.py +++ b/payments/mercadopago/test_mercadopago.py @@ -202,14 +202,17 @@ def test_approved_payment_notification(rf, mp_provider: MercadoPagoProvider): "status": 200, } - with patch( - "mercadopago.resources.payment.Payment.get", - spec=True, - return_value=payment_info_response, - ) as payment_info, patch( - "payments.mercadopago.redirect", - spec=True, - ) as redirect: + with ( + patch( + "mercadopago.resources.payment.Payment.get", + spec=True, + return_value=payment_info_response, + ) as payment_info, + patch( + "payments.mercadopago.redirect", + spec=True, + ) as redirect, + ): rv = mp_provider.process_data(payment, request) assert payment_info.call_count == 1 @@ -232,13 +235,16 @@ def test_create_preference_failure(mp_provider: MercadoPagoProvider): payment = Payment() - with patch( - "mercadopago.resources.preference.Preference.create", - spec=True, - return_value=preference_info, - ), pytest.raises( - PaymentError, - match="Failed to create MercadoPago preference.", + with ( + patch( + "mercadopago.resources.preference.Preference.create", + spec=True, + return_value=preference_info, + ), + pytest.raises( + PaymentError, + match="Failed to create MercadoPago preference.", + ), ): mp_provider.create_preference(payment) @@ -266,13 +272,16 @@ def test_process_failed_collection(mp_provider: MercadoPagoProvider): } payment = Payment() - with patch( - "mercadopago.resources.payment.Payment.get", - spec=True, - return_value=payment_info, - ), pytest.raises( - PaymentError, - match="MercadoPago sent invalid payment data.", + with ( + patch( + "mercadopago.resources.payment.Payment.get", + spec=True, + return_value=payment_info, + ), + pytest.raises( + PaymentError, + match="MercadoPago sent invalid payment data.", + ), ): mp_provider.process_collection(payment, "12") @@ -331,12 +340,13 @@ def test_get_preference_internal_error(mp_provider: MercadoPagoProvider): payment = Payment() payment.transaction_id = "ABJ122" - with patch( - "mercadopago.resources.preference.Preference.get", - spec=True, - return_value=mocked_response, - ) as get_preference, pytest.raises( - PaymentError, match="Failed to retrieve MercadoPago preference." + with ( + patch( + "mercadopago.resources.preference.Preference.get", + spec=True, + return_value=mocked_response, + ) as get_preference, + pytest.raises(PaymentError, match="Failed to retrieve MercadoPago preference."), ): mp_provider.get_preference(payment) @@ -365,11 +375,14 @@ def test_get_form_for_existing_preference( payment = Payment() payment.transaction_id = "ABJ122" - with patch( - "mercadopago.resources.preference.Preference.get", - spec=True, - return_value=mocked_response, - ) as get_preference, pytest.raises(RedirectNeeded) as exc_info: + with ( + patch( + "mercadopago.resources.preference.Preference.get", + spec=True, + return_value=mocked_response, + ) as get_preference, + pytest.raises(RedirectNeeded) as exc_info, + ): mp_provider.get_form(payment) assert get_preference.call_count == 1 @@ -387,11 +400,14 @@ def test_get_form_for_inexistent_preference(mp_provider: MercadoPagoProvider): } payment = Payment() - with patch( - "mercadopago.resources.preference.Preference.create", - spec=True, - return_value=mocked_response, - ) as get_preference, pytest.raises(RedirectNeeded) as exc_info: + with ( + patch( + "mercadopago.resources.preference.Preference.create", + spec=True, + return_value=mocked_response, + ) as get_preference, + pytest.raises(RedirectNeeded) as exc_info, + ): mp_provider.get_form(payment) assert get_preference.call_count == 1 diff --git a/payments/models.py b/payments/models.py index fe5203aee..303492033 100644 --- a/payments/models.py +++ b/payments/models.py @@ -2,7 +2,7 @@ import json import logging -from typing import Iterable +from collections.abc import Iterable from uuid import uuid4 from django.db import models