@@ -101,11 +101,51 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st
101101 carrier_output += f" -d '{ json .dumps (carrier_account_json , indent = 2 )} '"
102102 carrier_output += END_CHARS
103103 carrier_output = carrier_output .replace (f"{ LINE_BREAK_CHARS } { END_CHARS } " , f"{ END_CHARS } " )
104- # UPS/CanadaPost
105- elif carrier ["type" ] in (UPS_CUSTOM_WORKFLOW_CARRIERS + CANADAPOST_CUSTOM_WORKFLOW_CARRIERS ):
106- # TODO: Fix UPS carrier account
107- # TODO: Fix CanadaPost carrier account
108- pass
104+ # CanadaPost
105+ elif carrier ["type" ] in CANADAPOST_CUSTOM_WORKFLOW_CARRIERS :
106+ # BYOA cURL
107+ end = END_CHARS
108+ for top_level in carrier_fields :
109+ if top_level == "custom_workflow" :
110+ end += CUSTOM_WORKFLOW_CHARS
111+ else :
112+ top_level_carrier_fields = carrier_fields [top_level ]
113+ for item in top_level_carrier_fields :
114+ if carrier_account_json ["carrier_account" ].get (top_level ) is None :
115+ carrier_account_json ["carrier_account" ][top_level ] = {}
116+ carrier_account_json ["carrier_account" ][top_level ][item ] = "VALUE"
117+
118+ carrier_output += f" -d '{ json .dumps (carrier_account_json , indent = 2 )} '"
119+ carrier_output += end
120+ carrier_output = carrier_output .replace (f"{ LINE_BREAK_CHARS } { END_CHARS } " , f"{ END_CHARS } " )
121+
122+ # Default (aggregation) cURL
123+ default_output = f'# { carrier .get ("type" )} (EasyPost Aggregation)\n '
124+ default_output = add_curl_line (default_output , carrier )
125+ default_output = add_headers (default_output , carrier )
126+
127+ default_json = {
128+ "carrier_account" : {
129+ "type" : carrier ["type" ],
130+ "payment_mode" : "aggregation"
131+ }
132+ }
133+
134+ default_output += f" -d '{ json .dumps (default_json , indent = 2 )} '"
135+ default_output += END_CHARS
136+ default_output = default_output .replace (f"{ LINE_BREAK_CHARS } { END_CHARS } " , f"{ END_CHARS } " )
137+
138+ output_destination = os .path .join ("../" , "../" , "official" , "guides" , "create-carrier-curls" )
139+ if not os .path .exists (output_destination ):
140+ os .makedirs (output_destination )
141+
142+ with open (
143+ os .path .join (output_destination , "canadapost-default.sh" ),
144+ "w" ,
145+ ) as default_file :
146+ default_file .write (re .sub (r"^.*?\n" , "" , default_output ))
147+
148+ return carrier_output
109149 # Amazon Shipping
110150 elif carrier ["type" ] in OAUTH_CUSTOM_WORKFLOW_CARRIERS :
111151 carrier_account_json = {
@@ -141,6 +181,5 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st
141181
142182 return carrier_output
143183
144-
145184if __name__ == "__main__" :
146185 main ()
0 commit comments