mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-30 20:05:41 +00:00
Refactor payment verification to use PAYMENT_BASE_URL from environment variables and improve error handling for missing configuration
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m31s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m31s
This commit is contained in:
parent
2431793886
commit
929c6168a4
@ -15,7 +15,7 @@ EMAIL_PORT=
|
||||
EMAIL_USERNAME=
|
||||
EMAIL_PASSWORD=
|
||||
|
||||
PAYMENT_VERIFY_BASE_URL=""
|
||||
PAYMENT_BASE_URL=""
|
||||
FRONTEND_URL=""
|
||||
|
||||
SMS_API_URL=""
|
||||
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
import requests
|
||||
from decouple import config
|
||||
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.response import Response
|
||||
|
||||
@ -13,6 +13,19 @@ from api.mixins import StaffEditorPermissionMixin
|
||||
from .models import Device, Payment
|
||||
from .serializers import PaymentSerializer, UpdatePaymentSerializer
|
||||
|
||||
from apibase.env import env, BASE_DIR
|
||||
from django.utils.timezone import localtime
|
||||
import os
|
||||
|
||||
env.read_env(os.path.join(BASE_DIR, ".env"))
|
||||
|
||||
PAYMENT_BASE_URL = env("PAYMENT_BASE_URL", default=None)
|
||||
if not PAYMENT_BASE_URL:
|
||||
raise ValueError(
|
||||
"PAYMENT_BASE_URL is not set. Please set it in your environment variables."
|
||||
)
|
||||
print("PAYMENT_BASE_URL from env:", PAYMENT_BASE_URL)
|
||||
|
||||
|
||||
class InsufficientFundsError(Exception):
|
||||
pass
|
||||
@ -145,7 +158,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
"benefName": f"{user.first_name} {user.last_name}",
|
||||
"accountNo": user.acc_no,
|
||||
"absAmount": payment.amount,
|
||||
"time": (timezone.now() + timedelta(minutes=5)).strftime(
|
||||
"time": localtime(timezone.now() + timedelta(minutes=5)).strftime(
|
||||
"%Y-%m-%d %H:%M"
|
||||
),
|
||||
}
|
||||
@ -180,9 +193,9 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
return True
|
||||
|
||||
def verify_transfer_payment(self, data, payment):
|
||||
print("verifying transfer payment...")
|
||||
print(data)
|
||||
response = requests.post(
|
||||
f"{config('PAYMENT_VERIFY_BASE_URL')}/verify-payment",
|
||||
f"{PAYMENT_BASE_URL}/verify-payment",
|
||||
json=data,
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user