def get_url(self, url_data): """ Process an HTTP GET request given the full URL including XML and throw the response into a database ASAP in case something goes wrong during processing. @param url_data The url-encoded data string @type url_data str @return dictionary of response values indexed by name @rtype dict """ log_prefix = u'api_tools.get_url(): ' # Let's do this before the transaction just in case it causes trouble. rr = raw_response() # If we are using certificate authentication, this is where the magic happens if hasattr(settings, 'cert_file') and hasattr( settings, 'key_file') and settings.cert_file and settings.key_file: cert_args = { 'cert_file': settings.cert_file, 'key_file': settings.key_file, } else: cert_args = {} try: f = urllib.FancyURLopener(**cert_args).open( self.settings.url, url_data) except IOError, ioe: _logger.error(log_prefix + (u'IOError: [%s]' % unicode(ioe))) raise connection_error_exception
def get_url(self, url_data): """ Process an HTTP GET request given the full URL including XML and throw the response into a database ASAP in case something goes wrong during processing. @param url_data The url-encoded data string @type url_data str @return dictionary of response values indexed by name @rtype dict """ log_prefix = u'api_tools.get_url(): ' # Let's do this before the transaction just in case it causes trouble. rr = raw_response() # If we are using certificate authentication, this is where the magic happens if hasattr(settings, 'cert_file') and hasattr(settings, 'key_file') and settings.cert_file and settings.key_file: cert_args = { 'cert_file' : settings.cert_file, 'key_file' : settings.key_file, } else: cert_args = {} try: f = urllib.FancyURLopener(**cert_args).open(self.settings.url, url_data) except IOError, ioe: _logger.error(log_prefix + (u'IOError: [%s]' % unicode(ioe))) raise connection_error_exception
def get_url(self, xml_doc): """ GET the full url including xml, and throw the response into a database ASAP in case something goes wrong during processing. @param xml_doc instance of xml.dom.minidom.Document @type xml_doc xml.dom.minidom.Document @return dictionary of response values indexed by name @rtype dict """ xml = xml_doc.toxml() # VM doesn't accept the standard XML meta tag, so we must perform foolishness to remove it. p = urllib.urlencode({'xmldata' : xml[xml.index('>') + 1:]}) rr = raw_response() # Lets do this before the transaction just in case it causes trouble try: f = urllib.urlopen(self.settings.vm_url + '?%s' % p) except IOError: raise connection_error_exception # Throw this stuff into a database ASAP in case something goes wrong rr.text = f.read() rr.enter() try: response = parseString(rr.text) except ExpatError: raise invalid_xml_response_exception return response
def complete(self, token): """ Complete a sale. @param token the string issued by paypal which identifies a transaction @type token str @return dictionary containing transaction_id and result_message @rtype dict """ try: token = paypal_ec_token.objects.get(token=token) except paypal_ec_token.DoesNotExist: raise paypal_token_not_found_exception data = self.credentials.copy() data.update({ 'METHOD': 'GetExpressCheckoutDetails', 'TOKEN': token.token, }) details = self.get_url(urllib.urlencode(data)) data = self.credentials.copy() data.update({ 'METHOD': 'DoExpressCheckoutPayment', 'TOKEN': token.token, 'PAYMENTACTION': 'Sale', 'PAYERID': details['PAYERID'], 'AMT': token.amount, }) rr = raw_response() payment = self.get_url(urllib.urlencode(data)) rr.text = str(payment) rr.enter() token.delete() context = { 'AMT': payment['AMT'], 'FIRSTNAME': details['FIRSTNAME'], 'LASTNAME': details['LASTNAME'], 'ORDERTIME': payment['ORDERTIME'], 'TRANSACTIONID': payment['TRANSACTIONID'], } return context
def _issue_request(self, xml): """ This is a common method that can be used to submit a request in XML form to the payflowpro server @param xml XML data structure expected by paypal's server @type xml string """ rr = raw_response() try: response = urllib.urlopen(self.settings.URL, xml) except IOError: raise connection_error_exception rr.text = response.read() rr.enter() return self._parse_response(rr.text)