Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from open-formulieren/feature/4380-implement-ex…
Browse files Browse the repository at this point in the history
…tra-payment-attributes

✨ [open-formulieren/open-forms#4380] Extra StUF-ZDS payment attributes
  • Loading branch information
sergei-maertens authored Aug 5, 2024
2 parents dc12826 + 976f278 commit 773f47c
Show file tree
Hide file tree
Showing 16 changed files with 937 additions and 32 deletions.
84 changes: 63 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,84 @@ on:
pull_request:
workflow_dispatch:

env:
IMAGE_NAME: openformulieren/open-forms-ext-stuf-zds-payments

jobs:
tests:
name: Run the Django test suite
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.10', '3.11', '3.12']
django: ['4.2']

name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }})
services:
postgres:
image: postgres:14
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# Needed because the postgres container does not provide a healthcheck
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
--name postgres
redis:
image: redis:6
ports:
- 6379:6379

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout Open Forms
uses: actions/checkout@v4
with:
repository: open-formulieren/open-forms
path: open-forms

- name: Checkout StUF-ZDS payments extension
uses: actions/checkout@v4
with:
python-version: ${{ matrix.python }}
path: extension

- name: Install dependencies
run: pip install tox tox-gh-actions
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
apt-packages: 'libxml2 libxmlsec1 libxmlsec1-openssl gettext postgresql-client gdal-bin'
python-version: '3.12'
optimize-postgres: 'yes'
pg-service: 'postgres'
setup-node: 'yes'
nvmrc-custom-dir: 'open-forms'
npm-ci-flags: '--legacy-peer-deps'
working-directory: ${{ github.workspace }}/open-forms

- name: Make symlink in OF to the extension
run: |
ln -s ${{ github.workspace }}/extension/stuf_zds_payments ${{ github.workspace }}/open-forms/src
- name: Run tests
run: tox
run: |
export OPEN_FORMS_EXTENSIONS=stuf_zds_payments
python src/manage.py compilemessages
coverage run --source=stuf_zds_payments src/manage.py test stuf_zds_payments
coverage combine
coverage xml -o coverage-extension.xml
env:
PYTHON_VERSION: ${{ matrix.python }}
DJANGO: ${{ matrix.django }}
DJANGO_SETTINGS_MODULE: openforms.conf.ci
SECRET_KEY: dummy
DB_USER: postgres
DB_PASSWORD: ''
working-directory: ${{ github.workspace }}/open-forms

- name: Publish coverage report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
root_dir: ${{ github.workspace }}/extension
working-directory: ${{ github.workspace }}/open-forms
files: ./coverage-extension.xml

publish:
name: Publish package to PyPI
runs-on: ubuntu-latest
needs: tests
needs:
- tests
environment: release
permissions:
id-token: write
Expand All @@ -54,13 +98,11 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'

- name: Build sdist and wheel
run: |
pip install build --upgrade
python -m build
pip install pip build --upgrade
python -m build --sdist --wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

4 changes: 2 additions & 2 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [isort, black, flake8, docs]
toxenv: [isort, black, flake8]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Install dependencies
run: pip install tox
- run: tox
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.10"
python: "3.12"

sphinx:
configuration: docs/conf.py
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Welcome to stuf_zds_payments's documentation!
:Version: 0.1.0
:Source: https://github.com/maykinmedia/stuf_zds_payments
:Keywords: ``<keywords>``
:PythonVersion: 3.10
:PythonVersion: 3.12

|build-status| |code-quality| |black| |coverage| |docs|

Expand All @@ -30,7 +30,7 @@ Installation
Requirements
------------

* Python 3.10 or above
* Python 3.12 or above
* Django 4.2 or newer


Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ classifiers = [
"Operating System :: Unix",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
]
requires-python = ">=3.10"
requires-python = ">=3.12"
dependencies = [
"django>=4.2"
]
Expand All @@ -45,6 +43,7 @@ tests = [
"isort",
"black",
"flake8",
"vcrpy",
]
docs = [
"sphinx",
Expand Down
6 changes: 6 additions & 0 deletions stuf_zds_payments/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class StufZdsPaymentsConfig(AppConfig):
name = "stuf_zds_payments"
label = "registration_stuf_zds_payments"
verbose_name = _("StUF-ZDS (extra payments) registration plugin")

def ready(self):
from . import plugin # noqa
73 changes: 73 additions & 0 deletions stuf_zds_payments/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from functools import partial

from django.utils import timezone

from openforms.logging import logevent
from stuf.constants import EndpointType
from stuf.models import StufService
from stuf.service_client_factory import ServiceClientFactory, get_client_init_kwargs
from stuf.stuf_zds.client import (
Client as _Client,
NoServiceConfigured,
PaymentStatus,
ZaakOptions,
fmt_soap_date,
)
from stuf.stuf_zds.models import StufZDSConfig


class ZaakOptions(ZaakOptions):
payment_status_update_mapping: list[dict]


class Client(_Client):
def set_zaak_payment(
self,
zaak_identificatie: str,
partial: bool = False,
extra: dict | None = None,
) -> dict:
data = {
"betalings_indicatie": (
PaymentStatus.PARTIAL if partial else PaymentStatus.FULL
),
"laatste_betaaldatum": fmt_soap_date(timezone.now()),
"extra": extra,
}
return self.partial_update_zaak(zaak_identificatie, data)

def partial_update_zaak(self, zaak_identificatie: str, zaak_data: dict) -> None:
context = {
"zaak_identificatie": zaak_identificatie,
**zaak_data,
}

self.execute_call(
soap_action="updateZaak_Lk01",
template="registrations/contrib/stuf_zds_payments/updateZaak.xml",
context=context,
endpoint_type=EndpointType.ontvang_asynchroon,
)


def get_client(options: ZaakOptions):
config = StufZDSConfig.get_solo()
if not (service := config.service):
raise NoServiceConfigured("You must configure a service!")
return StufZDSClient(service, options)


def StufZDSClient(service: StufService, options: ZaakOptions) -> "Client":
factory = ServiceClientFactory(service)
init_kwargs = get_client_init_kwargs(
service,
request_log_hook=partial(logevent.stuf_zds_request, service),
)

return Client.configure_from(
factory,
options=options,
failure_log_callback=partial(logevent.stuf_zds_failure_response, service),
success_log_callback=partial(logevent.stuf_zds_success_response, service),
**init_kwargs,
)
Loading

0 comments on commit 773f47c

Please sign in to comment.