예제 #1
0
    def send(self, command, params=None, requester=None, api_type=None, resource=None):
        if not params:
            params = requester.translated_data

        root = etree.Element('transaction-request')

        etree.SubElement(root, 'version').text = self.api_version

        verification = etree.SubElement(root, 'verification')
        etree.SubElement(verification, 'merchantId').text = self.maxid
        etree.SubElement(verification, 'merchantKey').text = self.api_key

        order = etree.SubElement(root, 'order')

        command = etree.SubElement(order, command)

        for key, value in params:
            create_element_recursively(command, key).text = value

        xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)

        def callback(response, resource):
            if resource:
                resource = resource(data=response.content, requester=requester, manager=self)

            return requester.data.get('callback', lambda x: x)(resource or response)

        self.request(xml_data, callback=lambda resp: callback(resp, resource))
예제 #2
0
    def send(self, command, params=None, requester=None, api_type=None, resource=None):
        if not params:
            params = requester.translated_data

        root = etree.Element('rapi-request')

        etree.SubElement(root, 'version').text = self.api_version

        verification = etree.SubElement(root, 'verification')
        etree.SubElement(verification, 'merchantId').text = self.maxid
        etree.SubElement(verification, 'merchantKey').text = self.api_key

        etree.SubElement(root, 'command').text = command

        request = etree.SubElement(root, 'request')

        for key, value in params:
            create_element_recursively(request, key).text = value

        xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)

        response = self.request(xml_data)
        if resource:
            return resource(data=response.content, requester=requester, manager=self)
        return response
예제 #3
0
    def send(self, command, params=None, requester=None, api_type=None, resource=None):
        if not params:
            params = requester.translated_data

        root = etree.Element('rapi-request')

        etree.SubElement(root, 'version').text = self.api_version

        verification = etree.SubElement(root, 'verification')
        etree.SubElement(verification, 'merchantId').text = self.maxid
        etree.SubElement(verification, 'merchantKey').text = self.api_key

        etree.SubElement(root, 'command').text = command

        request = etree.SubElement(root, 'request')

        for key, value in params:
            create_element_recursively(request, key).text = value

        xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)

        response = self.request(xml_data)
        if resource:
            return resource(data=response.content, requester=requester, manager=self)
        return response