-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor payments module to apply plugin mechanism consistently #4921
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Mapping | ||
from typing import TYPE_CHECKING, Mapping, TypedDict | ||
|
||
from django.http import HttpRequest, HttpResponse | ||
|
||
from rest_framework import serializers | ||
from rest_framework.request import Request | ||
|
||
from openforms.plugins.plugin import AbstractBasePlugin | ||
from openforms.utils.mixins import JsonSchemaSerializerMixin | ||
|
@@ -32,45 +35,53 @@ class EmptyOptions(JsonSchemaSerializerMixin, serializers.Serializer): | |
pass | ||
|
||
|
||
class BasePlugin(AbstractBasePlugin): | ||
class Options(TypedDict): | ||
pass | ||
|
||
|
||
class BasePlugin[OptionsT: Options](AbstractBasePlugin): | ||
return_method = "GET" | ||
webhook_method = "POST" | ||
configuration_options = EmptyOptions | ||
configuration_options: type[serializers.Serializer] = EmptyOptions | ||
|
||
# override | ||
|
||
def start_payment( | ||
self, | ||
request: HttpRequest, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this stays HttpRequest because it's called outside of DRF views too |
||
payment: "SubmissionPayment", | ||
payment: SubmissionPayment, | ||
options: OptionsT, | ||
) -> PaymentInfo: | ||
raise NotImplementedError() | ||
|
||
def handle_return( | ||
self, request: HttpRequest, payment: "SubmissionPayment" | ||
self, | ||
request: Request, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to DRF request because plugin code is accessing DRF-specific properties that don't exist on |
||
payment: SubmissionPayment, | ||
options: OptionsT, | ||
) -> HttpResponse: | ||
raise NotImplementedError() | ||
|
||
def handle_webhook(self, request: HttpRequest) -> "SubmissionPayment": | ||
def handle_webhook(self, request: Request) -> SubmissionPayment: | ||
raise NotImplementedError() | ||
|
||
# helpers | ||
|
||
def get_start_url(self, request: HttpRequest, submission: "Submission") -> str: | ||
def get_start_url(self, request: HttpRequest, submission: Submission) -> str: | ||
return reverse_plus( | ||
"payments:start", | ||
kwargs={"uuid": submission.uuid, "plugin_id": self.identifier}, | ||
request=request, | ||
) | ||
|
||
def get_return_url(self, request: HttpRequest, payment: "SubmissionPayment") -> str: | ||
def get_return_url(self, request: HttpRequest, payment: SubmissionPayment) -> str: | ||
return reverse_plus( | ||
"payments:return", | ||
kwargs={"uuid": payment.uuid}, | ||
request=request, | ||
) | ||
|
||
def get_webhook_url(self, request: HttpRequest) -> str: | ||
def get_webhook_url(self, request: HttpRequest | None) -> str: | ||
return reverse_plus( | ||
"payments:webhook", | ||
kwargs={"plugin_id": self.identifier}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
irrelevant/unused because we only support the React-based change form page.