Example #1
0
    def __init__(self, tripleg_number, date, carrier, class_transport,
                 dest_from, dest_to, stop_over, basis_code, flight_number):
        """
        Args:
            tripleg_number (string): flight number
            date (string): date of tripleg
            carrier (string): carrier code
            class_transport (string): transport class
            dest_from (string): aiport from code
            dest_to (string): aiport to code
            stop_over (string): can stop (O|X)
            basis_code (string): tariff code
            flight_number (string): fligth number
        """
        if int(tripleg_number) <= 0 or int(tripleg_number) > 4:
            raise SdkException('Only 4 tripleg could be send')

        setattr(self, 'pg_tripleg_' + tripleg_number + '_date', date)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_carrier', carrier)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_class',
                class_transport)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_destination_from',
                dest_from)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_destination_to',
                dest_to)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_stopover', stop_over)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_fare_basis_code',
                basis_code)
        setattr(self, 'pg_tripleg_' + tripleg_number + '_flight_number',
                flight_number)
    def add_failure_url_method(self, method):
        """
        :param method: method which will be used when send user on failure url (string)
        """
        if self.__get_redirect_method_variables().get(method) == None:
            raise SdkException('Wrong method. Use from constants')

        self.pg_failure_url_method = method
Example #3
0
    def add_vat(self, vat):
        """
        :param vat: product vat 0|10|20|110|120 (string)
        """
        if self.__get_vat_variables().get(vat) == None:
            raise SdkException('Wrong vat. Use from constants')

        self.pg_vat = vat
    def add_request_method(self, method):
        """
        :param method: method which will be used to request merchant (string)
        """
        if self.__get_request_method_variables().get(method) == None:
            raise SdkException('Wrong request method. Use from constants')

        self.pg_request_method = method
Example #5
0
    def add_type(self, item_type):
        """
        :param item_type: product type (string)
        """
        if self.__get_type_variables().get(item_type) == None:
            raise SdkException('Wrong item type. Use from constants')

        self.pg_type = item_type
    def add_dates(self, dates):
        """
        :param dates: Set of sting dates (Dict)
        """
        if len(dates) == 0:
            raise SdkException('Use not empty Set')

        self.pg_dates = dates
Example #7
0
    def add_payment_type(self, payment_type):
        """
        :param payment_type: payment type (string)
        """
        if self.__get_payment_type_variables().get(payment_type) == None:
            raise SdkException('Wrong item type. Use from constants')

        self.pg_payment_type = payment_type
Example #8
0
    def add_item(self, item):
        """
        :param item: 1 item in receipt (Item)
        """
        if not isinstance(item, Item):
            raise SdkException('Only item object expected')

        self.receipt_items.append(item.get_params())
    def add_ps_additional_parameters(self, params):
        """
        :param params: ps additional params with pg_ names (Dict)
        """
        for param_name in params.keys():
            if param_name.find('pg_') == -1:
                raise SdkException('Only params without pg_')

            setattr(self, param_name, params.get(param_name))
Example #10
0
    def __init__(self, operation_type, payment_id=None, order_id=None):
        """
        Payment id or order id is not None
        :param operation_type: operation type payment|refund|moneyback (string)
        :param payment_id: digital platron payment id (string)
        :param order_id: merchant order id (string)
        """
        if payment_id == None and order_id == None:
            raise SdkException('payment id or order id must be nut null')

        if self.__get_operstion_types().get(operation_type) == None:
            raise SdkException('Wrong vat. Use from constants')

        self.pg_operation_type = operation_type
        if payment_id != None:
            self.pg_payment_id = payment_id
        if order_id != None:
            self.pg_order_id = order_id
Example #11
0
    def add_merchant_params(self, params):
        """
        :param params: merchant params without pg_ names which will get on result (Dict)
        """
        for param_name in params.keys():
            if param_name.find('pg_') != -1:
                raise SdkException('Only params without pg_')

            setattr(self, param_name, params.get(param_name))
Example #12
0
    def add_gds(self, avia_gds):
        """
        :param avia_gds: avia gds data (AviaGds)
        """
        if not isinstance(avia_gds, AviaGds):
            raise SdkException('Only long record object expected')

        avia_gds_params = avia_gds.get_params()
        for param_name in avia_gds_params.keys():
            setattr(self, param_name, avia_gds_params.get(param_name))
Example #13
0
    def add_bankcard(self, bankcard):
        """
        :param bankcard: bank card data (BankCard)
        """
        if not isinstance(bankcard, BankCard):
            raise SdkException('Only long record object expected')

        bank_card_params = bankcard.get_params()
        for param_name in bank_card_params.keys():
            setattr(self, param_name, bank_card_params.get(param_name))
Example #14
0
    def add_long_record(self, long_record):
        """
        :param long_record: long record params (LongRecord)
        """
        if type(long_record) != LongRecord:
            raise SdkException('Only long record object expected')

        long_record_params = long_record.get_params()
        for param_name in long_record_params.keys():
            setattr(self, param_name, long_record_params.get(param_name))
Example #15
0
    def add_additional_payment(self, payment_type, amount):
        """
        :param payment_type: additional payment type credit|debit (string)
        :param amount: additional payment amount (string)
        """
        if self.__get_additional_payment_types().get(payment_type) == None:
            raise SdkException('Wrong additional payment type. Use from constants')

        self.pg_additional_payment_type = payment_type
        self.pg_additional_payment_amount = amount
Example #16
0
    def add_tripleg(self, tripleg):
        """
        :param tripleg: One of four triplegs (TripLeg)
        """
        if not isinstance(tripleg, TripLeg):
            raise SdkException('Only long record object expected')

        params = tripleg.get_params()
        for param_name in params.keys():
            setattr(self, param_name, params.get(param_name))
Example #17
0
    def request(self, request_builder):
        """
        :param request_builder: instance of RequestBuilder (RequestBuilder)
        :raise SdkException
        :return Response (string)
        """
        try:
            params_to_request = request_builder.get_params()
            params_to_request.update({'pg_merchant_id': self.merchant})
            params_to_request.update({'pg_salt': random.randint(1, 10000)})

            sig_helper = SigHelper(self.secret_key)

            parsed_list = request_builder.get_url().split('/');
            script_name = parsed_list.__getitem__(parsed_list.__len__() - 1)

            not_treated_xml = dicttoxml.dicttoxml(params_to_request, True, 'request', False, False,
                                                  item_func=request_builder.item_function)
            xml_to_request_no_sig = request_builder.after_xml_created(not_treated_xml.decode('utf_8'))
            signature = sig_helper.make_xml(script_name, xml_to_request_no_sig)
            xml_to_request = self.add_sig_to_xml(xml_to_request_no_sig, signature)

            response = requests.post(request_builder.get_url(), {'pg_xml': xml_to_request})
            root = fromstring(response.text)
            signature = root.find('pg_sig').text
        except Exception:
            raise SdkException('Cant send request or parse response')

        for child in root:
            if child.tag == 'pg_error_description':
                pg_error_description = child.text
            if child.tag == 'pg_error_code':
                pg_error_code = child.text

        if 'pg_error_code' in locals():
            raise SdkException('Error in response ' + pg_error_description + ' code ' + pg_error_code)

        sig_helper = SigHelper(self.secret_key)
        if not sig_helper.check_xml(signature, script_name, response.text):
            raise SdkException('Wrong signature in response')

        return response.text
Example #18
0
    def validate_sig(self, params):
        """ Validete signature in callback request
        Args:
            params (dict): xml string
        Returns:
            Boolean
        """
        try:
            pg_sig = params.get('pg_sig')
        except Exception:
            raise SdkException('No pg_sig in request')

        return self.sig_helper.check(pg_sig, self.script_name, params)
Example #19
0
    def response_ok(self, params):
        """ Get xml with ok to responde
        Args:
            params (dict): xml string
        Returns:
            Xml string
        """
        try:
            pg_salt = params.get('pg_salt')
        except Exception:
            raise SdkException('No pg_salt in request')

        return self.__response(pg_salt, 'ok', 'ok')
Example #20
0
    def add_agent(self, agent_type, agent_name, agent_inn, agent_phone):
        """
        :param agent_type: agent type (string)
        :param agent_name: agent name (string)
        :param agent_inn: agent inn (string)
        :param agent_phone: agent legal phone sample 79050000000 (string)
        """
        if self.__get_agent_type_variables().get(agent_type) == None:
            raise SdkException('Wrong item type. Use from constants')

        self.pg_agent_type = agent_type
        self.pg_agent_name = agent_name
        self.pg_agent_inn = agent_inn
        self.pg_agent_phone = agent_phone
Example #21
0
    def response_error(self, params, error):
        """ Get xml with error to responde
        Args:
            params (dict): xml string
            error (str): error description
        Returns:
            Xml string
        """
        try:
            pg_salt = params.get('pg_salt')
        except Exception:
            raise SdkException('No pg_salt in request')

        return self.__response(pg_salt, 'error', error)
Example #22
0
    def response_rejected(self, params, description):
        """ Get xml with rejected to responde
        Args:
            params (dict): xml request
            error (str): rejected description
        Returns:
            Xml string
        """
        try:
            pg_salt = params.get('pg_salt')
        except Exception:
            raise SdkException('No pg_salt in request')

        return self.__response(pg_salt, 'rejected', description)
    def add_template(self, start_date, interval, period, max_periods=None):
        """
        :param start_date: start date of template (string)
        :param interval: day|week|month (string)
        :param period: digital period of interval (string)
        :param max_periods: digital max periods (string)
        """
        if self.__get_intervals().get(interval) == None:
            raise SdkException('Wrong interval. Use from constants')

        self.pg_template = {
            'pg_start_date': start_date,
            'pg_interval': interval,
            'pg_period': period
        }
        if max_periods != None:
            self.pg_template.update({'pg_max_periods': max_periods})
Example #24
0
 def get_url(self):
     raise SdkException('Not implemented get_url method')