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
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 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 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)
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)
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)
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)
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)
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)
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)
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
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))
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)
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)
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)
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)
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))
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)
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)
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)
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))
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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))
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)
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)
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)
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'
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'
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'
def test_url_without_format(self): assert routes.url('/test') == 'http://payplug.com/v1/test'