Skip to content

Commit 72a1189

Browse files
moacirmodarenzon
authored andcommitted
Implemented One Time Offer Page
close #1924
1 parent 7ad9376 commit 72a1189

File tree

9 files changed

+1282
-579
lines changed

9 files changed

+1282
-579
lines changed

pythonpro/core/tests/test_lead_landing_page.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ def test_only_role_lead_can_change_password(resp_lead_change_pasword, django_use
112112

113113
response = client.get(reverse('core:lead_change_password'), secure=True)
114114
assert response.status_code == 302
115+
116+
117+
def test_should_redirect_to_OTO_page(resp_lead_creation):
118+
assert resp_lead_creation['Location'] == reverse('payments:client_landing_page_oto')

pythonpro/core/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@ def lead_form(request):
151151
except user_facade.UserCreationException as e:
152152
return render(request, 'core/lead_form_errors.html', context={'form': e.form})
153153
login(request, user)
154-
return redirect(reverse('core:lead_change_password'))
154+
return redirect(reverse('payments:client_landing_page_oto'))

pythonpro/payments/facade.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timedelta
22
from typing import Tuple
33

44
import pagarme as _pagarme
@@ -9,13 +9,26 @@
99
_pagarme.authentication_key(settings.PAGARME_API_KEY)
1010

1111
PYTOOLS_PRICE = 39700
12-
PYTOOLS_PROMOTION_PRICE = 9700
12+
PYTOOLS_PROMOTION_PRICE = 9700 # flashning launch
13+
PYTOOLS_OTO_PRICE = 9700 # one time offer in python birds thank you page
1314
MEMBERSHIP_PRICE = 159990
1415
MEMBERSHIP_DISCOUNT_FOR_CLIENTS = 10000
1516

1617

18+
def _discover_pytools_price(user_creation: datetime):
19+
price = PYTOOLS_PRICE
20+
21+
if is_on_pytools_oto_season(user_creation):
22+
price = PYTOOLS_OTO_PRICE
23+
24+
elif is_on_pytools_promotion_season(user_creation):
25+
price = PYTOOLS_PROMOTION_PRICE
26+
27+
return price
28+
29+
1730
def pytools_capture(token: str, user_creation: datetime):
18-
price = PYTOOLS_PROMOTION_PRICE if is_on_pytools_promotion_season(user_creation) else PYTOOLS_PRICE
31+
price = _discover_pytools_price(user_creation)
1932
amount = _pagarme.transaction.find_by_id(token)['amount']
2033
if amount < price:
2134
raise PagarmeValidationException(f'Payment done ({amount}) is less then price ({price}) for token: {token}')
@@ -95,3 +108,19 @@ def calculate_7th_week_before_promotion() -> Tuple[datetime, datetime]:
95108
creation_begin = promotion_begin + relativedelta(weekday=MO(-8))
96109
creation_end = creation_begin + relativedelta(days=6, hour=23, minute=59, second=59)
97110
return creation_begin, creation_end
111+
112+
113+
def calculate_oto_expires_datetime(user_creation: datetime) -> datetime:
114+
"""
115+
Calculate datetime expiration for OTO pytools offer.
116+
:return: datetime
117+
"""
118+
return user_creation + timedelta(minutes=30)
119+
120+
121+
def is_on_pytools_oto_season(user_creation: datetime) -> bool:
122+
"""
123+
Chekc if user is available to receive Pytools OTO.
124+
:return: boolean
125+
"""
126+
return calculate_oto_expires_datetime(user_creation) > now()

pythonpro/payments/templates/payments/client_landing_page.html

Lines changed: 609 additions & 572 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)