def _save_fulfillment_parameters(request, client):
        # type: (Dict, ConnectClient) -> None
        """ This method saves the needed information of the created subscription in the request's fulfillment
            parameters. Customize the Payload params ids with your product fulfillment parameters id in Connect and
            the params values with the ones given by the Vendor API. """

        request_id = Utils.get_basic_value(request, 'id')
        # Update the fulfilment parameters in Fulfillment Request in Connect with the corresponding value

        # Prepare the update parameters payload with the response of APIClient.create_subscription method
        payload = {
            "asset": {
                "params": [
                    {
                        # TODO: Customize the fulfillment parameter id, as configured in product in Connect
                        # Saving the Subscription ID from Vendor system is encouraged to be able to map
                        # the subscription in Connect with the subscription in Vendor system
                        "id": "subscription_id",
                        "value": "value for subscription ID in Vendor System",
                        "value_error": "",
                        "structured_value": {}
                    },
                    {
                        # TODO: Change and/or add the fulfillment parameters id, as configured in product in Connect
                        "id": "param_b",
                        "value": "value for parameter b",
                        "value_error": "",
                        "structured_value": {}
                    }
                ]
            }
        }

        # Update the value in the fulfillment parameter
        Utils.update_subscription_parameters(request_id, payload, client)
    def _save_fulfillment_parameters(request, client):
        # type: (Dict, ConnectClient) -> None
        """ This method saves the needed information of the reseller in the tier config request's fulfillment
            parameters. Customize the Payload params ids with your product tier fulfillment parameters id in Connect and
            the params values with the ones given by the Vendor API. """

        tcr_id = Utils.get_basic_value(request, 'id')

        # Prepare the update parameters payload with the response of APIClient.create_subscription method
        payload = {
            "params": [
                {
                    # TODO: Customize the tier fulfillment parameter id, as configured in product in Connect
                    "id": "param_a",
                    "value": "value for param_a in Vendor System",
                    "value_error": "",
                    "structured_value": ""
                },
                {
                    # TODO: Change and/or add the tier fulfillment parameters id, as configured in product in Connect
                    "id": "param_b",
                    "value": "value for param b in Vendor System",
                    "value_error": "",
                    "structured_value": ""
                }
            ]
        }

        # Update the value in the fulfillment parameter of the tier configuration
        Utils.update_tier1_parameters(tcr_id, payload, client)
    def process_request(request, client):
        # type: (Dict, ConnectClient) -> Dict
        """  This method processes the Fulfillment Requests in Pending status for change subscription action.
            If vendor system does not support the change in the subscription check the request details
            to reject the request with proper message. """

        # Get the existing subscription Id saved as fulfilment parameter to Prepare the body/payload for the Vendor API
        # to update the subscription
        # Saving the Subscription ID from Vendor system is encouraged to be able to map the subscription in Connect with
        # the subscription in Vendor system
        # The Subscription ID can be saved in a fulfillment parameter
        # This external_subscription_id from Vendor platform might be required to call the Vendor API to change
        # the subscription
        external_subscription_id = Utils.get_param_value(
            request, 'fulfillment', 'subscription_id')

        # TODO: Add code to Update/Change the subscription in vendor system by calling the Vendor API
        # to update/change subscription
        # api_client = APIClient(api_url='',
        #                        api_key='')
        # change_payload = {}
        # api_client.change_subscription(change_payload, external_subscription_id)

        # When successful, approve the fulfillment request with the following code:
        return Utils.approve_fulfillment_request(request, client)
Ejemplo n.º 4
0
def do_validate():
    json_data = request.json
    # Customize: replace 'param_id_to_validate' with Id of the parameter that requires to be validated
    value = Utils.get_param_value(json_data, 'ordering',
                                  'param_id_to_validate')
    # Customize: Implement the desired logic to validate the value provided as the parameter
    # api_client = APIClient(api_url='',
    #                        api_key='')
    # error_message = api_client.validate_param(value)

    # Customize: Provide proper error message
    error_message = "Param param_id_to_validate not valid "
    if len(error_message) > 0:
        params = json_data['asset']['params']
        validated_param = Utils.get_item_by_id(params, 'param_id_to_validate')
        validated_param['value_error'] = error_message
        set_parameter(params, validated_param)
    return json_data
    def process_request(request, client):
        # type: (Dict, ConnectClient) -> Dict
        """ This method processes the Fulfillment Requests in Pending status for resume subscription action """

        # Get the subscription Id from the request that needs to be resumed
        # Saving the Subscription ID from Vendor system is encouraged to be able to map the subscription in Connect
        # with the subscription in Vendor system
        # The Subscription ID can be saved in a fulfillment parameter
        # This external_subscription_id from Vendor platform might be required to call the Vendor API
        # to resume the suspended subscription
        external_subscription_id = Utils.get_param_value(request, 'fulfillment', 'subscription_id')

        # TODO: Add code to Resume the subscription in vendor system by calling the Vendor API
        # to resume subscription
        # api_client = APIClient(api_url='',
        #                        api_key='')
        # resume_payload = {}
        # api_client.resume_subscription(resume_payload, external_subscription_id)

        # When successful, approve the fulfillment request with the following code:
        return Utils.approve_fulfillment_request(request, client)
Ejemplo n.º 6
0
    def process_request(request, client):
        # type: (Dict, ConnectClient) -> Dict
        """ This method approves or rejects the Fulfillment Requests in Pending status
        for cancel subscription action. """

        # Get the fulfillment parameter values from the subscription that needs to be cancelled
        # Saving the Subscription ID from Vendor system is encouraged to be able to map the Connect subscription
        # with the subscription in Vendor system. The Subscription ID can be saved in a fulfillment parameter.
        # Here 'subscription_id' is an example of Connect product fulfillment parameter id.
        # This external_subscription_id from Vendor platform might be required to call the Vendor API
        # to cancel the subscription
        external_subscription_id = Utils.get_param_value(
            request, 'fulfillment', 'subscription_id')

        # TODO: Add your code to Cancel the subscription in vendor system by calling the Vendor API
        # api_client = APIClient(api_url='',
        #                        api_key='')
        # cancel_payload = {}
        # api_client.cancel_subscription(cancel_payload, external_subscription_id)

        # When successful, approve the fulfillment request with the following code:
        return Utils.approve_fulfillment_request(request, client)
    def process_request(request, client):
        # type: (Dict, ConnectClient) -> Dict
        """ This method processes a tier configuration request in pending status for setup and update action. """

        # Check the reseller data in vendor system by calling the Vendor API
        # TODO: implement the Vendor API call to check, create or update the reseller in Vendor portal
        # The following is the Mock API and client to check tier scope ordering phase parameters
        # api_client = APIClient(api_url='',
        #                        api_key='')
        # data = {}
        # reseller_info = api_client.check_reseller(data=data)
        tcr_id = Utils.get_basic_value(request, 'id')

        # The response of check reseller Vendor API might have some information that needs to be saved in
        # the fulfillment parameter of the tier config request in Connect
        # With this response complete the tier config fulfillment parameters to be able to approve the request
        TierConfiguration._save_fulfillment_parameters(request, client)

        # If any tier scope parameter is not valid, the tier config request can be changed to Inquiring status,
        # so the reseller can change and check the entered values
        # using this method call Utils.set_inquiring_tier_config_request(tcr_id, client)

        return Utils.approve_tier_config_request(request, tcr_id, client)
 def _get_usage_data(subscription, usage_data):
     # type: (Any, [Any]) -> UsageData
     # Fills the UsageDate object with the subscription and usage data from Vendor.
     subs_usage_data = Utils.get_item_by_id(usage_data['subscriptions'],
                                            subscription['id'])
     usage_data_object = UsageData()
     usage_data_object.record_description = subscription['product'][
         'name'] + " Period: " + subs_usage_data[
             'start_date'] + "-" + subs_usage_data['end_date']
     usage_data_object.item_mpn = subs_usage_data['mpn']
     usage_data_object.quantity = subs_usage_data['quantity']
     usage_data_object.start_time_utc = subs_usage_data['start_date']
     usage_data_object.end_time_utc = subs_usage_data['end_date']
     usage_data_object.asset_recon_id = subs_usage_data['id']
     return usage_data_object
        def create_usage_excel(self, record_data):
            # type: ([UsageData]) -> str
            # Creates the Excel .xlsx File and loads the records returning the file path
            excel_records = Usage.UsageFileExcelCreator._load_records(
                record_data)
            workbook = self._create_usage_records_sheet(records=excel_records)

            # Saves the file in the .config folder
            config_file = Utils.get_config_file()
            usage_path = config_file['rootPathUsage']
            if not os.path.exists(usage_path):
                os.mkdir(usage_path)
            path = usage_path + "/usage_file" + datetime.today().strftime(
                "%Y%m%d%H%M%S") + ".xlsx"
            workbook.save(path)
            return path
    def process_request(request, client):
        # type: (Dict, ConnectClient) -> Dict
        """ This method processes the Fulfillment Requests in Pending status for purchase subscription action """

        # Create the subscription in vendor system by calling the Vendor API to create subscription
        # TODO: implement the Vendor API call to create the subscription in Vendor portal
        # The following is the Mock API and client to create subscription
        # api_client = APIClient(api_url='',
        #                        api_key='')
        # data = {}
        # subscription_info = api_client.create_subscription(data=data)

        # The response of create subscription Vendor API might have some information that needs to be saved in
        # the fulfillment parameter of the subscription request in Connect
        # With this response complete the request fulfillment parameters to be able to approve the request
        Purchase._save_fulfillment_parameters(request, client)

        return Utils.approve_fulfillment_request(request, client)
Ejemplo n.º 11
0
from cnct import ConnectClient
from datetime import datetime
from connect_processor.app.utils.globals import Globals
from connect_processor.app.utils.utils import Utils
from cnct import R

project_manager = __import__('connect_processor.app', globals(), locals(), [
    'purchase', 'change', 'cancel', 'suspend', 'resume', 'tier_fulfillment',
    'report_usage'
], 0)

# The processor.py is the entry point of Processor execution
if __name__ == '__main__':

    # Reading the config.json file in the Processor
    config_file = Utils.get_config_file()
    # apiEndpoint is the API End-point of Connect
    connect_api_url = config_file['connectApiEndpoint'],
    # apiKey is the API key for authorization created in Integrations menu of Connect
    connect_key = config_file['connectApiKey'],
    # Products are the list of IDs of the products which needs to be processed by this Processor
    client = ConnectClient(api_key=connect_key[0], endpoint=connect_api_url[0])

    # If the Product has parameters of scope 'Tier' then Tier use case implementation will be required.
    # Make sure the project has the Tier use case included during project creation
    # The Tier Config Requests (TCR) needs to be processed first and then the corresponding Fulfillment Requests
    if hasattr(project_manager, 'tier_fulfillment'):
        # Filter to fetch the Tier-Config-Request (TCR) for this product
        # The processor needs to process only the TCRs in Pending status

        query_tcr = R()