Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
schedule:
# Every 13th and 28th of the month at 07:42
- cron: '42 7 13,28 * *'
- cron: '42 7 13,28 * *'

jobs:
tests:
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Run Tests
env:
DJANGO_VERSION: ${{ matrix.django-version }}
run: "./dev_server.sh -d test"
run: './dev_server.sh -d test'

all-tests:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions dds_registration/fixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ To install test data (for local testting), use:
python manage.py loaddata site-local test-users test-event test-options
```

To add test registration object:
To add test registration and payment objects:

```
python manage.py loaddata test-registration
python manage.py loaddata test-payment-1-created test-registration-1-submited
```

Admin and the first user creating with `test` password.
Expand Down
12 changes: 6 additions & 6 deletions dds_registration/fixtures/test-event.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# @changed 2024.03.28, 15:18
# @changed 2024.04.06, 19:55

- model: dds_registration.event
pk: 1
fields:
id: 1
code: 'first'
title: 'The first event'
description: 'First event description'
description: 'The first event description'
success_email: 'dmia@yandex.ru'
public: 1
registration_open: '2024-03-25'
registration_close: '2024-04-20'
registration_open: '2024-04-06'
registration_close: '2024-04-25'
max_participants: 5
payment_deadline_days: 30
payment_details: ''
refund_last_day: '2024-04-30'
6 changes: 3 additions & 3 deletions dds_registration/fixtures/test-options.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# @changed 2024.03.28, 15:18
# @changed 2024.04.06, 19:59

- model: dds_registration.registrationoption
pk: 1
fields:
id: 1
item: 'Registration'
price: 100
currency: 'USD'
currency: 'CHF'
event_id: 1

- model: dds_registration.registrationoption
pk: 2
fields:
id: 2
item: 'T-Shirt'
price: 10
price: 19
currency: 'USD'
event_id: 1
10 changes: 10 additions & 0 deletions dds_registration/fixtures/test-payment-1-created.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @changed 2024.04.06, 20:05

- model: dds_registration.payment
pk: 1
fields:
id: 1
created: '2024-04-06'
updated: '2024-04-06'
status: 'CREATED'
data: '{"user": {"id": 2, "name": "John Lennon", "address": "251 Menlove Avenue, Liverpool, Merseyside L25 7SA, UK"}, "extra": "", "kind": "event", "method": "STRIPE", "event": {"id": 1, "title": "The first event"}, "registration": {"id": 1}, "option": {"id": 1, "item": "Registration"}, "price": 100.0, "currency": "CHF"}'
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# @changed 2024.03.28, 21:07
# @changed 2024.04.06, 20:01

- model: dds_registration.registration
pk: 1
fields:
id: 1
status: 'SUBMITTED'
created_at: '2024-03-28 20:00:00.000000'
updated_at: '2024-03-28 20:00:00.000000'
created_at: '2024-04-06 19:59:46.154852'
updated_at: '2024-04-06 19:59:46.167242'
event_id: 1
invoice_id: null
payment_id: 1
user_id: 2
option_id: 1
34 changes: 31 additions & 3 deletions dds_registration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
FileType,
Mail,
)
import json

from dds_registration.core.constants.payments import (
site_default_currency,
Expand Down Expand Up @@ -175,6 +176,7 @@ class Payment(Model):
# ("WISE", "Wise"), # Not yet implemented
]
DEFAULT_METHOD = "INVOICE"
# Use `get_method_name` helper (below) to get method name

# # User name and address, initialized by user's ones, by default
# name = models.TextField(blank=False, default="")
Expand All @@ -193,6 +195,33 @@ class Payment(Model):
# invoice or a receipt
data = models.JSONField(help_text="Read-only JSON object", default=dict)

def get_data(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No JSON anything is needed, all of that is done automatically. You are making this much more complicated than it needs to be. Please see #133 for a clean way to fix this issue.

data = self.data
if isinstance(data, str):
# Parse json...
try:
data = json.loads(data)
except:
# TODO: Throw an exception?
data = {}
return data


def get_method_name(self):
data = self.get_data()
method = data['method']
methods = dict(Payment.METHODS)
if not method in methods:
# TODO: To throw an error?
return None
return methods[method]


@property
def method_name(self):
return self.get_method_name()


def mark_paid(self):
if self.status == "PAID":
return
Expand Down Expand Up @@ -344,13 +373,12 @@ class Event(Model):
code = models.TextField(unique=True, default=random_code) # Show as an input
title = models.TextField(unique=True, null=False, blank=False) # Show as an input
description = models.TextField(blank=False, null=False)
# `success_email`: Can't see a description for this field. Can't see its usage anywhere in the app. Why is it required? Which email(s) should be here?
success_email = models.TextField(blank=False, null=False)
public = models.BooleanField(default=True)
registration_open = models.DateField(auto_now_add=True, help_text="Date registration opens (inclusive)")
registration_close = models.DateField(help_text="Date registration closes (inclusive)")
refund_last_day = models.DateField(
null=True, help_text="Last day that a fee refund can be offered"
)
refund_last_day = models.DateField(null=True, help_text="Last day that a fee refund can be offered")
max_participants = models.PositiveIntegerField(
default=0,
help_text="Maximum number of participants (0 = no limit)",
Expand Down
3 changes: 2 additions & 1 deletion dds_registration/views/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def membership_application(request: HttpRequest):
form = MembershipForm(request.POST)

if form.is_valid():
payment_method = form.cleaned_data["payment_method"]
payment = Payment(
status="CREATED",
data={
Expand All @@ -41,7 +42,7 @@ def membership_application(request: HttpRequest):
"membership": {
"type": form.cleaned_data["membership_type"],
},
"method": form.cleaned_data["payment_method"],
"method": payment_method,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the idea behind this change? You create a variable to only use it once. I suggest reverting this change.

"price": MEMBERSHIP_DATA[form.cleaned_data["membership_type"]]["price"],
"currency": MEMBERSHIP_DATA[form.cleaned_data["membership_type"]]["currency"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,3 @@
</div>
{% endfor %}
</fieldset>


2 changes: 1 addition & 1 deletion src/assets/events-list-table/events-list-table.django
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</td>
<td class="col-payment">
{% if payment %}
{{ payment.get_payment_method_display }}
{{ payment.get_method_name }}
{% endif %}
</td>
<td class="col-paid">
Expand Down
21 changes: 9 additions & 12 deletions src/assets/scripts.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/**
* @desc Main js entry point module (scripts)
* @module src/assets/scripts.ts
* @changed 2024.04.04, 16:06
* @changed 2024.04.06, 22:00
*/

/* NOTE: These modules are unused. Used only
* `src/assets/stripe-init/stripe_payment_intents_support.ts`, via requirejs,
* without exposing to global scope.
/* // NOTE: These modules are unused. Used only
* // `src/assets/stripe-init/stripe_payment_intents_support.ts`, via requirejs,
* // without exposing to global scope.
*
* import { billing_event_stripe_payment_proceed } from './stripe-init/billing_event_stripe_payment_proceed';
* import { billing_membership_stripe_payment_proceed } from './stripe-init/billing_membership_stripe_payment_proceed';
*
* // Expose functions to global scope...
* window.billing_event_stripe_payment_proceed = billing_event_stripe_payment_proceed;
* window.billing_membership_stripe_payment_proceed = billing_membership_stripe_payment_proceed;
* import { startStripeElementsForm } from './stripe-init/stripe_payment_intents_support';
*
* console.log('[scripts] Main client code entry point', {
* billing_event_stripe_payment_proceed,
* billing_membership_stripe_payment_proceed,
* startStripeElementsForm,
* });
*/

// Empty root module
export {};
29 changes: 8 additions & 21 deletions static/assets/scripts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading