mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-05-01 02:15: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_USERNAME=
|
||||||
EMAIL_PASSWORD=
|
EMAIL_PASSWORD=
|
||||||
|
|
||||||
PAYMENT_VERIFY_BASE_URL=""
|
PAYMENT_BASE_URL=""
|
||||||
FRONTEND_URL=""
|
FRONTEND_URL=""
|
||||||
|
|
||||||
SMS_API_URL=""
|
SMS_API_URL=""
|
||||||
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from decouple import config
|
|
||||||
from rest_framework import generics, status
|
from rest_framework import generics, status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
@ -13,6 +13,19 @@ from api.mixins import StaffEditorPermissionMixin
|
|||||||
from .models import Device, Payment
|
from .models import Device, Payment
|
||||||
from .serializers import PaymentSerializer, UpdatePaymentSerializer
|
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):
|
class InsufficientFundsError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -145,7 +158,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
"benefName": f"{user.first_name} {user.last_name}",
|
"benefName": f"{user.first_name} {user.last_name}",
|
||||||
"accountNo": user.acc_no,
|
"accountNo": user.acc_no,
|
||||||
"absAmount": payment.amount,
|
"absAmount": payment.amount,
|
||||||
"time": (timezone.now() + timedelta(minutes=5)).strftime(
|
"time": localtime(timezone.now() + timedelta(minutes=5)).strftime(
|
||||||
"%Y-%m-%d %H:%M"
|
"%Y-%m-%d %H:%M"
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@ -180,9 +193,9 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def verify_transfer_payment(self, data, payment):
|
def verify_transfer_payment(self, data, payment):
|
||||||
print("verifying transfer payment...")
|
print(data)
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{config('PAYMENT_VERIFY_BASE_URL')}/verify-payment",
|
f"{PAYMENT_BASE_URL}/verify-payment",
|
||||||
json=data,
|
json=data,
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user