U
    -d                     @   sN   d Z ddlZddlmZmZ ddlmZ ddlT G dd deZ	d
dd	Z
dS )ui  
WSDL кривоватая, клиенты с ней сходу не работают. Делаем на raw requests

/vcrm/vtigerservice.php?service=leadfromsite HTTP/1.1
Host: soap.crm.carbonsoft.ru
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.3
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:xmethods-delayed-quotes#getQuote"
Content-Length: 1190

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:create_lead_from_site><email xsi:type="xsd:string">s.troshin@carbonsoft.ru</email><name xsi:type="xsd:string">............ ............ ..........................</name><company xsi:type="xsd:string">................</company><town xsi:nil="true"/><cid xsi:type="xsd:string">1475393252.1526982157</cid><roistat xsi:type="xsd:string"></roistat><phone xsi:type="xsd:string">+79090201999</phone><cnt xsi:nil="true"/><downloaduri xsi:type="xsd:string">http://download5.carbonsoft.ru/Carbon_install/Carbon_Billing_x64.img</downloaduri><refer xsi:type="xsd:string">None</refer><ip xsi:type="xsd:string">195.64.222.80</ip><product xsi:type="xsd:string">CRB-Billing5</product><is_carbon_ip xsi:type="xsd:string">true</is_carbon_ip></ns1:create_lead_from_site></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
      <ns1:create_lead_from_siteResponse xmlns:ns1="urn:xmethods-delayed-quotes">
          <return xsi:type="xsd:string">Save1</return>
      </ns1:create_lead_from_siteResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
    N)urlopenRequest)escape)*c                   @   s   e Zd ZdS )	VcrmErrorN)__name__
__module____qualname__ r
   r
   ./common/vcrm.pyr   %   s   r   c           
      K   s   | pd} | }|pd}|pd}|p"d}t js8td d S td|| | dt|  dt| dt| dt| dt| t j d	}tt j d
| dddd}t|dd}|	 
d}	W 5 Q R X td|	 d|	krtd|	d S )N z+Register vcrm skip. VCRM_URL not configuredz!Register vcrm product: %s, %s, %sa  <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:create_lead_from_site>
        <email xsi:type="xsd:string">z-</email>
        <name xsi:type="xsd:string">z/</name>
        <company xsi:type="xsd:string">z</company>
        <town xsi:nil="true"/>
        <cid xsi:type="xsd:string"></cid>
        <roistat xsi:type="xsd:string"></roistat>
        <phone xsi:type="xsd:string">zZ</phone>
        <cnt xsi:nil="true"/>
        <downloaduri xsi:type="xsd:string">https://a3  /</downloaduri>
        <refer xsi:type="xsd:string">None</refer>
        <ip xsi:type="xsd:string">127.0.0.1</ip>
        <product xsi:type="xsd:string">ACRM</product>
        <is_carbon_ip xsi:type="xsd:string">false</is_carbon_ip>
    </ns1:create_lead_from_site>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
z,/vcrm/vtigerservice.php?service=leadfromsiteztext/xml; charset=utf-8z&"urn:xmethods-delayed-quotes#getQuote")zContent-TypeZ
SOAPAction)Zheaders   )timeoutzutf-8zRegister vcrm response: %sZSave1zInvalid return value)ZconfigZVCRM_URLlogginginfor   ZAUTH_SESSION_COOKIE_DOMAINr   encoder   readdecoder   )
ZemailZphoneZorg_nameZcompany_kwargsnamedataZrequestfZresponser
   r
   r   vcrm_register)   sD    


r   )NNNN)__doc__r   Zurllib.requestr   r   Zxml.sax.saxutilsr   Zcmf.include	Exceptionr   r   r
   r
   r
   r   <module>   s   