Example #1
0
    def instance_url(self):
        self.id = utf8(self.id)
        self.customer = utf8(getattr(self, 'customer', self.customer_id))
        extn = quote_plus(self.id)

        return "%s/%s/subscriptions/%s" % (Customer.class_url(), self.customer,
                                           extn)
Example #2
0
    def __repr__(self):
        ident_parts = [type(self).__name__]

        if isinstance(self.get('object'), str):
            ident_parts.append(utf8(self.get('object')))

        if isinstance(self.get('id'), str):
            ident_parts.append('id=%s' % utf8(self.get('id')))

        return '<%s at %s> JSON: %s' % (' '.join(ident_parts), hex(
            id(self)), str(self))
Example #3
0
    def instance_url(self):
        self.id = utf8(self.id)
        if hasattr(self, 'customer'):
            self.customer = utf8(self.customer)
        else:
            self.customer = utf8(self.customer_id)

        base = Customer.class_url()
        cust_extn = self.customer
        extn = quote_plus(self.id)

        return "%s/%s/bankaccounts/%s" % (base, cust_extn, extn)
Example #4
0
    def instance_url(self):
        self.id = utf8(self.id)

        if getattr(self, '_as_merchant', False):
            extn = quote_plus(self.id)
            url = "{0}/{1}".format(Charge.class_url(), extn)
        else:
            self.customer = utf8(self.customer_id)
            extn = quote_plus(self.id)
            url = "%s/%s/charges/%s" % (Customer.class_url(), self.customer,
                                        extn)

        return url
Example #5
0
    def retrieve(self, id, **params):
        base = self.get('url')
        id = utf8(id)
        extn = quote_plus(id)
        url = "%s/%s" % (base, extn)

        return self.request('get', url, params)
Example #6
0
 def retrieve_as_merchant(cls, id):
     params = {}
     api_key = getattr(cls, 'api_key', varopago.api_key)
     cls._as_merchant = True
     requestor = api.APIClient(api_key)
     uid = utf8(id)
     url = "%s/%s" % (cls.class_url(), quote_plus(uid))
     response, api_key = requestor.request('get', url, params)
     return convert_to_varopago_object(response, api_key, 'charge')
Example #7
0
def _api_encode(data):
    for key, value in data.iteritems():
        key = util.utf8(key)
        if value is None:
            continue
        elif hasattr(value, 'varopago_id'):
            yield (key, value.varopago_id)
        elif isinstance(value, list) or isinstance(value, tuple):
            for subvalue in value:
                yield ("%s[]" % (key, ), util.utf8(subvalue))
        elif isinstance(value, dict):
            subdict = dict(('%s[%s]' % (key, subkey), subvalue)
                           for subkey, subvalue in value.iteritems())
            for subkey, subvalue in _api_encode(subdict):
                yield (subkey, subvalue)
        elif isinstance(value, datetime.datetime):
            yield (key, _encode_datetime(value))
        else:
            yield (key, util.utf8(value))
Example #8
0
    def instance_url(self):
        id = self.get('id')
        if not id:
            raise error.InvalidRequestError(
                'Could not determine which URL to request: %s instance '
                'has invalid ID: %r' % (type(self).__name__, id), 'id')
        id = utf8(id)
        params = None
        if 'customer' in list(self._retrieve_params.keys()):
            params = {'customer': self._retrieve_params.get('customer')}

        base = self.class_url(params)
        extn = quote_plus(id)
        return "%s/%s" % (base, extn)