def delete(self, url, username, password): opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(url) request.get_method = lambda: 'DELETE' base64string = base64.encodestring('%s:%s' % (username, password))[:-1] request.add_header("Authorization", "Basic %s" % base64string) response = HTTPResponse(None) try: handle = opener.open(request) info = handle.info() response.setCode(handle.getcode()) print 'Response code = %d' % (handle.getcode()) if info is not None: headers = info.dict if headers is not None: if 'location' in headers: response.setLocation(headers['location']) if 'content-type' in headers: response.setContentType(headers['content-type']) except HTTPError, e: print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code response.setCode(e.code)
def delete(self, url, username, password): opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(url) request.get_method = lambda: 'DELETE' base64string = base64.encodestring('%s:%s' % (username,password))[:-1] request.add_header("Authorization", "Basic %s" % base64string) response=HTTPResponse(None) try: handle = opener.open(request) info=handle.info() response.setCode(handle.getcode()) print 'Response code = %d' % (handle.getcode()) if info is not None: headers=info.dict if headers is not None: if 'location' in headers: response.setLocation(headers['location']) if 'content-type' in headers: response.setContentType(headers['content-type']) except HTTPError, e: print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code response.setCode(e.code)
def paimentSMS(self,cr,uid,ids,context=None): temp=self.browse(cr, uid, ids, context=context) connect_obj = self.pool.get('connect.connect') connect_ids = connect_obj.search(cr,uid,[]) connect_rec = connect_obj.browse(cr, uid, connect_ids) '''information from menu authentication ''' end=str(connect_rec[0].url_pay) #print'end',end password=str(connect_rec[0].password) username =str(connect_rec[0].username) transactionOperationStatus=str(temp[0].transactionOperationStatus) description=str(temp[0].description) currency=str(temp[0].currency) amount= float(temp[0].amount) referenceCode=str(temp[0].referenceCode) taxAmount=str(temp[0].taxAmount) purchaseCategoryCode=str(temp[0].purchaseCategoryCode) channel=str(temp[0].channel) onBehalfOf=str(temp[0].OnBehalfOf) clientCorrelator=str(temp[0].clientCorrelator) endUser=str(temp[0].telephone) ''' adding the string tel: to endUser which is telephone number of one user ''' num="tel:+" +endUser endUserId=num baseurl=end if '{endUserId}' in baseurl : baseurl=baseurl.replace('{endUserId}', str(endUserId)) responsetype='application/json' '''form urlencoded ''' conTyp='application/x-www-form-urlencoded' formdata = { "clientCorrelator" : clientCorrelator, "endUserId" : endUserId, "amount" : amount , "currency" : currency, "description" : description, "onBehalfOf" : onBehalfOf, "purchaseCategoryCode" : purchaseCategoryCode, "channel" : channel, "taxAmount" : taxAmount, "referenceCode" : referenceCode, "transactionOperationStatus" : transactionOperationStatus, } '''turn data into understandable data url ''' data_encoded = urllib.urlencode(formdata) test= data_encoded.replace('+','%20') opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(baseurl, test) print'base',baseurl if responsetype is not None: request.add_header('Accept', responsetype) if conTyp is not None : request.add_header('Content-Type',conTyp) request.get_method = lambda: 'POST' base64string=base64.encodestring('%s:%s' % (username, password)).replace('\n', '') request.add_header("Authorization", "Basic %s" % base64string) '''instantiation of the HttpResponse class ''' response=HTTPResponse(None) try: handle = opener.open(request) ''' convert json object to object python ''' jsondata=json.loads(handle.read()) print'jsondata',jsondata info=handle.info() content=handle.read() response.setCode(handle.getcode()) response.setContent(content) cod=handle.getcode() print 'Response code = %d' % (handle.getcode()) ''' if success store it in field define in openerp ''' if cod==201 or cod==200 : self.pool.get('paiment.paiment').write(cr,uid,ids,{'response' : ' Success'}) else : self.pool.get('paiment.paiment').write(cr,uid,ids,{'response' : ' failed'}) if info is not None: headers=info.dict if headers is not None: if 'location' in headers: response.setLocation(headers['location']) if 'content-type' in headers: response.setContentType(headers['content-type']) except HTTPError, e: print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code response.setCode(e.code)
def postMultipart(self, url, postdata, responsetype, username, password, boundary): opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(url, postdata) if responsetype is not None: request.add_header('Accept', responsetype) request.get_method = lambda: 'POST' base64string = base64.encodestring('%s:%s' % (username, password))[:-1] request.add_header("Authorization", "Basic %s" % base64string) request.add_header("Content-Type", 'multipart/mixed; boundary="' + boundary + '"') response = HTTPResponse(None) try: handle = opener.open(request) info = handle.info() content = handle.read() response.setCode(handle.getcode()) response.setContent(content) print 'Response code = %d' % (handle.getcode()) if info is not None: headers = info.dict if headers is not None: if 'location' in headers: response.setLocation(headers['location']) if 'content-type' in headers: response.setContentType(headers['content-type']) except HTTPError, e: print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code response.setCode(e.code)
def postMultipart(self, url, postdata, responsetype, username, password, boundary): opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request(url, postdata) if responsetype is not None: request.add_header('Accept', responsetype) request.get_method = lambda: 'POST' base64string = base64.encodestring('%s:%s' % (username,password))[:-1] request.add_header("Authorization", "Basic %s" % base64string) request.add_header("Content-Type", 'multipart/mixed; boundary="'+boundary+'"') response=HTTPResponse(None) try: handle = opener.open(request) info=handle.info() content=handle.read() response.setCode(handle.getcode()) response.setContent(content) print 'Response code = %d' % (handle.getcode()) if info is not None: headers=info.dict if headers is not None: if 'location' in headers: response.setLocation(headers['location']) if 'content-type' in headers: response.setContentType(headers['content-type']) except HTTPError, e: print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code response.setCode(e.code)