-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,134 additions
and
21 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
9 changes: 9 additions & 0 deletions
9
modules/connectors/fedex/karrio/providers/fedex/pickup/__init__.py
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,9 @@ | ||
from karrio.providers.fedex.pickup.create import parse_pickup_response, pickup_request | ||
from karrio.providers.fedex.pickup.update import ( | ||
parse_pickup_update_response, | ||
pickup_update_request, | ||
) | ||
from karrio.providers.fedex.pickup.cancel import ( | ||
parse_pickup_cancel_response, | ||
pickup_cancel_request, | ||
) |
79 changes: 79 additions & 0 deletions
79
modules/connectors/fedex/karrio/providers/fedex/pickup/cancel.py
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,79 @@ | ||
import karrio.schemas.fedex.cancel_pickup_request as fedex | ||
import karrio.schemas.fedex.cancel_pickup_response as pickup | ||
|
||
import typing | ||
import karrio.lib as lib | ||
import karrio.core.units as units | ||
import karrio.core.models as models | ||
import karrio.providers.fedex.error as error | ||
import karrio.providers.fedex.utils as provider_utils | ||
import karrio.providers.fedex.units as provider_units | ||
|
||
|
||
def parse_pickup_cancel_response( | ||
_response: lib.Deserializable[dict], | ||
settings: provider_utils.Settings, | ||
) -> typing.Tuple[models.ConfirmationDetails, typing.List[models.Message]]: | ||
response = _response.deserialize() | ||
messages = error.parse_error_response(response, settings) | ||
success = any(lib.failsafe(lambda: response["output"]["pickupConfirmationCode"])) | ||
|
||
confirmation = lib.identity( | ||
models.ConfirmationDetails( | ||
carrier_id=settings.carrier_id, | ||
carrier_name=settings.carrier_name, | ||
operation="Cancel Pickup", | ||
success=success, | ||
) | ||
if success | ||
else None | ||
) | ||
|
||
return confirmation, messages | ||
|
||
|
||
def pickup_cancel_request( | ||
payload: models.PickupCancelRequest, | ||
settings: provider_utils.Settings, | ||
) -> lib.Serializable: | ||
address = lib.to_address(payload.address) | ||
options = lib.units.Options( | ||
payload.options, | ||
option_type=lib.units.create_enum( | ||
"PickupOptions", | ||
# fmt: off | ||
{ | ||
"fedex_carrier_code": lib.OptionEnum("carrierCode"), | ||
"fedex_pickup_location": lib.OptionEnum("location"), | ||
}, | ||
# fmt: on | ||
), | ||
) | ||
|
||
# map data to convert karrio model to fedex specific type | ||
request = fedex.CancelPickupRequestType( | ||
associatedAccountNumber=fedex.AssociatedAccountNumberType( | ||
value=settings.account_number, | ||
), | ||
pickupConfirmationCode=payload.confirmation_number, | ||
remarks=payload.reason, | ||
carrierCode=options.fedex_carrier_code.state, | ||
accountAddressOfRecord=lib.identity( | ||
fedex.AccountAddressOfRecordType( | ||
streetLines=address.address_lines, | ||
urbanizationCode=None, | ||
city=address.city, | ||
stateOrProvinceCode=provider_utils.state_code(address), | ||
postalCode=address.postal_code, | ||
countryCode=address.country_code, | ||
residential=address.residential, | ||
addressClassification=None, | ||
) | ||
if payload.address | ||
else None | ||
), | ||
scheduledDate=lib.fdate(payload.pickup_date, "%Y-%m-%d"), | ||
location=options.fedex_pickup_location.state, | ||
) | ||
|
||
return lib.Serializable(request, lib.to_dict) |
148 changes: 148 additions & 0 deletions
148
modules/connectors/fedex/karrio/providers/fedex/pickup/create.py
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,148 @@ | ||
import karrio.schemas.fedex.pickup_request as fedex | ||
import karrio.schemas.fedex.pickup_response as pickup | ||
|
||
import typing | ||
import karrio.lib as lib | ||
import karrio.core.units as units | ||
import karrio.core.models as models | ||
import karrio.providers.fedex.error as error | ||
import karrio.providers.fedex.utils as provider_utils | ||
import karrio.providers.fedex.units as provider_units | ||
|
||
|
||
def parse_pickup_response( | ||
_response: lib.Deserializable[dict], | ||
settings: provider_utils.Settings, | ||
) -> typing.Tuple[typing.List[models.PickupDetails], typing.List[models.Message]]: | ||
response = _response.deserialize() | ||
|
||
messages = error.parse_error_response(response, settings) | ||
pickup = lib.identity( | ||
_extract_details(response, settings, _response.ctx) | ||
if (response.get("output") or {}).get("pickupConfirmationCode") | ||
else None | ||
) | ||
|
||
return pickup, messages | ||
|
||
|
||
def _extract_details( | ||
data: dict, | ||
settings: provider_utils.Settings, | ||
ctx: dict, | ||
) -> models.PickupDetails: | ||
details = lib.to_object(pickup.PickupResponseType, data) | ||
|
||
return models.PickupDetails( | ||
carrier_id=settings.carrier_id, | ||
carrier_name=settings.carrier_name, | ||
confirmation_number=details.output.pickupConfirmationCode, | ||
pickup_date=lib.fdate(ctx["pickup_date"]), | ||
) | ||
|
||
|
||
def pickup_request( | ||
payload: models.PickupRequest, | ||
settings: provider_utils.Settings, | ||
) -> lib.Serializable: | ||
address = lib.to_address(payload.address) | ||
packages = lib.to_packages(payload.parcels) | ||
options = lib.units.Options( | ||
payload.options, | ||
option_type=lib.units.create_enum( | ||
"PickupOptions", | ||
# fmt: off | ||
{ | ||
"fedex_carrier_code": lib.OptionEnum("carrierCode"), | ||
"fedex_pickup_location": lib.OptionEnum("location"), | ||
"fedex_user_message": lib.OptionEnum("userMessage"), | ||
"fedex_early_pickup": lib.OptionEnum("earlyPickup"), | ||
"fedex_building_part": lib.OptionEnum("buildingPart"), | ||
"fedex_pickup_date_type": lib.OptionEnum("pickupDateType"), | ||
"fedex_supplies_requested": lib.OptionEnum("suppliesRequested"), | ||
"fedex_pickup_address_type": lib.OptionEnum("pickupAddressType"), | ||
"fedex_building_part_description": lib.OptionEnum("buildingPartDescription"), | ||
"fedex_associated_account_number_type": lib.OptionEnum("associatedAccountNumberType"), | ||
}, | ||
# fmt: on | ||
), | ||
) | ||
|
||
# map data to convert karrio model to fedex specific type | ||
request = fedex.PickupRequestType( | ||
associatedAccountNumber=fedex.AccountNumberType( | ||
value=settings.account_number, | ||
), | ||
originDetail=fedex.OriginDetailType( | ||
pickupAddressType=options.fedex_pickup_address_type.state, | ||
pickupLocation=fedex.PickupLocationType( | ||
contact=fedex.ContactType( | ||
companyName=address.company_name, | ||
personName=address.person_name, | ||
phoneNumber=address.phone_number, | ||
phoneExtension=None, | ||
), | ||
address=fedex.AccountAddressOfRecordType( | ||
streetLines=address.address_lines, | ||
city=address.city, | ||
stateOrProvinceCode=address.state_code, | ||
postalCode=address.postal_code, | ||
countryCode=address.country_code, | ||
residential=address.residential, | ||
addressClassification=None, | ||
urbanizationCode=None, | ||
), | ||
accountNumber=fedex.AccountNumberType( | ||
value=settings.account_number, | ||
), | ||
deliveryInstructions=options.instructions.state, | ||
), | ||
readyDateTimestamp=f"{payload.pickup_date}T{payload.closing_time}:00Z", | ||
customerCloseTime=f"{payload.closing_time}:00", | ||
pickupDateType=options.fedex_pickup_date_type.state, | ||
packageLocation=payload.package_location, | ||
buildingPart=options.fedex_building_part.state, | ||
buildingPartDescription=options.fedex_building_part_description.state, | ||
earlyPickup=options.fedex_early_pickup.state, | ||
suppliesRequested=options.fedex_supplies_requested.state, | ||
geographicalPostalCode=options.geographical_postal_code.state, | ||
), | ||
associatedAccountNumberType=options.fedex_associated_account_number_type.state, | ||
totalWeight=fedex.TotalWeightType( | ||
units=packages.weight_unit, | ||
value=packages.weight.value, | ||
), | ||
packageCount=len(packages), | ||
carrierCode=options.fedex_carrier_code.state or "FDXE", | ||
accountAddressOfRecord=None, | ||
remarks=None, | ||
countryRelationships=None, | ||
pickupType=None, | ||
trackingNumber=None, | ||
commodityDescription=lib.text(packages.description, max=100), | ||
expressFreightDetail=None, | ||
oversizePackageCount=None, | ||
pickupNotificationDetail=lib.identity( | ||
fedex.PickupNotificationDetailType( | ||
emailDetails=[ | ||
fedex.EmailDetailType( | ||
address=address.email, | ||
locale="en_US", | ||
) | ||
], | ||
format="TEXT", | ||
userMessage=options.fedex_user_message.state, | ||
) | ||
if address.email | ||
else None | ||
), | ||
) | ||
|
||
return lib.Serializable( | ||
request, | ||
lib.to_dict, | ||
dict( | ||
pickup_date=payload.pickup_date, | ||
address=payload.address, | ||
), | ||
) |
Oops, something went wrong.