33# See the LICENSE.md file for more information.
44# See the DISCLAIMER.md file for disclaimer details
55
6- from odoo .addons .pos_multisafepay_cloud .helpers .status import _Status
76from odoo .addons .pos_multisafepay_cloud .helpers .order_context_builder import (
87 _OrderContextBuilder ,
98)
9+ from odoo .addons .pos_multisafepay_cloud .helpers .status import _Status
1010
1111
1212class _OdooPayloadBuilder :
@@ -42,8 +42,10 @@ def create_values(response, data, terminal_id, status):
4242 "session_id" : data .get ("session_id" ),
4343 "terminal_id" : terminal_id ,
4444 "events_token" : response .get ("events_token" ) or response .get ("event_token" ),
45- "remote_transaction_id" : response .get ("transaction_id" ) or response .get ("order_id" ),
46- "events_stream_url" : response .get ("events_stream_url" ) or response .get ("event_stream_url" ),
45+ "remote_transaction_id" : response .get ("transaction_id" )
46+ or response .get ("order_id" ),
47+ "events_stream_url" : response .get ("events_stream_url" )
48+ or response .get ("event_stream_url" ),
4749 "last_event_id" : response .get ("last_event_id" ),
4850 "msp_latest_response" : payload ,
4951 "status" : status ,
@@ -62,12 +64,18 @@ def write_for_cancel(payment, cancellation):
6264 :rtype: dict
6365 """
6466 status = _Status .normalize (cancellation .get ("status" ) or "canceled" )
65- payload = (payment .msp_latest_response or {}) | cancellation | {
66- "status" : status ,
67- "state" : _Status .state (status ),
68- "order_id" : payment .name ,
69- "transaction_id" : cancellation .get ("transaction_id" ) or payment .remote_transaction_id or payment .name ,
70- }
67+ payload = (
68+ (payment .msp_latest_response or {})
69+ | cancellation
70+ | {
71+ "status" : status ,
72+ "state" : _Status .state (status ),
73+ "order_id" : payment .name ,
74+ "transaction_id" : cancellation .get ("transaction_id" )
75+ or payment .remote_transaction_id
76+ or payment .name ,
77+ }
78+ )
7179 return {
7280 "msp_latest_response" : payload ,
7381 "status" : status ,
@@ -136,14 +144,20 @@ def write_for_notification(cls, payment, payload, method, now_string):
136144 "notification_method" : method ,
137145 "notification_received_at" : now_string ,
138146 }
139- for key in ("last_status_refresh_error" , "last_status_refresh_error_at" , "last_status_refresh_error_source" ):
147+ for key in (
148+ "last_status_refresh_error" ,
149+ "last_status_refresh_error_at" ,
150+ "last_status_refresh_error_source" ,
151+ ):
140152 latest_response .pop (key , None )
141153
142154 write_vals = {
143155 "status" : status ,
144156 "remote_transaction_id" : transaction_id ,
145157 "stream_state" : "done" if state != "pending" else payment .stream_state ,
146- "stream_lock_until" : False if state != "pending" else payment .stream_lock_until ,
158+ "stream_lock_until" : False
159+ if state != "pending"
160+ else payment .stream_lock_until ,
147161 }
148162
149163 cls ._append_events (payload , write_vals , latest_response )
@@ -185,7 +199,9 @@ def _append_events(payload, write_vals, latest_response):
185199
186200 stream_url = payload .get ("events_stream_url" ) or payload .get ("event_stream_url" )
187201 if stream_url :
188- write_vals ["events_stream_url" ] = latest_response ["events_stream_url" ] = stream_url
202+ write_vals ["events_stream_url" ] = latest_response ["events_stream_url" ] = (
203+ stream_url
204+ )
189205
190206 @staticmethod
191207 def write_for_refresh_error (payment , remote_status , source , now_string ):
@@ -238,10 +254,14 @@ def write_for_cancel_error(payment, cancellation):
238254 :return: A tuple of write values dictionary and error payload dictionary.
239255 :rtype: tuple[dict, dict]
240256 """
241- payload = (payment .msp_latest_response or {}) | cancellation | {
242- "order_id" : payment .name ,
243- "transaction_id" : payment .remote_transaction_id or payment .name ,
244- }
257+ payload = (
258+ (payment .msp_latest_response or {})
259+ | cancellation
260+ | {
261+ "order_id" : payment .name ,
262+ "transaction_id" : payment .remote_transaction_id or payment .name ,
263+ }
264+ )
245265 write_vals = {
246266 "msp_latest_response" : payload ,
247267 "status" : "error" ,
0 commit comments