generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from pagopa/PAGOPA-2282
[PAGOPA-2282]
- Loading branch information
Showing
15 changed files
with
286 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import sys | ||
import logging, time | ||
import methods | ||
|
||
|
||
NUMBER_OF_PAYMENTS = 300 | ||
MAX_PAYMENTS_PER_ADD_OPERATION = 100 | ||
|
||
def main(URL, subkey): | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
flow_date = "2024-10-30" | ||
tmstmp = timestamp = int(time.time()) | ||
flow_name = f"{flow_date}88888888888-{tmstmp}" | ||
|
||
create_url = URL + f"/psps/88888888888/fdrs/{flow_name}" | ||
methods.create_empty_flow(create_url, flow_name, flow_date, NUMBER_OF_PAYMENTS, subkey) | ||
|
||
|
||
add_url = URL + f"/psps/88888888888/fdrs/{flow_name}/payments/add" | ||
methods.add_payments(add_url, NUMBER_OF_PAYMENTS, MAX_PAYMENTS_PER_ADD_OPERATION, flow_date, subkey) | ||
|
||
|
||
publish_url = URL + f"/psps/88888888888/fdrs/{flow_name}/publish" | ||
methods.publish_payments(publish_url, subkey) | ||
|
||
def get_url(env): | ||
if env == 'dev': | ||
return "https://api.dev.platform.pagopa.it/fdr-psp/service/v1" | ||
elif env == 'uat': | ||
return "https://upload.uat.platform.pagopa.it/fdr-psp/service/v1" | ||
else: | ||
raise ValueError(f"Invalid environment: {env}. Please use 'dev' or 'uat'.") | ||
|
||
if __name__ == "__main__": | ||
try: | ||
env = sys.argv[1] | ||
key = sys.argv[2] | ||
url = get_url(env) | ||
main(url, key) | ||
except IndexError: | ||
print("Usage: python3 main.py <environment> <sukey> \ni.e. python3 main.py dev your-key") | ||
except ValueError as e: | ||
print(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import random | ||
import json, logging, requests, time | ||
|
||
|
||
def create_empty_flow(url, flow_name, flow_date, total_payments, key): | ||
|
||
headers = { | ||
"Ocp-Apim-Subscription-Key": key | ||
} | ||
request = { | ||
"fdr": flow_name, | ||
"fdrDate": f"{flow_date}T12:00:00.000Z", | ||
"sender": { | ||
"type": "LEGAL_PERSON", | ||
"id": "SELBIT2B", | ||
"pspId": "88888888888", | ||
"pspName": "Bank", | ||
"pspBrokerId": "88888888888", | ||
"channelId": "88888888888_01", | ||
"password": "PLACEHOLDER" | ||
}, | ||
"receiver": { | ||
"id": "APPBIT2B", | ||
"organizationId": "15376371009", | ||
"organizationName": "PagoPA" | ||
}, | ||
"regulation": "SEPA - Bonifico xzy", | ||
"regulationDate": f"{flow_date}T12:00:00.000Z", | ||
"bicCodePouringBank": "UNCRITMMXXX", | ||
"totPayments": total_payments, | ||
"sumPayments": total_payments * 10 | ||
} | ||
logging.info(f"\nSend request to: [{url}]\nRequest: [{request}]") | ||
start_time = time.time() | ||
response = requests.post(url=url, | ||
data=json.dumps(request), | ||
headers=headers) | ||
end_time = time.time() | ||
logging.info(f"=====\nElapsed time: [{(end_time - start_time):.3f} sec] Status Code: [{response.status_code}]\nResponse: {response.json()}\n==================") | ||
|
||
|
||
|
||
def add_payments(url, total_payments, max_per_add, date, key): | ||
|
||
headers = { | ||
"Ocp-Apim-Subscription-Key": key | ||
} | ||
|
||
total_amount = total_payments * 10 | ||
payments = generate_payments(total_payments, total_amount, date) | ||
request = [] | ||
|
||
total_requests = int(total_payments / max_per_add) | ||
for req_idx in range(total_requests): | ||
extracted_payments = { | ||
"payments": payments[(req_idx * max_per_add):(req_idx * max_per_add + max_per_add)] | ||
} | ||
request = json.dumps(extracted_payments) | ||
logging.info(f"\nSend request to: [{url}]\nRequest: [TOO LONG]") | ||
start_time = time.time() | ||
response = requests.put(url=url, | ||
data=request, | ||
headers=headers) | ||
end_time = time.time() | ||
logging.info(f"=====\nElapsed time: [{(end_time - start_time):.3f} sec] Status Code: [{response.status_code}]\nResponse: {response.json()}\n==================") | ||
|
||
|
||
def publish_payments(url, key): | ||
headers = { | ||
"Ocp-Apim-Subscription-Key": key | ||
} | ||
logging.info(f"\nSend request to: [{url}]") | ||
start_time = time.time() | ||
response = requests.post(url=url, | ||
headers=headers) | ||
end_time = time.time() | ||
logging.info(f"=====\nElapsed time: [{(end_time - start_time):.3f} sec] Status Code: [{response.status_code}]\nResponse: {response.json()}\n==================") | ||
|
||
|
||
######### | ||
# UTILS # | ||
######### | ||
def generate_payments(number_of_payments, total_amount, date): | ||
|
||
payments = [] | ||
iuvs = set() | ||
for idx in range(number_of_payments): | ||
iuv = get_random_numeric_string(15) | ||
if iuv not in iuvs: | ||
iuvs.add(iuv) | ||
payments.append({ | ||
"index": idx + 1, | ||
"iuv": iuv, | ||
"iur": get_random_numeric_string(11), | ||
"pay": total_amount / number_of_payments, | ||
"idTransfer": 1, | ||
"payStatus": "EXECUTED", | ||
"payDate": f"{date}T12:00:00.000Z" | ||
}) | ||
else: | ||
idx -= 1 | ||
return payments | ||
|
||
def get_random_numeric_string(size, dataset = "0123456789"): | ||
random_string = ''.join(random.choices(dataset, k=size)) | ||
return random_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.