karrio-canadapost 2025.5rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. karrio/mappers/canadapost/__init__.py +3 -0
  2. karrio/mappers/canadapost/mapper.py +88 -0
  3. karrio/mappers/canadapost/proxy.py +373 -0
  4. karrio/mappers/canadapost/settings.py +23 -0
  5. karrio/plugins/canadapost/__init__.py +23 -0
  6. karrio/providers/canadapost/__init__.py +25 -0
  7. karrio/providers/canadapost/error.py +42 -0
  8. karrio/providers/canadapost/manifest.py +127 -0
  9. karrio/providers/canadapost/pickup/__init__.py +3 -0
  10. karrio/providers/canadapost/pickup/cancel.py +33 -0
  11. karrio/providers/canadapost/pickup/create.py +217 -0
  12. karrio/providers/canadapost/pickup/update.py +55 -0
  13. karrio/providers/canadapost/rate.py +192 -0
  14. karrio/providers/canadapost/shipment/__init__.py +8 -0
  15. karrio/providers/canadapost/shipment/cancel.py +53 -0
  16. karrio/providers/canadapost/shipment/create.py +308 -0
  17. karrio/providers/canadapost/tracking.py +75 -0
  18. karrio/providers/canadapost/units.py +285 -0
  19. karrio/providers/canadapost/utils.py +92 -0
  20. karrio/schemas/canadapost/__init__.py +0 -0
  21. karrio/schemas/canadapost/authreturn.py +3389 -0
  22. karrio/schemas/canadapost/common.py +2037 -0
  23. karrio/schemas/canadapost/customerinfo.py +2307 -0
  24. karrio/schemas/canadapost/discovery.py +3016 -0
  25. karrio/schemas/canadapost/manifest.py +3704 -0
  26. karrio/schemas/canadapost/merchantregistration.py +1498 -0
  27. karrio/schemas/canadapost/messages.py +1431 -0
  28. karrio/schemas/canadapost/ncshipment.py +7231 -0
  29. karrio/schemas/canadapost/openreturn.py +2438 -0
  30. karrio/schemas/canadapost/pickup.py +1407 -0
  31. karrio/schemas/canadapost/pickuprequest.py +6794 -0
  32. karrio/schemas/canadapost/postoffice.py +2240 -0
  33. karrio/schemas/canadapost/rating.py +5308 -0
  34. karrio/schemas/canadapost/serviceinfo.py +1505 -0
  35. karrio/schemas/canadapost/shipment.py +9982 -0
  36. karrio/schemas/canadapost/track.py +3100 -0
  37. karrio_canadapost-2025.5rc1.dist-info/METADATA +44 -0
  38. karrio_canadapost-2025.5rc1.dist-info/RECORD +41 -0
  39. karrio_canadapost-2025.5rc1.dist-info/WHEEL +5 -0
  40. karrio_canadapost-2025.5rc1.dist-info/entry_points.txt +2 -0
  41. karrio_canadapost-2025.5rc1.dist-info/top_level.txt +3 -0
@@ -0,0 +1,92 @@
1
+ """Karrio Canada post client settings."""
2
+
3
+ import base64
4
+ import karrio.lib as lib
5
+ import karrio.core.settings as settings
6
+
7
+
8
+ LanguageEnum = lib.units.create_enum("LanguageEnum", ["en", "fr"])
9
+
10
+
11
+ class Settings(settings.Settings):
12
+ """Canada post connection settings."""
13
+
14
+ username: str
15
+ password: str
16
+ customer_number: str
17
+ contract_id: str = None
18
+ language: LanguageEnum = "en" # type: ignore
19
+
20
+ @property
21
+ def carrier_name(self):
22
+ return "canadapost"
23
+
24
+ @property
25
+ def server_url(self):
26
+ return (
27
+ "https://ct.soa-gw.canadapost.ca"
28
+ if self.test_mode
29
+ else "https://soa-gw.canadapost.ca"
30
+ )
31
+
32
+ @property
33
+ def tracking_url(self):
34
+ return (
35
+ "https://www.canadapost-postescanada.ca/track-reperage/"
36
+ + self.language
37
+ + "#/resultList?searchFor={}"
38
+ )
39
+
40
+ @property
41
+ def authorization(self):
42
+ pair = "%s:%s" % (self.username, self.password)
43
+ return base64.b64encode(pair.encode("utf-8")).decode("ascii")
44
+
45
+ @property
46
+ def connection_config(self) -> lib.units.Options:
47
+ from karrio.providers.canadapost.units import ConnectionConfig
48
+
49
+ return lib.to_connection_config(
50
+ self.config or {},
51
+ option_type=ConnectionConfig,
52
+ )
53
+
54
+
55
+ def format_ca_postal_code(code: str = None) -> str:
56
+ """Format canadian postal code."""
57
+ return (code or "").replace(" ", "").upper()
58
+
59
+
60
+ def parse_label_references(shipement_response: str) -> dict:
61
+ response = lib.to_element(f"<wrapper>{shipement_response}</wrapper>")
62
+ messages = lib.find_element("message", response)
63
+ links = lib.find_element("link", response)
64
+
65
+ href, media = next(
66
+ (
67
+ (link.get("href"), link.get("media-type"))
68
+ for link in links
69
+ if link.get("rel") == "label" and len(messages) == 0
70
+ ),
71
+ (None, None),
72
+ )
73
+
74
+ return dict(href=href, media=media)
75
+
76
+
77
+ def parse_submitted_shipment(shipment_response: str, ctx) -> str:
78
+ import karrio.schemas.canadapost.shipment as canadapost
79
+
80
+ shipment = lib.to_object(
81
+ canadapost.ShipmentInfoType, lib.to_element(shipment_response)
82
+ )
83
+
84
+ return (
85
+ lib.to_xml(
86
+ canadapost.ShipmentRefundRequestType(email=ctx.get("email")),
87
+ namespacedef_='xmlns="http://www.canadapost.ca/ws/shipment-v8"',
88
+ name_="shipment-refund-request",
89
+ )
90
+ if shipment.shipment_status == "transmitted"
91
+ else None
92
+ )
File without changes