forked from fossasia/eventyay-tickets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement schedule task to collect billing invoice (fossasia#417)
* Implement schedule task to collect billing invoice * consider sourcery-ai and fix isort * Implement billing settings form for organizer * Fix flake8 in pipeline * implement create and save payment_information * Fix isort, flake8 in pipeline * implement payment-information-v1 * src/pretix/control/views/organizer_views/organizer_view.py * Code refactoring * Code refactoring * Remove payment_information attribute * Implement tax validation * Update code * Update code * Fix flake8 in pipeline * Add pyvat package * Fix flake8 in pipeline * Latest code * Fix flake8 in pipeline * Add logger error * Fix flake8 in pipeline * implement trigger invoice to organizer * Fix conflict pretix/base/migration * Implement auto billing charge * Fix conflict pretix base migration * Update pretix base migration * Add logging information and modify error logging * Implement auto billing charge * update schedule task * fix isort, flake8 and update branch * fix isort pipeline * Implement automatic payment charging * update invoice template * change var name, format code * Implement automatic payment charging * Add comment * Implement show error message * handle case update invoice to expired * fix isort, flake8 pipeline * Update api to trigger billing task for testing * Implement stripe webhook secret key in global setting * Add comment,save tax_id, show error and sucess message * handle case get mail backend for global settings * fix isort pipeline * fix sending custom mail smtp * tickets fee should be calculated based on net amount * remove unsed import to fix pipeline * correct import to fix isort * Update code * Fix flake8 in pipeline * Update code * Update code * Update code * fix flake8 in pipeline * move validation to clean method and move get_country_name to countries helper * formar code * merge migration file * fix isort --------- Co-authored-by: lcduong <lcduong> Co-authored-by: odkhang <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,103 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[program:pretixtask] | ||
command=/usr/local/bin/pretix taskbeat | ||
autostart=true | ||
autorestart=true | ||
priority=5 | ||
user=pretixuser | ||
stdout_logfile=/dev/fd/1 | ||
stdout_logfile_maxbytes=0 | ||
stderr_logfile=/dev/fd/2 | ||
stderr_logfile_maxbytes=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
import stripe | ||
from django.http import HttpResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
from pretix.eventyay_common.tasks import update_billing_invoice_information | ||
from pretix.helpers.stripe_utils import ( | ||
get_stripe_secret_key, get_stripe_webhook_secret_key, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@csrf_exempt | ||
def stripe_webhook_view(request): | ||
stripe.api_key = get_stripe_secret_key() | ||
payload = request.body | ||
webhook_secret_key = get_stripe_webhook_secret_key() | ||
sig_header = request.META['HTTP_STRIPE_SIGNATURE'] | ||
|
||
try: | ||
event = stripe.Webhook.construct_event( | ||
payload, sig_header, webhook_secret_key | ||
) | ||
except ValueError as e: | ||
logger.error("Error parsing payload: %s", str(e)) | ||
return HttpResponse("Invalid payload", status=400) | ||
except stripe.error.SignatureVerificationError as e: | ||
logger.error("Error verifying webhook signature: %s", str(e)) | ||
return HttpResponse("Invalid signature", status=400) | ||
|
||
if event.type == 'payment_intent.succeeded': | ||
invoice_id = event.data.object.get('metadata', {}).get('invoice_id') | ||
update_billing_invoice_information.delay(invoice_id=invoice_id) | ||
|
||
return HttpResponse("Success", status=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Generated by Django 5.1.3 on 2024-11-19 04:50 | ||
|
||
import datetime | ||
|
||
import django.contrib.postgres.fields | ||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import pretix.base.models.base | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"pretixbase", | ||
"0003_alter_cachedcombinedticket_id_alter_cachedticket_id_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="BillingInvoice", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False | ||
), | ||
), | ||
("status", models.CharField(default="n", max_length=1)), | ||
("amount", models.DecimalField(decimal_places=2, max_digits=10)), | ||
("currency", models.CharField(max_length=3)), | ||
("ticket_fee", models.DecimalField(decimal_places=2, max_digits=10)), | ||
("payment_method", models.CharField(max_length=20, null=True)), | ||
("paid_datetime", models.DateTimeField(blank=True, null=True)), | ||
("note", models.TextField(null=True)), | ||
("monthly_bill", models.DateField(default=datetime.date.today)), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("created_by", models.CharField(max_length=50)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("updated_by", models.CharField(max_length=50)), | ||
("last_reminder_datetime", models.DateTimeField(blank=True, null=True)), | ||
("next_reminder_datetime", models.DateTimeField(blank=True, null=True)), | ||
( | ||
"reminder_schedule", | ||
django.contrib.postgres.fields.ArrayField( | ||
base_field=models.IntegerField(), default=list, size=None | ||
), | ||
), | ||
("reminder_enabled", models.BooleanField(default=True)), | ||
( | ||
"stripe_payment_intent_id", | ||
models.CharField(max_length=50, null=True), | ||
), | ||
( | ||
"event", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="pretixbase.event", | ||
), | ||
), | ||
( | ||
"organizer", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="pretixbase.organizer", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Billing Invoice", | ||
"verbose_name_plural": "Billing Invoices", | ||
"ordering": ("-created_at",), | ||
}, | ||
bases=(models.Model, pretix.base.models.base.LoggingMixin), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from datetime import date | ||
|
||
from django.contrib.postgres.fields import ArrayField | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from django_scopes import ScopedManager | ||
|
||
from pretix.base.models import LoggedModel | ||
|
||
|
||
class BillingInvoice(LoggedModel): | ||
STATUS_PENDING = "n" | ||
STATUS_PAID = "p" | ||
STATUS_EXPIRED = "e" | ||
STATUS_CANCELED = "c" | ||
|
||
STATUS_CHOICES = [ | ||
(STATUS_PENDING, _("pending")), | ||
(STATUS_PAID, _("paid")), | ||
(STATUS_EXPIRED, _("expired")), | ||
(STATUS_CANCELED, _("canceled")), | ||
] | ||
|
||
organizer = models.ForeignKey('Organizer', on_delete=models.CASCADE) | ||
# organizer_billing = models.ForeignKey('OrganizerBilling', on_delete=models.CASCADE) | ||
event = models.ForeignKey('Event', on_delete=models.CASCADE) | ||
|
||
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=STATUS_PENDING) | ||
amount = models.DecimalField(max_digits=10, decimal_places=2) | ||
currency = models.CharField(max_length=3) | ||
|
||
ticket_fee = models.DecimalField(max_digits=10, decimal_places=2) | ||
payment_method = models.CharField(max_length=20, null=True, blank=True) | ||
paid_datetime = models.DateTimeField(null=True, blank=True) | ||
note = models.TextField(null=True, blank=True) | ||
|
||
monthly_bill = models.DateField(default=date.today) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
created_by = models.CharField(max_length=50) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
updated_by = models.CharField(max_length=50) | ||
|
||
last_reminder_datetime = models.DateTimeField(null=True, blank=True) | ||
next_reminder_datetime = models.DateTimeField(null=True, blank=True) | ||
reminder_schedule = ArrayField( | ||
models.IntegerField(), | ||
default=list, # Sets the default to an empty list | ||
blank=True, | ||
help_text="Days after creation for reminders, e.g., [14, 28]" | ||
) | ||
reminder_enabled = models.BooleanField(default=True) | ||
stripe_payment_intent_id = models.CharField(max_length=50, null=True, blank=True) | ||
|
||
objects = ScopedManager(organizer='organizer') | ||
|
||
class Meta: | ||
verbose_name = "Billing Invoice" | ||
verbose_name_plural = "Billing Invoices" | ||
ordering = ("-created_at",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.