Skip to content

Commit 27b1f73

Browse files
ignapaspcrespovsanderegg
authored
🐛 Fixes listing in billing center (#5140)
Co-authored-by: Pedro Crespo-Valero <[email protected]> Co-authored-by: Sylvain <[email protected]>
1 parent 29b7733 commit 27b1f73

File tree

13 files changed

+318
-275
lines changed

13 files changed

+318
-275
lines changed

.env-devel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ PAYMENTS_AUTORECHARGE_MIN_BALANCE_IN_CREDITS=100
8080
PAYMENTS_AUTORECHARGE_ENABLED=1
8181
PAYMENTS_FAKE_COMPLETION_DELAY_SEC=10
8282
PAYMENTS_FAKE_COMPLETION=0
83-
PAYMENTS_GATEWAY_API_SECRET=replace-with-api-secret
84-
PAYMENTS_GATEWAY_URL=https://fake-payment-gateway.com
83+
PAYMENTS_GATEWAY_API_SECRET=adminadmin
84+
PAYMENTS_GATEWAY_URL=http://127.0.0.1:32769
8585
PAYMENTS_HOST=payments
8686
PAYMENTS_LOGLEVEL=INFO
8787
PAYMENTS_PASSWORD=adminadmin
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from typing import Final
22

33
SOCKET_IO_PAYMENT_COMPLETED_EVENT: Final[str] = "paymentCompleted"
4-
SOCKET_IO_PAYMENT_METHOD_ACKED_EVENT: Final[str] = "paymentMethodAcknoledged"
4+
SOCKET_IO_PAYMENT_METHOD_ACKED_EVENT: Final[str] = "paymentMethodAcknowledged"

packages/service-library/src/servicelib/fastapi/http_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,16 @@ def to_curl_command(request: httpx.Request, *, use_short_options: bool = True) -
114114

115115
# https://curl.se/docs/manpage.html#-H
116116
# H, --header <header/@file> Pass custom header(s) to server
117+
117118
headers_option = ""
118-
if headers := [f'"{k}: {v}"' for k, v in request.headers.items()]:
119+
headers = []
120+
for key, value in request.headers.items():
121+
if "secret" in key.lower() or "pass" in key.lower():
122+
headers.append(f'"{key}: *****"')
123+
else:
124+
headers.append(f'"{key}: {value}"')
125+
126+
if headers:
119127
_h = "-H" if use_short_options else "--header"
120128
headers_option = f"{_h} {f' {_h} '.join(headers)}"
121129

packages/service-library/tests/fastapi/test_http_client.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,34 +115,42 @@ async def test_to_curl_command(mock_server_api: respx.MockRouter, base_url: str)
115115
mock_server_api.delete(path__startswith="/foo").respond(status.HTTP_200_OK)
116116

117117
async with httpx.AsyncClient(base_url=base_url) as client:
118-
response = await client.post("/foo", params={"x": "3"}, json={"y": 12})
118+
response = await client.post(
119+
"/foo",
120+
params={"x": "3"},
121+
json={"y": 12},
122+
headers={"x-secret": "this should not display"},
123+
)
119124
assert response.status_code == 200
120125

121-
cmd = to_curl_command(response.request)
126+
cmd_short = to_curl_command(response.request)
122127

123128
assert (
124-
cmd
125-
== 'curl -X POST -H "host: test_base_http_api" -H "accept: */*" -H "accept-encoding: gzip, deflate" -H "connection: keep-alive" -H "user-agent: python-httpx/0.25.0" -H "content-length: 9" -H "content-type: application/json" -d \'{"y": 12}\' https://test_base_http_api/foo?x=3'
129+
cmd_short
130+
== 'curl -X POST -H "host: test_base_http_api" -H "accept: */*" -H "accept-encoding: gzip, deflate" -H "connection: keep-alive" -H "user-agent: python-httpx/0.25.0" -H "x-secret: *****" -H "content-length: 9" -H "content-type: application/json" -d \'{"y": 12}\' https://test_base_http_api/foo?x=3'
126131
)
127132

128-
cmd = to_curl_command(response.request, use_short_options=False)
129-
assert (
130-
cmd
131-
== 'curl --request POST --header "host: test_base_http_api" --header "accept: */*" --header "accept-encoding: gzip, deflate" --header "connection: keep-alive" --header "user-agent: python-httpx/0.25.0" --header "content-length: 9" --header "content-type: application/json" --data \'{"y": 12}\' https://test_base_http_api/foo?x=3'
133+
cmd_long = to_curl_command(response.request, use_short_options=False)
134+
assert cmd_long == cmd_short.replace("-X", "--request",).replace(
135+
"-H",
136+
"--header",
137+
).replace(
138+
"-d",
139+
"--data",
132140
)
133141

134142
# with GET
135143
response = await client.get("/foo", params={"x": "3"})
136-
cmd = to_curl_command(response.request)
144+
cmd_long = to_curl_command(response.request)
137145

138146
assert (
139-
cmd
147+
cmd_long
140148
== 'curl -X GET -H "host: test_base_http_api" -H "accept: */*" -H "accept-encoding: gzip, deflate" -H "connection: keep-alive" -H "user-agent: python-httpx/0.25.0" https://test_base_http_api/foo?x=3'
141149
)
142150

143151
# with DELETE
144152
response = await client.delete("/foo", params={"x": "3"})
145-
cmd = to_curl_command(response.request)
153+
cmd_long = to_curl_command(response.request)
146154

147-
assert "DELETE" in cmd
148-
assert " -d " not in cmd
155+
assert "DELETE" in cmd_long
156+
assert " -d " not in cmd_long

services/payments/gateway/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@ include ../../../scripts/common.Makefile
55
.PHONY: openapi.json
66
openapi.json: ## creates OAS
77
example_payment_gateway.py openapi > $@
8+
9+
.PHONY: up-local
10+
up-local: ## starts payments-gateway sample for local testing
11+
## Docs in http://127.0.0.1:32769/docs ...
12+
source $(DOT_ENV_FILE) && export PAYMENTS_USERNAME PAYMENTS_PASSWORD && \
13+
docker run -it \
14+
-p 32769:8000 \
15+
--env "PAYMENTS_SERVICE_API_BASE_URL=http://127.0.0.1:8011" \
16+
--env "PAYMENTS_USERNAME=$$PAYMENTS_USERNAME" \
17+
--env "PAYMENTS_PASSWORD=$$PAYMENTS_PASSWORD" \
18+
--name "example_payment_gateway" \
19+
local/payments:production \
20+
example_payment_gateway.py run

services/payments/scripts/example_payment_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def create_app():
450450

451451

452452
def run_command(args):
453-
uvicorn.run(the_app, port=8080)
453+
uvicorn.run(the_app, port=8000, host="0.0.0.0") # nosec # NOSONAR
454454

455455

456456
def openapi_command(args):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Final
22

3-
ACKED: Final[str] = "Acknoledged"
3+
ACKED: Final[str] = "Acknowledged"
44
PAG: Final[str] = "Payments Gateway service"
55
PGDB: Final[str] = "Postgres service"
66
RUT: Final[str] = "Resource Usage Tracker service"

services/static-webserver/client/source/class/osparc/About.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ qx.Class.define("osparc.About", {
9494
contentPaddingLeft: 0,
9595
barPosition: "top"
9696
});
97-
tabView.getChildControl("pane").setBackgroundColor("transparent_overlay");
97+
tabView.getChildControl("pane").setBackgroundColor("transparent");
9898
this.add(tabView, {
9999
flex: 1
100100
});

services/static-webserver/client/source/class/osparc/desktop/credits/OneTimePayment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ qx.Class.define("osparc.desktop.credits.OneTimePayment", {
375375

376376
__popUpPaymentGateway: function(paymentId, url) {
377377
const options = {
378-
width: 400,
378+
width: 450,
379379
height: 600
380380
};
381381

@@ -392,7 +392,7 @@ qx.Class.define("osparc.desktop.credits.OneTimePayment", {
392392

393393
__popUpPaymentGatewayOld: function(paymentId, url) {
394394
const options = {
395-
width: 400,
395+
width: 450,
396396
height: 600,
397397
top: 100,
398398
left: 200,

services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", {
101101
};
102102
osparc.data.Resources.fetch("paymentMethods", "init", params)
103103
.then(data => {
104-
this.__popUpPaymentGateway(data["paymentMethodId"], data["paymentMethodFormUrl"]);
105-
this.__fetchPaymentMethods();
104+
const gatewayWindow = this.__popUpPaymentGateway(data.paymentMethodId, data.paymentMethodFormUrl);
105+
osparc.wrapper.WebSocket.getInstance().getSocket().once("paymentMethodAcknoledged", wsData => {
106+
const {paymentMethodId} = JSON.parse(wsData);
107+
if (paymentMethodId === data.paymentMethodId) {
108+
gatewayWindow.close();
109+
this.__fetchPaymentMethods();
110+
}
111+
});
106112
});
107113
}
108114
},
@@ -127,7 +133,7 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", {
127133

128134
__popUpPaymentGateway: function(paymentMethodId, url) {
129135
const options = {
130-
width: 400,
136+
width: 450,
131137
height: 600
132138
};
133139

@@ -184,7 +190,7 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", {
184190
spacing: 3,
185191
height: 150,
186192
width: 150,
187-
backgroundColor: "transparent_overlay"
193+
backgroundColor: "transparent"
188194
});
189195

190196
const paymentMethodsModel = this.__paymentMethodsModel = new qx.data.Array();
@@ -207,7 +213,6 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", {
207213
}
208214
});
209215

210-
paymentMethodsModel.removeAll();
211216
allPaymentMethods.forEach(paymentMethod => {
212217
const paymentMethodModel = qx.data.marshal.Json.createModel(paymentMethod);
213218
paymentMethodsModel.append(paymentMethodModel);

0 commit comments

Comments
 (0)