Skip to content

Commit aa58cdc

Browse files
committed
Allow to enable payment method and create an order with it.
1 parent 7422444 commit aa58cdc

4 files changed

Lines changed: 92 additions & 5 deletions

File tree

pretix_pix_manual/apps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
class PluginApp(PluginConfig):
1212
default = True
1313
name = "pretix_pix_manual"
14-
verbose_name = "PIX Manual"
14+
verbose_name = "Brazilian Pix - Manual processing"
1515

1616
class PretixPluginMeta:
17-
name = gettext_lazy("PIX Manual")
17+
name = gettext_lazy("Brazilian Pix - Manual processing")
1818
author = "Renne Rocha"
19-
description = gettext_lazy("Pagamento PIX com confimação manual")
19+
description = gettext_lazy("Brazilian Pix - Manual processing")
2020
visible = True
2121
version = __version__
2222
category = "PAYMENT"

pretix_pix_manual/payment.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from collections import OrderedDict
2+
3+
from django import forms
4+
from django.core.exceptions import ValidationError
5+
from django.utils.translation import gettext_lazy as _
6+
7+
from pretix.base.payment import BasePaymentProvider
8+
9+
10+
def _is_valid_pix_key(pix_key):
11+
return True
12+
13+
14+
class PixManual(BasePaymentProvider):
15+
identifier = "pix_manual"
16+
verbose_name = _("Brazilian Pix - Manual processing")
17+
18+
@property
19+
def settings_form_fields(self):
20+
default_form_fields = list(super().settings_form_fields.items())
21+
custom_keys = [
22+
(
23+
"_pix_key",
24+
forms.CharField(
25+
label=_("Pix key"),
26+
help_text=_(
27+
"Pix key that will be used to receive payments. "
28+
"It can be an email address, phone number, CNPJ, "
29+
"CPF, or a random key generated by your bank."
30+
),
31+
required=True,
32+
),
33+
)
34+
]
35+
return OrderedDict(custom_keys + default_form_fields)
36+
37+
def settings_form_clean(self, cleaned_data):
38+
pix_key = cleaned_data.get("payment_pix_manual__pix_key")
39+
if not _is_valid_pix_key(pix_key):
40+
raise ValidationError(
41+
{"payment_pix_manual__pix_key": _("Please provide a valid Pix key.")}
42+
)
43+
44+
return cleaned_data
45+
46+
def settings_content_render(self, request):
47+
return _(
48+
"This payment method will generate a Pix key with order information "
49+
"that your customer can use to make the payment. Payment confirmation, "
50+
"cancellations, and refunds must be done manually."
51+
)
52+
53+
@property
54+
def test_mode_message(self):
55+
return _(
56+
"In test mode, you can just manually mark this order as paid in the backend "
57+
"after it has been created."
58+
)
59+
60+
def payment_is_valid_session(self, request):
61+
return True
62+
63+
def checkout_confirm_render(self, request, order=None, info_data=None):
64+
return "Review order info"
65+
66+
def order_pending_mail_render(self, order, payment):
67+
return "Alguma coisa no email de confirmação"
68+
69+
def payment_pending_render(self, request, payment):
70+
"""
71+
Render customer-facing instructions on how to proceed with a pending payment
72+
73+
:return: HTML
74+
"""
75+
return "como vou pagar essa bodega"

pretix_pix_manual/signals.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
# Register your receivers here
1+
from django.dispatch import receiver
2+
3+
from pretix.base.signals import register_payment_providers
4+
5+
6+
@receiver(register_payment_providers, dispatch_uid="pretix_pix_manual")
7+
def register_payment_provider(sender, **kwargs):
8+
from .payment import PixManual
9+
10+
return PixManual

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from setuptools import setup
22

33

4-
setup()
4+
setup(entry_points="""
5+
[pretix.plugin]
6+
pretix_pix_manual=pretix_pix_manual:PretixPluginMeta
7+
""")

0 commit comments

Comments
 (0)