pakettikauppa package¶
Submodules¶
pakettikauppa.merchant module¶
This is a module for Pakettikauppa integration for merchants to use
- The module provides below functionality:
- Get shipping method list
- Get additional service list
- Search pickup points
- Get shipment status
- Create shipment
- Get shipping label
-
class
pakettikauppa.merchant.
PkMerchant
(is_test_mode=0, api_key=None, secret=None)[source] Bases:
pakettikauppa.pakettikauppa.Pakettikauppa
-
create_additional_info_element
(root, **dict_data)[source] Append additional info element to given root object. :param root: root XML object. :param dict_data: dictionary of additional info text :return:
-
create_shipment
(**kwargs)[source] Main function to send a request to Pakettikauppa to create shipment.
Parameters: kwargs – See get_xml_shipment_req_data() function Return dict_data: See parse_xml_create_shipment_res() function
-
create_shipment_with_simple_data
(**kwargs)[source] Same as create_shipment() function expect the input parameter is in shorter format
This API send request data in XML format.
Parameters: kwargs – see get_simple_test_data_create_shipment() function Return dict_data: See parse_xml_create_shipment_res() function
-
generate_additional_services_data
(list_data=None)[source] Generate additional services data.
Parameters: list_data – list of dictionary of additional services Return list_data: list of formatted dictionary of additional services
-
generate_parcels_data
(list_data=None)[source] Generate parcels data.
Parameters: list_data – list of dictionary of parcels Return list_data: list of formatted dictionary of parcels
-
get_additional_service_list
(language_code2='EN')[source] Get list of additional service for the account
Parameters: language_code2 – 2 letters of language code. Default value is ‘EN’ Return list_data: list of response data
-
get_api_config
(api_name=None)[source] Constructs API configuration
Parameters: api_name – string of API name Return dict_data: dictionary of configuration data - dict_data keys:
- api_post_url (string): post URL address api_key (string): API key api_secret (string): secret key
-
get_api_suffix
(param)[source] Get API suffix for the API name :param api_name: string of API name :return api_suffix: string of API suffix
-
get_create_multi_parcels_shipment_test_data
()[source] Main function to generate test data set for create shipment request call.
Return dict_data: dictionary of request data
-
get_create_shipment_test_data
()[source] Main function to generate test data set for create shipment request call.
Return dict_data: dictionary of request data
-
get_create_shipment_test_req_data
()[source] Generates test data set for create shipment request call.
Return dict_data: dictionary of request data
-
get_one_additional_service_data
(**kwargs)[source] Generate one additional service data item.
Parameters: kwargs – contain following keys: ServiceCode: string of additional service code Specifier: list of dictionary or dictionary of service details. See get_one_specifier_data() function for input format Return dict_data: dictionary for one additional service
-
get_one_parcel_data
(**kwargs)[source] Generate one parcel data.
Parameters: kwargs – dictionary contain following keys: Reference: parcel reference PackageType: code of package type Weight: dictionary with ‘weight_unit’ and ‘value’ key. Volume: dictionary with ‘unit’ and ‘value’ key. InfoCode: Contents: product description ReturnService: return service code ContentLine: dictionary of parcel content data ParcelServices: parcel additional service (optional) Return dict_data: dictionary of parcel data
-
get_one_parcel_service_data
(**kwargs)[source] Generate one parcel service data.
Parameters: kwargs – dictionary of parcel service code, contain following key: ServiceCode: parcel service code - string Return dict_data: dictionary of one parcel service
-
get_one_specifier_data
(**kwargs)[source] Generate one specifier data item
Parameters: kwargs – contain following keys: name: attribute name for additional service value: attribute value Return dict_data: dictionary of one specifier
-
get_pickup_point_req_data
(api_key, **kwargs)[source] Constructs request data for search pickup point API
Parameters: - api_key – string of API key
- kwargs –
- Kwargs:
- postal_code (string): postal code (mandatory) country_code2 (string): 2 letters of country code i.e ‘FI’. Default is ‘FI’ street_address (string): street address service_provider (string): Limits search to a single service provider, possible values: “Posti”, “Matkahuolto” or “Db Schenker”. Case insensitive values. max_result (integer): maximum number of search results. Default is 5
Return dict_data: dictionary of request data
-
get_proper_req_data_create_shipment
(**simple_dict_data)[source] Generate low lever of request input data for create shipment API.
Parameters: simple_dict_data – see output of get_simple_test_data_create_shipment() function Return dict_data: dictionary of request data
-
get_routing_key
(routing_id)[source] Calculate routing key.
Parameters: routing_id – string of routing ID Return digest_string: digest string of MD5 hash
-
get_shipment_status
(tracking_code)[source] Get shipment status from Pakettikauppa.
Parameters: tracking_code – string of tracking code for checking Returns:
-
get_shipment_status_req_data
(tracking_code)[source] Construct request data for get shipment status API.
Parameters: tracking_code – string of tracking code Return dict_data: dictionary of request data
-
get_shipping_label
(**kwargs)[source] Get shipping labels from Pakettikauppa. This API send request data in XML format.
Parameters: kwargs – See get_xml_shipping_label_req_data() function Returns: See parse_xml_get_shipping_label_res() function
-
get_shipping_label_req_test_data
()[source] Generate test request data for getting shipping label.
Return dict_data: dictionary
-
get_shipping_method_list
(language_code2='EN')[source] Get list of available shipping method for the account
Parameters: language_code2 – 2 letters of language code. Default value is ‘EN’ Return list_data: list of response data
-
get_simple_test_data_create_shipment
()[source] Generate more simplify version of request data of create shipment API. Output of this function should then pass to get_proper_req_data_create_shipment() function to get right data structure for request input data.
For full version see get_create_shipment_test_data() function.
Return dict_data: dictionary of request data
-
get_xml_shipment_req_data
(**kwargs)[source] Construct XML string of request data for create shipment API
Parameters: kwargs – - Kwargs:
- eChannel: dictionary with following keys
ROUTING: see _create_routing_elements() function
Shipment: see _create_shipment_elements() function
Return xml_string: string of XML request data for create shipment API
-
get_xml_shipping_label_req_data
(**kwargs)[source] Construct XML string request data for getting shipping label
Parameters: kwargs – contains following keys
- eChannel: contains following keys
- ROUTING: dictionary of routing data PrintLabel: dictionary of tracking codes
- ROUTING:
- Routing.Account: API key Routing.Key: MD5 hash string Routing.Id: could be order id or shop id or combination of both Routing.Name: could be order alias or shop alias or combination of both Routing.Time: string of current datetime with following format ‘%Y%m%d%H%M%S’
- PrintLabel:
- responseFormat: expected response data format. Possible values are “File” and “inline”, “File” is default. content: dictionary of tracking code with ‘TrackingCode’ as a key.
- TrackingCode: could be dictionary with ‘Code’ key or list of dictionary of ‘Code’ key for asking multiple labels
- Code: string of tracking code
Return xml_string:
-
parse_xml_create_shipment_res
(xml_string)[source] Constructs dictionary from response XML string
Parameters: xml_string – string of XML data Return dict_data: dictionary of response data - dict_data contains following keys:
- status (integer): 1 = status OK message (string): response message from Pakettikauppa reference (dictionary): contains two keys: ‘uuid’ and ‘value’ trackingcode (dictionary): contains two keys: ‘tracking_url’ and ‘value’ (tracking code)
-
parse_xml_get_shipping_label_res
(xml_string)[source] Construct dictionary from response data.
Parameters: xml_string – XML string of response data Returns: dict_data: dictionary, contains below keys status (integer): 1 = operation OK message (string): response message PDFcontent (string): binary data of PDF content ContentEncoded (boolean): True = PDFContent data is encoded
-
search_pickup_points
(**kwargs)[source] Main method to search pickup points
Parameters: kwargs – see get_pickup_point_req_data() function Returns: list of pickup point data
-
validate_input_params_create_shipment
(**kwargs)[source]
-
validate_routing_data
(**kwargs)[source]
-
-
pakettikauppa.merchant.
create_currency_element
(root, value=None)[source] Append ‘Consignment.Currency’ element to given root object.
Parameters: - root – root XML element object
- value – string of currency code i.e. ‘EUR’
Returns:
-
pakettikauppa.merchant.
create_merchandise_value_element
(root, value=None)[source] Append ‘Consignment.Merchandisevalue’ element to given root object.
Parameters: - root – root XML element object
- value – string of merchandise value
Returns:
-
pakettikauppa.merchant.
create_product_element
(root, product_code)[source] Append ‘Consignment.Product’ element to given root object.
Parameters: - root – root XML object
- product_code – string of Posti’s product code
Returns:
-
pakettikauppa.merchant.
create_reference_element
(root, value=None)[source] Append ‘Consignment.Reference’ element to given root object.
Parameters: - root – root XML object
- value – string of reference number
Returns:
-
pakettikauppa.merchant.
decode_pdf_content
(encoded_pdf_content)[source]
-
pakettikauppa.merchant.
write_pdf_to_file
(target_file_path, pdf_content)[source]
pakettikauppa.pakettikauppa module¶
Pakettikauppa app
This module provides base functionality for Pakettikauppa integration
-
class
pakettikauppa.pakettikauppa.
Pakettikauppa
(is_test_mode=0)[source] Bases:
object
Base class for Pakettikauppa integration.
-
get_api_end_point
()[source] Get API base end point string
Return base_end_point: API base end point string
-
get_hash_sha256
(secret_key, **kwargs)[source] Calculate SHA256 digest string.
Parameters: - secret_key – string of secret key
- kwargs – dictionary of parameters for caluclation
Return digest_string: digest string
-
get_logger
()[source] Get logger object.
Returns:
-
get_md5_hash
(api_key=None, secret_key=None, routing_id=None)[source] Calculate MD5 digest string.
Parameters: - api_key – string of API key
- secret_key – string of secret key
- routing_id – string of routing id
Return digest_string: digest string
-
get_post_url
(api_suffix=None)[source] Get API post URL address
Parameters: api_suffix – string of API suffix Return api_post_url (string): Post URL
-
logger
= None
-
parse_res_json_data
(res_obj)[source] Parse response JSON data (Not yet completely implemented)
Parameters: res_obj – response object Returns:
-
parse_res_to_list
(res_obj=None)[source] Parse response object to list data.
Parameters: res_obj – response object Return list_data: list data of response data from Pakettikauppa
-
send_request
(send_method='POST', _api_post_url=None, req_input=None, **headers)[source] Send a request to Pakettikauppa.
Parameters: - send_method – type of request method. Possible value are ‘POST’ and ‘GET’, ‘POST’ is default value.
- _api_post_url – string of post URL
- req_input – request input data
- headers – dictionary of header data
Return res_obj: response object
-
set_logger
()[source] Set logger object.
Returns:
-
-
exception
pakettikauppa.pakettikauppa.
PakettikauppaException
[source] Bases:
exceptions.Exception
-
pakettikauppa.pakettikauppa.
check_api_name
(in_function)[source] Validate API name :type in_function: input function
pakettikauppa.reseller module¶
This is a module for Pakettikauppa integration for resellers to use
- The module provides below functionality:
- Create customer
- Update customer
- Get list of customer
- De-activate customer
-
class
pakettikauppa.reseller.
PkReseller
(is_test_mode=0, api_key=None, secret=None)[source] Bases:
pakettikauppa.pakettikauppa.Pakettikauppa
Pakettikauppa reseller class is mean for reseller.
-
accept_payment_service_provider
= ('CHECKOUT', 'CREDIT_CARD')
-
clean_up_phone_data
(phone_string=None)[source] Remove none-digit data from phone number.
Parameters: phone_string – string of phone number Returns:
-
create_customer
(**kwargs)[source] Create customer in Pakettikauppa’s system.
Parameters: kwargs – See get_create_customer_req_data() function Return list_data: list of response data
-
deactivate_customer
(customer_id)[source] De-activate customer account in Pakettikauppa’s system.
Parameters: customer_id – Pakettikauppa’s customer id Return list_data: list of response data
-
get_api_config
(api_name=None)[source] Constructs API configuration
Parameters: api_name – string of API name Return dict_data: dictionary of configuration data - dict_data keys:
- api_post_url (string): post URL address api_key (string): API key api_secret (string): secret key
-
get_api_suffix
(param)[source] Get API suffix for given API name.
Parameters: api_name – string of API name Return api_suffix: string of API suffix
-
get_create_customer_req_data
(**kwargs)[source] Construct request data for create customer API.
Parameters: kwargs – contains following key name: customer name business_id: VAT ID payment_service_provider: possible values are ‘CHECKOUT’ and ‘CREDIT_CARD’, can be empty string psp_merchant_id: Required if payment_service_provider is CHECKOUT. Value is merchant id in the Checkout service. marketing_name: optional field street_address: street address post_office: city name postcode: postal code country: country name phone: phone number email: email address contact_person_name: contact person name contact_person_phone: contact person phone number contact_person_email: contact person email address customer_service_phone: customer service phone number customer_service_email: customer service email address Return dict_data: dictionary of request data
-
get_customer_list
()[source] Get list of customer for your account.
Return list_data: list of response data
-
get_update_customer_req_data
(customer_id, **kwargs)[source] Construct request data for updating customer details.
Parameters: - customer_id – Pakettikauppa’s customer id
- kwargs – attributes that you wish to update. See possible keys from get_create_customer_req_data()
Return dict_data: dictionary of request data
-
update_customer
(customer_id=None, **kwargs)[source] Update customer details in Pakettikauppa’s system.
Parameters: - customer_id – Pakettikauppa’s customer id
- kwargs – attributes that you wish to update. See possible keys from get_create_customer_req_data()
Returns:
-
Module contents¶
Top-level package for Pakettikauppa.