Esempio n. 1
0
 def test_url_with_format_and_paginator(self):
     url = routes.url('/foo/{val}', pagination={'page': 2, 'per_page': 20}, val='bar')
     assert url.startswith('http://payplug.com/v1/foo/bar?')
     query_params_str = url.split('?')[1]
     query_params = query_params_str.split('&')
     assert 'page=2' in query_params
     assert 'per_page=20' in query_params
Esempio n. 2
0
    def list(customer, per_page=None, page=None):
        """
        List of cards. You have to handle pagination manually for the moment.

        :param customer: the customer id or object
        :type customer: string|Customer
        :param page: the page number
        :type page: int|None
        :param per_page: number of customers per page. It's a good practice to increase this number if you know that you
        will need a lot of payments.
        :type per_page: int|None

        :return A collection of cards
        :rtype resources.APIResourceCollection
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        # Comprehension dict are not supported in Python 2.6-. You can use this commented line instead of the current
        # line when you drop support for Python 2.6.
        # pagination = {key: value for (key, value) in [('page', page), ('per_page', per_page)] if value}
        pagination = dict((key, value) for (key, value) in [('page', page), ('per_page', per_page)] if value)

        http_client = HttpClient()
        response, _ = http_client.get(routes.url(routes.CARD_RESOURCE, customer_id=customer, pagination=pagination))
        return resources.APIResourceCollection(resources.Card, **response)
Esempio n. 3
0
    def list(customer, per_page=None, page=None):
        """
        List of cards. You have to handle pagination manually for the moment.

        :param customer: the customer id or object
        :type customer: string|Customer
        :param page: the page number
        :type page: int|None
        :param per_page: number of customers per page. It's a good practice to increase this number if you know that you
        will need a lot of payments.
        :type per_page: int|None

        :return A collection of cards
        :rtype resources.APIResourceCollection
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        # Comprehension dict are not supported in Python 2.6-. You can use this commented line instead of the current
        # line when you drop support for Python 2.6.
        # pagination = {key: value for (key, value) in [('page', page), ('per_page', per_page)] if value}
        pagination = dict(
            (key, value)
            for (key, value) in [('page', page), ('per_page', per_page)]
            if value)

        http_client = HttpClient()
        response, _ = http_client.get(
            routes.url(routes.CARD_RESOURCE,
                       customer_id=customer,
                       pagination=pagination))
        return resources.APIResourceCollection(resources.Card, **response)
Esempio n. 4
0
    def list(per_page=None, page=None):
        """
        List of payments. You have to handle pagination manually

        :param page: the page number
        :type page: int|None
        :param per_page: number of payment per page. It's a good practice to increase this number if you know that you
        will need a lot of payments.
        :type per_page: int|None

        :return A collection of payment
        :rtype resources.APIResourceCollection
        """
        # Comprehension dict are not supported in Python 2.6-. You can use this commented line instead of the current
        # line when you drop support for Python 2.6.
        # pagination = {key: value for (key, value) in [('page', page), ('per_page', per_page)] if value}
        pagination = dict(
            (key, value)
            for (key, value) in [('page', page), ('per_page', per_page)]
            if value)

        http_client = HttpClient()
        response, _ = http_client.get(
            routes.url(routes.PAYMENT_RESOURCE, pagination=pagination))
        return resources.APIResourceCollection(resources.Payment, **response)
Esempio n. 5
0
 def get_consistent_resource(self):
     """
     :return a payment that you can trust.
     :rtype Payment
     """
     http_client = HttpClient()
     response, _ = http_client.get(routes.url(routes.PAYMENT_RESOURCE, resource_id=self.id))
     return Payment(**response)
Esempio n. 6
0
 def get_consistent_resource(self):
     """
     :return a payment that you can trust.
     :rtype Payment
     """
     http_client = HttpClient()
     response, _ = http_client.get(
         routes.url(routes.PAYMENT_RESOURCE, resource_id=self.id))
     return Payment(**response)
Esempio n. 7
0
 def get_consistent_resource(self):
     """
     :return a refund that you can trust.
     :rtype Refund
     """
     http_client = HttpClient()
     response, _ = http_client.get(
         routes.url(routes.REFUND_RESOURCE, resource_id=self.id, payment_id=self.payment_id)
     )
     return Refund(**response)
Esempio n. 8
0
 def get_consistent_resource(self):
     """
     :return a refund that you can trust.
     :rtype Refund
     """
     http_client = HttpClient()
     response, _ = http_client.get(
         routes.url(routes.REFUND_RESOURCE,
                    resource_id=self.id,
                    payment_id=self.payment_id))
     return Refund(**response)
Esempio n. 9
0
    def create(**data):
        """
        Create a customer.

        :param data: data required to create the customer

        :return: The customer resource
        :rtype resources.Customer
        """
        http_client = HttpClient()
        response, _ = http_client.post(routes.url(routes.CUSTOMER_RESOURCE), data)
        return resources.Customer(**response)
Esempio n. 10
0
    def create(**data):
        """
        Create a Payment request.

        :param data: data required to create the payment

        :return: The payment resource
        :rtype resources.Payment
        """
        http_client = HttpClient()
        response, _ = http_client.post(routes.url(routes.CREATE_PAYMENT), data)
        return resources.Payment(**response)
Esempio n. 11
0
 def test_url_with_format_and_paginator(self):
     url = routes.url('/foo/{val}',
                      pagination={
                          'page': 2,
                          'per_page': 20
                      },
                      val='bar')
     assert url.startswith('http://payplug.com/v1/foo/bar?')
     query_params_str = url.split('?')[1]
     query_params = query_params_str.split('&')
     assert 'page=2' in query_params
     assert 'per_page=20' in query_params
Esempio n. 12
0
    def delete(customer):
        """
        Delete a customer from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        http_client.delete(routes.url(routes.CUSTOMER_RESOURCE, resource_id=customer))
Esempio n. 13
0
    def retrieve(payment_id):
        """
        Retrieve a payment from its id.

        :param payment_id: The payment id
        :type payment_id: string

        :return: The payment resource
        :rtype: resources.Payment
        """
        http_client = HttpClient()
        response, __ = http_client.get(routes.url(routes.RETRIEVE_PAYMENT, payment_id=payment_id))
        return resources.Payment(**response)
Esempio n. 14
0
    def abort(payment_id):
        """
        Abort a payment from its id.

        :param payment_id: The payment id
        :type payment_id: string

        :return: The payment resource
        :rtype: resources.Payment
        """
        http_client = HttpClient()
        response, __ = http_client.patch(routes.url(routes.ABORT_PAYMENT, payment_id=payment_id), {'abort': True})
        return resources.Payment(**response)
Esempio n. 15
0
    def create(**data):
        """
        Create a Payment request.

        :param data: data required to create the payment

        :return: The payment resource
        :rtype resources.Payment
        """
        http_client = HttpClient()
        response, _ = http_client.post(routes.url(routes.PAYMENT_RESOURCE),
                                       data)
        return resources.Payment(**response)
Esempio n. 16
0
    def retrieve(customer_id):
        """
        Retrieve a customer from its id.

        :param customer_id: The customer id
        :type customer_id: string

        :return: The customer resource
        :rtype: resources.Customer
        """
        http_client = HttpClient()
        response, __ = http_client.get(routes.url(routes.CUSTOMER_RESOURCE, resource_id=customer_id))
        return resources.Customer(**response)
Esempio n. 17
0
    def create(**data):
        """
        Create a customer.

        :param data: data required to create the customer

        :return: The customer resource
        :rtype resources.Customer
        """
        http_client = HttpClient()
        response, _ = http_client.post(routes.url(routes.CUSTOMER_RESOURCE),
                                       data)
        return resources.Customer(**response)
Esempio n. 18
0
    def delete(customer):
        """
        Delete a customer from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        http_client.delete(
            routes.url(routes.CUSTOMER_RESOURCE, resource_id=customer))
Esempio n. 19
0
    def retrieve(customer_id):
        """
        Retrieve a customer from its id.

        :param customer_id: The customer id
        :type customer_id: string

        :return: The customer resource
        :rtype: resources.Customer
        """
        http_client = HttpClient()
        response, __ = http_client.get(
            routes.url(routes.CUSTOMER_RESOURCE, resource_id=customer_id))
        return resources.Customer(**response)
Esempio n. 20
0
    def retrieve(payment_id):
        """
        Retrieve a payment from its id.

        :param payment_id: The payment id
        :type payment_id: string

        :return: The payment resource
        :rtype: resources.Payment
        """
        http_client = HttpClient()
        response, __ = http_client.get(
            routes.url(routes.PAYMENT_RESOURCE, resource_id=payment_id))
        return resources.Payment(**response)
Esempio n. 21
0
    def list(payment):
        """
        List all the refunds for a payment.

        :param payment: The payment object or the payment id
        :type payment: resources.Payment|string

        :return: A collection of refunds
        :rtype resources.APIResourceCollection
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, _ = http_client.get(routes.url(routes.LIST_REFUNDS, payment_id=payment))
        return resources.APIResourceCollection(resources.Refund, **response)
Esempio n. 22
0
    def delete(customer, card):
        """
        Delete a card from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        :param card: The card id or object
        :type card: string|Card
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id
        if isinstance(card, resources.Card):
            card = card.id

        http_client = HttpClient()
        http_client.delete(routes.url(routes.CARD_RESOURCE, resource_id=card, customer_id=customer))
Esempio n. 23
0
    def abort(payment):
        """
        Abort a payment from its id.

        :param payment: The payment id or payment object
        :type payment: string|Payment

        :return: The payment resource
        :rtype: resources.Payment
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, __ = http_client.patch(routes.url(routes.PAYMENT_RESOURCE, resource_id=payment), {'abort': True})
        return resources.Payment(**response)
Esempio n. 24
0
    def list(payment):
        """
        List all the refunds for a payment.

        :param payment: The payment object or the payment id
        :type payment: resources.Payment|string

        :return: A collection of refunds
        :rtype resources.APIResourceCollection
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, _ = http_client.get(
            routes.url(routes.REFUND_RESOURCE, payment_id=payment))
        return resources.APIResourceCollection(resources.Refund, **response)
Esempio n. 25
0
    def create(payment, **data):
        """
        Create a refund on a payment.

        :param payment: Either the payment object or the payment id you want to refund.
        :type payment: resources.Payment|string
        :param data: data required to create the refund

        :return: The refund resource
        :rtype resources.Refund
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, _ = http_client.post(routes.url(routes.CREATE_REFUND, payment_id=payment), data)
        return resources.Refund(**response)
Esempio n. 26
0
    def update(customer, **data):
        """
        Update a customer from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        :param data: The data you want to update

        :return: The customer resource
        :rtype resources.Customer
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        response, _ = http_client.patch(routes.url(routes.CUSTOMER_RESOURCE, resource_id=customer), data)
        return resources.Customer(**response)
Esempio n. 27
0
    def create(customer, **data):
        """
        Create a card instance.

        :param customer: the customer id or object
        :type customer: string|Customer
        :param data: data required to create the card

        :return: The card resource
        :rtype resources.Card
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        response, _ = http_client.post(routes.url(routes.CARD_RESOURCE, customer_id=customer), data)
        return resources.Card(**response)
Esempio n. 28
0
    def create(payment, **data):
        """
        Create a refund on a payment.

        :param payment: Either the payment object or the payment id you want to refund.
        :type payment: resources.Payment|string
        :param data: data required to create the refund

        :return: The refund resource
        :rtype resources.Refund
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, _ = http_client.post(
            routes.url(routes.REFUND_RESOURCE, payment_id=payment), data)
        return resources.Refund(**response)
Esempio n. 29
0
    def retrieve(payment, refund_id):
        """
        Retrieve a refund from a payment and the refund id.

        :param payment: The payment id or the payment object
        :type payment: resources.Payment|string
        :param refund_id: The refund id
        :type refund_id: string

        :return: The refund resource
        :rtype: resources.Refund
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, _ = http_client.get(routes.url(routes.RETRIEVE_REFUND, payment_id=payment, refund_id=refund_id))
        return resources.Refund(**response)
Esempio n. 30
0
    def update(customer, **data):
        """
        Update a customer from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        :param data: The data you want to update

        :return: The customer resource
        :rtype resources.Customer
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        response, _ = http_client.patch(
            routes.url(routes.CUSTOMER_RESOURCE, resource_id=customer), data)
        return resources.Customer(**response)
Esempio n. 31
0
    def retrieve(customer, card_id):
        """
        Retrieve a card from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        :param card_id: The card id
        :type card_id: string

        :return: The customer resource
        :rtype: resources.Card
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        response, __ = http_client.get(routes.url(routes.CARD_RESOURCE, resource_id=card_id, customer_id=customer))
        return resources.Card(**response)
Esempio n. 32
0
    def create(customer, **data):
        """
        Create a card instance.

        :param customer: the customer id or object
        :type customer: string|Customer
        :param data: data required to create the card

        :return: The card resource
        :rtype resources.Card
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        response, _ = http_client.post(
            routes.url(routes.CARD_RESOURCE, customer_id=customer), data)
        return resources.Card(**response)
Esempio n. 33
0
    def abort(payment):
        """
        Abort a payment from its id.

        :param payment: The payment id or payment object
        :type payment: string|Payment

        :return: The payment resource
        :rtype: resources.Payment
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, __ = http_client.patch(
            routes.url(routes.PAYMENT_RESOURCE, resource_id=payment),
            {'abort': True})
        return resources.Payment(**response)
Esempio n. 34
0
    def delete(customer, card):
        """
        Delete a card from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        :param card: The card id or object
        :type card: string|Card
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id
        if isinstance(card, resources.Card):
            card = card.id

        http_client = HttpClient()
        http_client.delete(
            routes.url(routes.CARD_RESOURCE,
                       resource_id=card,
                       customer_id=customer))
Esempio n. 35
0
    def retrieve(customer, card_id):
        """
        Retrieve a card from its id.

        :param customer: The customer id or object
        :type customer: string|Customer
        :param card_id: The card id
        :type card_id: string

        :return: The customer resource
        :rtype: resources.Card
        """
        if isinstance(customer, resources.Customer):
            customer = customer.id

        http_client = HttpClient()
        response, __ = http_client.get(
            routes.url(routes.CARD_RESOURCE,
                       resource_id=card_id,
                       customer_id=customer))
        return resources.Card(**response)
Esempio n. 36
0
    def retrieve(payment, refund_id):
        """
        Retrieve a refund from a payment and the refund id.

        :param payment: The payment id or the payment object
        :type payment: resources.Payment|string
        :param refund_id: The refund id
        :type refund_id: string

        :return: The refund resource
        :rtype: resources.Refund
        """
        if isinstance(payment, resources.Payment):
            payment = payment.id

        http_client = HttpClient()
        response, _ = http_client.get(
            routes.url(routes.REFUND_RESOURCE,
                       resource_id=refund_id,
                       payment_id=payment))
        return resources.Refund(**response)
Esempio n. 37
0
    def list(per_page=None, page=None):
        """
        List of payments. You have to handle pagination manually

        :param page: the page number
        :type page: int|None
        :param per_page: number of payment per page. It's a good practice to increase this number if you know that you
        will need a lot of payments.
        :type per_page: int|None

        :return A collection of payment
        :rtype resources.APIResourceCollection
        """
        # Comprehension dict are not supported in Python 2.6-. You can use this commented line instead of the current
        # line when you drop support for Python 2.6.
        # pagination = {key: value for (key, value) in [('page', page), ('per_page', per_page)] if value}
        pagination = dict((key, value) for (key, value) in [('page', page), ('per_page', per_page)] if value)

        http_client = HttpClient()
        response, _ = http_client.get(routes.url(routes.LIST_PAYMENTS, pagination))
        return resources.APIResourceCollection(resources.Payment, **response)
Esempio n. 38
0
 def test_url_paginator_escape(self):
     url = routes.url('/route', pagination={'foo&bar': 'I love Python'})
     query_params_str = url.split('?')[1]
     assert query_params_str == 'foo%26bar=I+love+Python'
Esempio n. 39
0
 def test_url_with_format(self):
     assert routes.url('/foo/{val}', val='bar') == 'http://payplug.com/v1/foo/bar'
     assert routes.url('/payments/{payment_id}', payment_id='112358') == 'http://payplug.com/v1/payments/112358'
Esempio n. 40
0
 def test_url_with_format(self):
     assert routes.url('/foo/{val}',
                       val='bar') == 'http://payplug.com/v1/foo/bar'
     assert routes.url(
         '/payments/{payment_id}',
         payment_id='112358') == 'http://payplug.com/v1/payments/112358'
Esempio n. 41
0
 def test_url_paginator_escape(self):
     url = routes.url('/route', pagination={'foo&bar': 'I love Python'})
     query_params_str = url.split('?')[1]
     assert query_params_str == 'foo%26bar=I+love+Python'
Esempio n. 42
0
 def test_url_without_format(self):
     assert routes.url('/test') == 'http://payplug.com/v1/test'
Esempio n. 43
0
 def test_url_without_format(self):
     assert routes.url('/test') == 'http://payplug.com/v1/test'