Exemplo n.º 1
0
    def execute(cls, payment_token, params=None, api=None):
        api = api or default_api()
        params = params or {}

        url = util.join_url(cls.path, payment_token, "agreement-execute")

        return Resource(api.post(url, params), api=api)
Exemplo n.º 2
0
    def search(cls, params=None, api=None):
        api = api or default_api()
        params = params or {}

        url = util.join_url(cls.path, 'search')

        return Resource(api.post(url, params), api=api)
Exemplo n.º 3
0
    def find(cls, resource_id, api=None):
        """Locate resource e.g. payment with given id

        Usage::
            >>> payment = Payment.find("PAY-1234")
        """
        api = api or default_api()

        url = util.join_url(cls.path, str(resource_id))
        return cls(api.get(url), api=api)
Exemplo n.º 4
0
    def __init__(self, attributes=None, api=None):
        attributes = attributes or {}
        self.__dict__['api'] = api or default_api()

        super(Resource, self).__setattr__('__data__', {})
        super(Resource, self).__setattr__('error', None)
        super(Resource, self).__setattr__('headers', {})
        super(Resource, self).__setattr__('header', {})
        super(Resource, self).__setattr__('request_id', None)
        self.merge(attributes)
Exemplo n.º 5
0
    def get_qr_code(self, height=500, width=500, api=None):

        # height and width have default value of 500 as in the APIs
        api = api or default_api()

        # Construct url similar to
        # /invoicing/invoices/<INVOICE-ID>/qr-code?height=<HEIGHT>&width=<WIDTH>
        endpoint = util.join_url(self.path, str(self['id']), 'qr-code')
        image_attributes = [('height', height), ('width', width)]
        url = util.join_url_params(endpoint, image_attributes)

        return Resource(self.api.get(url), api=api)
Exemplo n.º 6
0
    def search_transactions(self, start_date, end_date, api=None):
        if not start_date or not end_date:
            raise exceptions.MissingParam("Search transactions needs valid start_date and end_date.")
        api = api or default_api()

        # Construct url similar to
        # /billing-agreements/I-HT38K76XPMGJ/transactions?start-date=2014-04-13&end-date=2014-04-30
        endpoint = util.join_url(self.path, str(self["id"]), "transactions")
        date_range = [("start_date", start_date), ("end_date", end_date)]
        url = util.join_url_params(endpoint, date_range)

        return Resource(self.api.get(url), api=api)
Exemplo n.º 7
0
 def test_create_with_refresh_token(self):
     Base.post.side_effect = paypal.ResourceNotFound('', '')
     self.assertRaises(paypal.ResourceNotFound,
                       Tokeninfo.create_with_refresh_token, "invalid-token")
     Base.post.assert_called_once_with(
         'v1/identity/openidconnect/tokenservice', {
             'client_secret': client_secret,
             'grant_type': 'refresh_token',
             'refresh_token': 'invalid-token',
             'client_id': client_id
         },
         api=default_api())
Exemplo n.º 8
0
    def create(cls, options=None, api=None):
        options = options or {}
        api = api or default_api()
        if isinstance(options, string_types):
            options = {'code': options}

        options = util.merge_dict({
            'grant_type': 'authorization_code',
            'client_id': client_id(api),
            'client_secret': client_secret(api)
        }, options)
        return cls.post(cls.path, options, api=api)
Exemplo n.º 9
0
    def search_transactions(self, start_date, end_date, api=None):
        if not start_date or not end_date:
            raise exceptions.MissingParam("Search transactions needs valid start_date and end_date.")
        api = api or default_api()

        # Construct url similar to
        # /billing-agreements/I-HT38K76XPMGJ/transactions?start-date=2014-04-13&end-date=2014-04-30
        endpoint = util.join_url(self.path, str(self['id']), 'transactions')
        date_range = [('start_date', start_date), ('end_date', end_date)]
        url = util.join_url_params(endpoint, date_range)

        return Resource(self.api.get(url), api=api)
Exemplo n.º 10
0
    def get_qr_code(self, height=500, width=500, api=None):

        # height and width have default value of 500 as in the APIs
        api = api or default_api()

        # Construct url similar to
        # /invoicing/invoices/<INVOICE-ID>/qr-code?height=<HEIGHT>&width=<WIDTH>
        endpoint = util.join_url(self.path, str(self['id']), 'qr-code')
        image_attributes = [('height', height), ('width', width)]
        url = util.join_url_params(endpoint, image_attributes)

        return Resource(self.api.get(url), api=api)
Exemplo n.º 11
0
    def all(cls, params=None, api=None):
        """Get list of payments as on
        https://developer.paypal.com/docs/api/#list-payment-resources

        Usage::
            
            >>> payment_histroy = Payment.all({'count': 2})
        """
        api = api or default_api()

        if params is None:
            url = cls.path
        else:
            url = util.join_url_params(cls.path, params)
        return cls.list_class(api.get(url), api=api)
Exemplo n.º 12
0
    def all(cls, params=None, api=None):
        """Get list of payments as on
        https://developer.paypal.com/docs/api/#list-payment-resources

        Usage::

            >>> payment_histroy = Payment.all({'count': 2})
        """
        api = api or default_api()

        if params is None:
            url = cls.path
        else:
            url = util.join_url_params(cls.path, params)
        return cls.list_class(api.get(url), api=api)
Exemplo n.º 13
0
    def all(cls, params=None, api=None):
        """Get list of payments as on
        https://developer.paypal.com/docs/api/#list-payment-resources

        Usage::

            >>> payment_history = Payment.all({'count': 2})
        """
        api = api or default_api()

        if params is None:
            url = cls.path
        else:
            url = util.join_url_params(cls.path, params)

        try:
            response = api.get(url)
            return cls.list_class(response, api=api)
        except AttributeError:
            # To handle the case when response is JSON Array
            if isinstance(response, list):
                new_resp = [cls.list_class(elem, api=api) for elem in response]
                return new_resp
Exemplo n.º 14
0
    def all(cls, params=None, api=None):
        """Get list of payments as on
        https://developer.paypal.com/docs/api/#list-payment-resources

        Usage::

            >>> payment_histroy = Payment.all({'count': 2})
        """
        api = api or default_api()

        if params is None:
            url = cls.path
        else:
            url = util.join_url_params(cls.path, params)

        try:
            response = api.get(url)
            return cls.list_class(response, api=api)
        except AttributeError:
            # To handle the case when response is JSON Array
            if isinstance(response, list):
                new_resp = [cls.list_class(elem) for elem in response]
                return new_resp
Exemplo n.º 15
0
 def next_invoice_number(cls, api=None):
     api = api or default_api()
     url = util.join_url(cls.path, 'next-invoice-number')
     return Resource(api.post(url), api=api)
Exemplo n.º 16
0
 def get_event_types(self, api=None):
     """Get the list of events types that are subscribed to a webhook
     """
     api = api or default_api()
     url = util.join_url(self.path, str(self['id']), 'event-types')
     return Resource(self.api.get(url), api=api)
 def get_event_types(self, api=None):
     """Get the list of events types that are subscribed to a webhook
     """
     api = api or default_api()
     url = util.join_url(self.path, str(self['id']), 'event-types')
     return Resource(self.api.get(url), api=api)
Exemplo n.º 18
0
def client_id(api=None):
    api = api or default_api()
    return api.options.get("openid_client_id", api.client_id)
Exemplo n.º 19
0
def endpoint(api=None):
    api = api or default_api()
    return api.options.get("openid_endpoint", api.endpoint)
Exemplo n.º 20
0
def redirect_uri(api=None):
    api = api or default_api()
    return api.options.get("openid_redirect_uri")