Beispiel #1
0
    def _fetch(self, params, required, defaults):
        """Make the NVP request and store the response."""
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)

        if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG):
            log.debug('PayPal Request:\n%s\n', pprint.pformat(defaults))
            log.debug('PayPal Response:\n%s\n', pprint.pformat(response_params))

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}
        for k, v in MergeDict(defaults, response_params).items():
            if k in NVP_FIELDS:
                nvp_params[str(k)] = v

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(nvp_params['timestamp'])

        nvp_obj = PayPalNVP(**nvp_params)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #2
0
    def _fetch(self, params, required, defaults):
        """
        Make the NVP request and store the response.
        
        """
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)        
        pp_string = self.signature + urllib.urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)
        
        print 'PayPal Request:'
        pprint.pprint(defaults)
        print '\nPayPal Response:'
        pprint.pprint(response_params)

        # Put all fields from NVP into everything so we can pass it to `create`.
        everything = {}
        def merge(*dicts):
            for d in dicts:
                for k, v in d.iteritems():
                    if k in NVP_FIELDS:
                        everything[k] = v
                        
        merge(defaults, response_params)

        # PayPal timestamp has to be set correctly to be stored.
        if 'timestamp' in everything:
            everything['timestamp'] = paypaltime2datetime(everything['timestamp'])

        nvp_obj = PayPalNVP(**everything)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #3
0
    def _fetch(self, params, required, defaults):
        """Make the NVP request and store the response."""
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)

        # save the response and request to the database:
        if 'user_email' in defaults:
            cpm = CartProcessingMessage()
            cpm.user_email_address = defaults['user_email']
            if 'firstname' in defaults:
                cpm.first_name = defaults['firstname']
            if 'lastname' in defaults:
                cpm.last_name = defaults['lastname']

            if response_params['ack'].lower() == 'failure':
                cpm.type = 'ERROR'
            else:
                cpm.type = 'SUCCESS'

            cpm.data_sent = self.clean_defaults(defaults)
            cpm.message = response_params
            cpm.save()

        if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG):
            print 'PayPal Request:'
            pprint.pprint(defaults)
            print '\nPayPal Response:'
            pprint.pprint(response_params)

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}
        for k, v in MergeDict(defaults, response_params).items():
            if k in NVP_FIELDS:
                nvp_params[str(k)] = v

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(nvp_params['timestamp'])

        nvp_obj = PayPalNVP(**nvp_params)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #4
0
    def _fetch(self, params, required, defaults):
        """Make the NVP request and store the response."""
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)

        if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG):
            log.debug('PayPal Request:\n%s\n', pprint.pformat(defaults))
            log.debug('PayPal Response:\n%s\n', pprint.pformat(response_params))

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}
        tmpd = defaults.copy()
        tmpd.update(response_params)
        for k, v in tmpd.items():
            if k in self.NVP_FIELDS:
                nvp_params[str(k)] = v

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(nvp_params['timestamp'])

        nvp_obj = PayPalNVP(**nvp_params)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #5
0
    def _fetch(self, params, required, defaults):
        """Make the NVP request and store the response."""
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)        
        pp_string = self.signature + urllib.urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)
        
        print 'PayPal Request:'
        pprint.pprint(defaults)
        print '\nPayPal Response:'
        pprint.pprint(response_params)

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}
        for k, v in MergeDict(defaults, response_params).items():
            if k in NVP_FIELDS:
                nvp_params[k] = v    

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(nvp_params['timestamp'])

        nvp_obj = PayPalNVP(**nvp_params)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #6
0
    def _fetch(self, params, required, defaults):
        """Make the NVP request and store the response."""
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)


#        log.info( 'PayPal Request:%s\nPayPal Response:%s'%
#            (pprint.pformat(defaults),pprint.pformat(response_params)))

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}
        for k, v in MergeDict(defaults, response_params).items():
            if k in NVP_FIELDS:
                nvp_params[str(k)] = v

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(nvp_params['timestamp'])


        nvp_obj = PayPalNVP(**nvp_params)

        nvp_obj.init(self.request, params, response_params)
        nvp_obj.custom = params.get('PAYMENTREQUEST_0_CUSTOM','')
        nvp_obj.save()
        return nvp_obj
    def _fetch(
        self, params, required=None, defaults=None, extra_requirements=None):
        """Make the NVP request and store the response."""
        if required is None or defaults is None:
            assert params['METHOD'] in API_METHODS
            if required is None:
                required = API_METHODS[params['METHOD']].get('required', ())
            if defaults is None:
                defaults = API_METHODS[params['METHOD']].get('defaults', {})
        required += extra_requirements or ()
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)

        if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG):
            print 'PayPal Request:'
            pprint.pprint(defaults)
            print '\nPayPal Response:'
            pprint.pprint(response_params)

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}

        for key, value in dict(defaults, **response_params).items():
            if key.lower() in NVP_FIELDS:
                nvp_params[str(key.lower())] = value

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(
                nvp_params['timestamp'])

        nvp_obj = PayPalNVP(**nvp_params)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #8
0
    def _fetch(self, params, required, defaults):
        """
        Make the NVP request and store the response.
        
        """
        # ### This function just sucks.
        
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)        
        pp_string = self.signature + urllib.urlencode(pp_params)
        response = urllib.urlopen(self.endpoint, pp_string).read()
        response_params = self._parse_response(response)
        
        print 'Request:'
        pprint.pprint(defaults)
        print '\nResponse:'
        pprint.pprint(response_params)

        # Put fields from NVP into everything so we can pass it to `create`.
        everything = {}
        def into_everything(d):
            for k, v in d.iteritems():
                if k in NVP_FIELDS:
                    everything[k] = v
        
        into_everything(defaults)
        into_everything(response_params)        

        if 'timestamp' in everything:
            everything['timestamp'] = paypaltime2datetime(everything['timestamp'])

        # Record this NVP.
        nvp_obj = PayPalNVP(**everything)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #9
0
    def _fetch(self,
               params,
               required=None,
               defaults=None,
               extra_requirements=None):
        """Make the NVP request and store the response."""
        if required is None or defaults is None:
            assert params['METHOD'] in API_METHODS
            if required is None:
                required = API_METHODS[params['METHOD']].get('required', ())
            if defaults is None:
                defaults = API_METHODS[params['METHOD']].get('defaults', {})
        required += extra_requirements or ()
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)

        if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG):
            print 'PayPal Request:'
            pprint.pprint(defaults)
            print '\nPayPal Response:'
            pprint.pprint(response_params)

        # Gather all NVP parameters to pass to a new instance.
        nvp_params = {}
        merge = {}
        merge.update(defaults)
        merge.update(response_params)
        for key, value in merge.items():
            if key.lower() in NVP_FIELDS:
                nvp_params[str(key.lower())] = value

        # PayPal timestamp has to be formatted.
        if 'timestamp' in nvp_params:
            nvp_params['timestamp'] = paypaltime2datetime(
                nvp_params['timestamp'])

        nvp_obj = PayPalNVP(**nvp_params)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj
Beispiel #10
0
    def _fetch(self, params, required, defaults):
        """
        Make the NVP request and store the response.
        
        """
        defaults.update(params)
        pp_params = self._check_and_update_params(required, defaults)
        pp_string = self.signature + urllib.urlencode(pp_params)
        response = self._request(pp_string)
        response_params = self._parse_response(response)

        print 'PayPal Request:'
        pprint.pprint(defaults)
        print '\nPayPal Response:'
        pprint.pprint(response_params)

        # Put all fields from NVP into everything so we can pass it to `create`.
        everything = {}

        def merge(*dicts):
            for d in dicts:
                for k, v in d.iteritems():
                    if k in NVP_FIELDS:
                        everything[k] = v

        merge(defaults, response_params)

        # PayPal timestamp has to be set correctly to be stored.
        if 'timestamp' in everything:
            everything['timestamp'] = paypaltime2datetime(
                everything['timestamp'])

        nvp_obj = PayPalNVP(**everything)
        nvp_obj.init(self.request, params, response_params)
        nvp_obj.save()
        return nvp_obj