Exemplo n.º 1
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)
Exemplo 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)
Exemplo 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)
 def test_http_query_requests(self):
     http_client = HttpClient(token='a_secret_key',
                              request_handler=RequestsRequest)
     _, status = http_client._request('GET',
                                      routes.API_BASE_URL + '/test',
                                      authenticated=False)
     assert status == 200
Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo n.º 9
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)
Exemplo n.º 10
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))
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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))
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo 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)
Exemplo n.º 20
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)
Exemplo 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)
Exemplo 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))
Exemplo n.º 23
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)
Exemplo 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)
Exemplo n.º 25
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)
Exemplo n.º 26
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)
Exemplo n.º 27
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)
Exemplo 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)
Exemplo n.º 29
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)
Exemplo n.º 30
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)
Exemplo n.º 31
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)
Exemplo n.º 32
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)
Exemplo n.º 33
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))
Exemplo n.º 34
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)
Exemplo n.º 35
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)
Exemplo 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)
Exemplo n.º 37
0
 def test_http_query_requests(self):
     http_client = HttpClient(token='a_secret_key', request_handler=RequestsRequest)
     _, status = http_client._request('GET', routes.API_BASE_URL + '/test', authenticated=False)
     assert status == 200