refactor: update Cashfree credential verification endpoint and add API version header
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 28s
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 28s
This commit is contained in:
parent
a454af5ab6
commit
a03df35dd5
1 changed files with 20 additions and 14 deletions
|
|
@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class CashfreeSecureIDClient:
|
||||
"""
|
||||
Service client for Cashfree Secure ID (Verification Suite) APIs.
|
||||
Service client for Cashfree Secure ID (Verification Suite / VRS) APIs.
|
||||
Supports both Sandbox (TEST) and Production (PROD) environments.
|
||||
Includes built-in test-data fallback for immediate interactive testing.
|
||||
"""
|
||||
|
|
@ -40,7 +40,7 @@ class CashfreeSecureIDClient:
|
|||
|
||||
def verify_credentials(self):
|
||||
"""
|
||||
Verify if provided Cashfree credentials are valid.
|
||||
Verify if provided Cashfree Verification Suite credentials are valid.
|
||||
"""
|
||||
if not self.has_credentials():
|
||||
return {
|
||||
|
|
@ -50,14 +50,21 @@ class CashfreeSecureIDClient:
|
|||
"data": None
|
||||
}
|
||||
|
||||
url = f"{self.base_url}/api/v1/credentials/verify"
|
||||
# Test credentials against IFSC verification endpoint
|
||||
url = f"{self.base_url}/ifsc"
|
||||
payload = {"ifsc": "YESB0000262"}
|
||||
try:
|
||||
res = requests.post(url, headers=self._get_headers(), timeout=10)
|
||||
res = requests.post(url, headers=self._get_headers(), json=payload, timeout=10)
|
||||
res_data = res.json() if res.headers.get("content-type", "").startswith("application/json") else res.text
|
||||
|
||||
# Check for success or specific credential error
|
||||
is_valid = res.status_code == 200 or (isinstance(res_data, dict) and res_data.get("status") == "SUCCESS")
|
||||
|
||||
return {
|
||||
"success": res.status_code == 200,
|
||||
"success": is_valid,
|
||||
"status_code": res.status_code,
|
||||
"data": res.json() if res.headers.get("content-type", "").startswith("application/json") else res.text,
|
||||
"curl": f"curl -X POST '{url}' -H 'x-client-id: {self.client_id}' -H 'x-client-secret: [REDACTED]'"
|
||||
"data": res_data,
|
||||
"curl": f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'x-api-version: 2024-01-01' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
|
|
@ -75,7 +82,7 @@ class CashfreeSecureIDClient:
|
|||
payload["name"] = name.strip()
|
||||
|
||||
url = f"{self.base_url}/pan"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'x-api-version: 2024-01-01' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
|
||||
if self.has_credentials():
|
||||
try:
|
||||
|
|
@ -128,7 +135,6 @@ class CashfreeSecureIDClient:
|
|||
}
|
||||
status_code = 400
|
||||
else:
|
||||
# Default response for custom input
|
||||
mock_res = {
|
||||
"reference_id": 982343,
|
||||
"pan": pan,
|
||||
|
|
@ -156,7 +162,7 @@ class CashfreeSecureIDClient:
|
|||
payload = {"aadhaar_number": aadhaar_number}
|
||||
|
||||
url = f"{self.base_url}/aadhaar" if action == "verify" else f"{self.base_url}/aadhaar/masking"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'x-api-version: 2024-01-01' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
|
||||
if self.has_credentials():
|
||||
try:
|
||||
|
|
@ -235,7 +241,7 @@ class CashfreeSecureIDClient:
|
|||
gstin = gstin.strip().upper()
|
||||
payload = {"gstin": gstin}
|
||||
url = f"{self.base_url}/gstin"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'x-api-version: 2024-01-01' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
|
||||
if self.has_credentials():
|
||||
try:
|
||||
|
|
@ -333,7 +339,7 @@ class CashfreeSecureIDClient:
|
|||
ifsc = ifsc.strip().upper()
|
||||
payload = {"ifsc": ifsc}
|
||||
url = f"{self.base_url}/ifsc"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'x-api-version: 2024-01-01' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
|
||||
if self.has_credentials():
|
||||
try:
|
||||
|
|
@ -452,7 +458,7 @@ class CashfreeSecureIDClient:
|
|||
payload["phone"] = phone.strip()
|
||||
|
||||
url = f"{self.base_url}/bank-account/sync"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
curl_cmd = f"curl -X POST '{url}' \\\n -H 'x-client-id: {self.client_id or 'YOUR_CLIENT_ID'}' \\\n -H 'x-client-secret: [REDACTED]' \\\n -H 'x-api-version: 2024-01-01' \\\n -H 'Content-Type: application/json' \\\n -d '{json.dumps(payload)}'"
|
||||
|
||||
if self.has_credentials():
|
||||
try:
|
||||
|
|
@ -468,7 +474,7 @@ class CashfreeSecureIDClient:
|
|||
logger.error(f"Error calling Cashfree Bank Account API: {e}")
|
||||
|
||||
# Fallback simulation
|
||||
valid_accounts = ["026291800001191", "00011020001772", "000890289871772", "1233943142", "388108022658"]
|
||||
valid_accounts = ["026291800001191", "00011020001772", "0008902898772", "1233943142", "388108022658"]
|
||||
failed_accounts = ["000100289877623", "026291800001190"]
|
||||
|
||||
if bank_account in valid_accounts or (len(bank_account) >= 9 and bank_account not in failed_accounts):
|
||||
|
|
|
|||
Loading…
Reference in a new issue