feat: public id
This commit is contained in:
@@ -84,7 +84,8 @@ class Settings(BaseSettings):
|
|||||||
RABBIT_CONNECT_TIMEOUT: int = 5
|
RABBIT_CONNECT_TIMEOUT: int = 5
|
||||||
RABBIT_EMAIL_CODE_QUEUE: str = "email.verification_code"
|
RABBIT_EMAIL_CODE_QUEUE: str = "email.verification_code"
|
||||||
|
|
||||||
ITPAY_AUTHORIZATION: str
|
ITPAY_PUBLIC_ID: str
|
||||||
|
ITPAY_API_SECRET: str
|
||||||
|
|
||||||
LOG_LEVEL: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"
|
LOG_LEVEL: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"
|
||||||
LOG_FORMAT: Literal["JSON", "TEXT"] = "TEXT"
|
LOG_FORMAT: Literal["JSON", "TEXT"] = "TEXT"
|
||||||
@@ -151,7 +152,6 @@ class Settings(BaseSettings):
|
|||||||
database = read_secret('database')
|
database = read_secret('database')
|
||||||
csrf = read_secret_optional('csrf')
|
csrf = read_secret_optional('csrf')
|
||||||
rabbitmq = read_secret_optional('rabbitmq')
|
rabbitmq = read_secret_optional('rabbitmq')
|
||||||
itpay = read_secret_optional('itpay')
|
|
||||||
|
|
||||||
db_ci = {str(k).lower(): v for k, v in database.items()}
|
db_ci = {str(k).lower(): v for k, v in database.items()}
|
||||||
|
|
||||||
@@ -200,11 +200,27 @@ class Settings(BaseSettings):
|
|||||||
rb_set('password','RABBIT_PASSWORD')
|
rb_set('password','RABBIT_PASSWORD')
|
||||||
rb_set('vhost','RABBIT_VHOST')
|
rb_set('vhost','RABBIT_VHOST')
|
||||||
|
|
||||||
if itpay:
|
itpay_public_id = data.get('ITPAY_PUBLIC_ID') or os.getenv('ITPAY_PUBLIC_ID')
|
||||||
|
itpay_api_secret = data.get('ITPAY_API_SECRET') or os.getenv('ITPAY_API_SECRET')
|
||||||
|
if itpay_public_id is not None and str(itpay_public_id).strip() and itpay_api_secret is not None and str(itpay_api_secret).strip():
|
||||||
|
data['ITPAY_PUBLIC_ID'] = str(itpay_public_id).strip()
|
||||||
|
data['ITPAY_API_SECRET'] = str(itpay_api_secret).strip()
|
||||||
|
else:
|
||||||
|
itpay = read_secret('itpay')
|
||||||
itpay_ci = {str(k).lower(): v for k, v in itpay.items()}
|
itpay_ci = {str(k).lower(): v for k, v in itpay.items()}
|
||||||
secret = itpay_ci.get('secret')
|
public_id = itpay_ci.get('public_id')
|
||||||
if secret is not None and str(secret).strip():
|
api_secret = itpay_ci.get('api_secret')
|
||||||
data['ITPAY_AUTHORIZATION'] = f'Token {str(secret).strip()}'
|
if api_secret is None:
|
||||||
|
api_secret = itpay_ci.get('secret')
|
||||||
|
missing = []
|
||||||
|
if public_id is None or not str(public_id).strip():
|
||||||
|
missing.append('public_id')
|
||||||
|
if api_secret is None or not str(api_secret).strip():
|
||||||
|
missing.append('api_secret')
|
||||||
|
if missing:
|
||||||
|
raise RuntimeError(f'Vault secret itpay missing non-empty keys: {missing} (mount={mount},path=itpay)')
|
||||||
|
data['ITPAY_PUBLIC_ID'] = str(public_id).strip()
|
||||||
|
data['ITPAY_API_SECRET'] = str(api_secret).strip()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
@@ -52,14 +52,14 @@ async def create_order(
|
|||||||
}
|
}
|
||||||
url = f'{ITPAY_API_BASE}/v1/payments'
|
url = f'{ITPAY_API_BASE}/v1/payments'
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': settings.ITPAY_AUTHORIZATION,
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
timeout = aiohttp.ClientTimeout(total=30)
|
timeout = aiohttp.ClientTimeout(total=30)
|
||||||
async with aiohttp.ClientSession(timeout=timeout) as session:
|
async with aiohttp.ClientSession(timeout=timeout) as session:
|
||||||
async with session.post(url, json=payload, headers=headers) as resp:
|
auth = aiohttp.BasicAuth(settings.ITPAY_PUBLIC_ID, settings.ITPAY_API_SECRET)
|
||||||
|
async with session.post(url, json=payload, headers=headers, auth=auth) as resp:
|
||||||
response_text = await resp.text()
|
response_text = await resp.text()
|
||||||
try:
|
try:
|
||||||
response_json = json.loads(response_text)
|
response_json = json.loads(response_text)
|
||||||
|
|||||||
Reference in New Issue
Block a user