def redact( self ):
     '''Redact sensitive information in payment gateway.
     '''
     req = APIRequest(
         self.api, 'gateways/%s/redact.xml' % self.token, 'PUT', '')
     self.from_dict(xml_to_dict(req.xml().find('gateway')))
     return self
    def redact( self ):
        '''
            This will redact a previously retained payment method making it unavailable for any future transactions.
        '''
        req = APIRequest( self.api, 'payment_methods/%s/redact.xml' % self.token, 'PUT', '' )
        self.from_dict( xml_to_dict( req.xml().find( 'payment_method' ) ) )

        return self
 def _update_fields(self, xml_res):
     """
     Updates field with the returned `xml_res`.
     """
     parsed_res = xml_to_dict(xml_res)
     if not self._check_for_errors(parsed_res) and parsed_res.get(self.top_xml_key):
         self.__dict__.update(**parsed_res[self.top_xml_key])
         self._check_semantic_errors(parsed_res)
    def retain( self ):
        '''
            This will store the Payment Method for later use. If a payment method is not retained, you will only be able to use it once.
        '''
        req = APIRequest( self.api, 'payment_methods/%s/retain.xml' % self.token, 'PUT', '' )
        self.from_dict( xml_to_dict( req.xml().find( 'payment_method' ) ) )

        return self
 def _update_fields(self, xml_res):
     """
     Updates field with the returned `xml_res`.
     """
     parsed_res = xml_to_dict(xml_res)
     if not self._check_for_errors(parsed_res) and parsed_res.get(
             self.top_xml_key):
         self.__dict__.update(**parsed_res[self.top_xml_key])
         self._check_semantic_errors(parsed_res)
    def redact(self):
        '''
            This will redact a previously retained payment method making it unavailable for any future transactions.
        '''
        req = APIRequest(self.api,
                         'payment_methods/%s/redact.xml' % self.token, 'PUT',
                         '')
        self.from_dict(xml_to_dict(req.xml().find('payment_method')))

        return self
    def retain(self):
        '''
            This will store the Payment Method for later use. If a payment method is not retained, you will only be able to use it once.
        '''
        req = APIRequest(self.api,
                         'payment_methods/%s/retain.xml' % self.token, 'PUT',
                         '')
        self.from_dict(xml_to_dict(req.xml().find('payment_method')))

        return self
    def to_object(self, cls, target=None):
        '''
            Stores the returned data against an API Object.
            If target is supplied the data will be stored on the supplied object instead of a new one.
            The handlers parameter will be passed on to the xml_to_dict function.
        '''
        result = self.xml()
        if isinstance(result, dict) and 'error' in result:
            d = xml_to_dict(result['et'])
            return {'error': True, 'dict': d}
        else:
            d = xml_to_dict(result)
            if target:
                o = target
            else:
                o = cls.__new__(cls)

            o.api = self.api
            o.from_dict(d)
            return o
    def to_object( self, cls, target = None ):
        '''
            Stores the returned data against an API Object.
            If target is supplied the data will be stored on the supplied object instead of a new one.
            The handlers parameter will be passed on to the xml_to_dict function.
        '''
        result = self.xml()
        if isinstance(result, dict) and 'error' in result:
            d = xml_to_dict(result['et'])
            return {'error':True, 'dict':d}
        else:
            d = xml_to_dict(result)
            if target:
                o = target
            else:
                o = cls.__new__( cls )

            o.api = self.api
            o.from_dict( d )
            return o
    def methods( self ):
        '''Returns a list of available gateways'''
        xml = APIRequest( self, 'payment_methods.xml' ).xml()
        
        if xml.tag == 'payment_methods':
            ret = []
            for elem in xml:
                o = PaymentMethod.__new__( PaymentMethod )
                o.from_dict( xml_to_dict( elem ) )
                o.api = self
                ret.append( o )
            
            return ret

        return []
    def methods(self):
        '''Returns a list of available gateways'''
        xml = APIRequest(self, 'payment_methods.xml').xml()

        if xml.tag == 'payment_methods':
            ret = []
            for elem in xml:
                o = PaymentMethod.__new__(PaymentMethod)
                o.from_dict(xml_to_dict(elem))
                o.api = self
                ret.append(o)

            return ret

        return []
 def to_object( self, cls, target = None ):
     '''
         Stores the returned data against an API Object.
         If target is supplied the data will be stored on the supplied object instead of a new one.
         The handlers parameter will be passed on to the xml_to_dict function.
     '''
     d = xml_to_dict( self.xml())
     
     if target:
         o = target
     else:
         o = cls.__new__( cls )
     
     o.api = self.api
     o.from_dict( d )
     return o
    def add( cls, api, credit_card ):
        '''
        Creates a new Payment Method.
        
        WARNING: Using this method to create payment methods should only be used
        if you are unable to use the standard method outlined in: https://spreedlycore.com/manual/quickstart
        
        The standard method is safer because you do not have to touch the credit
        card data as it is sent straight to spreedly core via the form.
        credit_card is a dictionary with credit card details with the following keys:
        first_name, last_name, number, verification_value, month, year
        Where number is the credit card number and month and year are for
        the expiration date. The year is expressed using 4 digits (ie 2012)
        '''
        d = dict_to_xml( { 'credit_card': credit_card } )
       
        req = APIRequest( api, 'payment_methods.xml', 'POST', data = d )

        o = PaymentMethod.__new__( cls )
        o.from_dict( xml_to_dict( req.xml().find( 'payment_method' ) ) )

        return o
    def transactions(self, since=None):
        ''' Returns a list of 20 transactions.
            Passing a transaction token in the since parameter will return
            20 transactions that occured after the supplied transaction token.
        '''
        url = 'transactions.xml'
        if since:
            url += '?since_token=%s' % since

        xml = APIRequest(self, url).xml()

        if xml.tag == 'transactions':
            ret = []
            for elem in xml:
                o = Transaction.__new__(Transaction)
                o.from_dict(xml_to_dict(elem))
                o.api = self
                ret.append(o)

            return ret

        return []
    def transactions(self, since=None):
        '''
            Will return a list of 20 transactions done using the payment method.
            Passing a transaction token in the since attribute will return 20 transactions that occured after the supplied transaction token.
        '''
        url = 'payment_methods/%s/transactions.xml' % self.token
        if since:
            url += '?since_token=%s' % since

        xml = APIRequest(self.api, url).xml()

        if xml.tag == 'transactions':
            ret = []
            for elem in xml:
                o = Transaction.__new__(Transaction)
                o.__dict__ = xml_to_dict(elem)
                o.api = self
                ret.append(o)

            return ret

        return []
    def add(cls, api, credit_card):
        '''
        Creates a new Payment Method.

        WARNING: Using this method to create payment methods should only be used
        if you are unable to use the standard method outlined in: https://spreedlycore.com/manual/quickstart

        The standard method is safer because you do not have to touch the credit
        card data as it is sent straight to spreedly core via the form.
        credit_card is a dictionary with credit card details with the following keys:
        first_name, last_name, number, verification_value, month, year
        Where number is the credit card number and month and year are for
        the expiration date. The year is expressed using 4 digits (ie 2012)
        '''
        d = dict_to_xml({'credit_card': credit_card})

        req = APIRequest(api, 'payment_methods.xml', 'POST', data=d)

        o = PaymentMethod.__new__(cls)
        o.from_dict(xml_to_dict(req.xml().find('payment_method')))

        return o
    def transactions( self, since = None ):
        ''' Returns a list of 20 transactions.
            Passing a transaction token in the since parameter will return
            20 transactions that occured after the supplied transaction token.
        '''
        url = 'transactions.xml'
        if since:
            url += '?since_token=%s' % since
        
        xml = APIRequest( self, url ).xml()
        
        if xml.tag == 'transactions':
            ret = []
            for elem in xml:
                o = Transaction.__new__( Transaction )
                o.from_dict( xml_to_dict( elem ) )
                o.api = self
                ret.append( o )
            
            return ret

        return []
    def transactions( self, since = None ):
        '''
            Will return a list of 20 transactions done using the payment method.
            Passing a transaction token in the since attribute will return 20 transactions that occured after the supplied transaction token.
        '''
        url = 'payment_methods/%s/transactions.xml' % self.token
        if since:
            url += '?since_token=%s' % since
        
        xml = APIRequest( self.api, url ).xml()
        
        if xml.tag == 'transactions':
            ret = []
            for elem in xml:
                o = Transaction.__new__( Transaction )
                o.__dict__ = xml_to_dict( elem )
                o.api = self
                ret.append( o )
            
            return ret

        return []
        def __init__(self, data):
            self.xml = xml_to_dict(data)

            self.errors = search_dict(self.xml, 'message')
            self.field_errors = search_dict(self.xml, 'error')
 def __init__( self, data ):
     self.xml = xml_to_dict( data )
     
     self.errors = search_dict( self.xml, 'message' )
     self.field_errors = search_dict( self.xml, 'error' )