|
1 | | -from datetime import datetime |
| 1 | +from datetime import datetime, timedelta |
2 | 2 | from typing import Tuple |
3 | 3 |
|
4 | 4 | import pagarme as _pagarme |
|
9 | 9 | _pagarme.authentication_key(settings.PAGARME_API_KEY) |
10 | 10 |
|
11 | 11 | 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 |
13 | 14 | MEMBERSHIP_PRICE = 159990 |
14 | 15 | MEMBERSHIP_DISCOUNT_FOR_CLIENTS = 10000 |
15 | 16 |
|
16 | 17 |
|
| 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 | + |
17 | 30 | 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) |
19 | 32 | amount = _pagarme.transaction.find_by_id(token)['amount'] |
20 | 33 | if amount < price: |
21 | 34 | 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]: |
95 | 108 | creation_begin = promotion_begin + relativedelta(weekday=MO(-8)) |
96 | 109 | creation_end = creation_begin + relativedelta(days=6, hour=23, minute=59, second=59) |
97 | 110 | 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() |
0 commit comments