Private
Public Access
1
0

some more work

This commit is contained in:
2024-11-16 16:35:37 +01:00
parent 6a759b637f
commit e5effd5567
2 changed files with 44 additions and 3 deletions

View File

@@ -1,9 +1,10 @@
from rowers.models import Rower, PaidPlan, CoachingGroup
from rowers.models import Rower, PaidPlan, CoachingGroup, iDokladToken
from rowers.utils import ProcessorCustomerError
from rowsandall_app.settings import (
BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY,
BRAINTREE_SANDBOX_MERCHANT_ID, BRAINTREE_SANDBOX_PUBLIC_KEY,
BRAINTREE_SANDBOX_PRIVATE_KEY, BRAINTREE_MERCHANT_ACCOUNT_ID
BRAINTREE_SANDBOX_PRIVATE_KEY, BRAINTREE_MERCHANT_ACCOUNT_ID,
IDOKLAD_CLIENT_ID, IDOKLAD_CLIENT_SECRET, IDOKLAD_REDIRECT_URI,
)
import pandas as pd
from rowers.utils import dologging
@@ -52,6 +53,46 @@ else:
)
)
def idoklad_token():
try:
token = iDokladToken.objects.get(id=1)
except iDokladToken.DoesNotExist:
return None
if token.updated_at + datetime.timedelta(seconds=token.expires_in) < timezone.now():
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'grant_type': 'refresh_token',
'client_id': IDOKLAD_CLIENT_ID,
'client_secret': IDOKLAD_CLIENT_SECRET,
'scope': 'eet offline_access',
'refresh_token': token.refresh_token,
}
response = requests.post('https://app.idoklad.cz/identity/server/connect/token', headers=headers, data=data)
if response.status_code == 200:
token = response.json()
token['updated_at'] = timezone.now()
iDokladToken.objects.filter(id=1).update(**token)
else:
return None
return token
def prepare_invoice():
token = idoklad_token()
if token is None:
return None
data = {
'templateId': 1,
}
def process_webhook(notification):
if not settings.TESTING: # pragma: no cover