|
| 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" |
0 commit comments