示例#1
0
    async def delete_saved_card_by_token(self, token: str) -> dict:
        url_path = f'/api/cards/{token}/'
        url = self.prepare_url(url_path)

        async with API(url=url) as api:
            response = await api.delete(headers=self._headers)
            return response
示例#2
0
    async def withdraw_payment(self, reference: int, amount: int):
        url_path = '/api/payments/withdraw/'
        url = self.prepare_url(url_path)
        data = {
            'reference': reference,
            'amount': amount
        }

        async with API(url=url) as api:
            response = await api.post(data=data, headers=self._headers)
            return response
示例#3
0
    async def get_payment_status(self, reference: int):
        url_path = f'/api/payments/{reference}/status/'
        url = self.prepare_url(url_path)

        async with API(url=url) as api:
            response = await api.get(headers=self._headers)
            try:
                model = schemas.Payment(**response)
                return model
            except ValidationError as e:
                return e.json()
示例#4
0
 async def get_client_saved_cards(self, client_id: int):
     url_path = '/api/cards/'
     params = {
         'client_id': client_id,
     }
     url = self.prepare_url(url_path, params=params)
     async with API(url=url) as api:
         response = await api.get(headers=self._headers)
         try:
             models = parse_obj_as(List[schemas.SavedCard], response)
             return models
         except ValidationError as e:
             return e.json()
示例#5
0
    async def cancel_payment(self, reference: int):
        url_path = '/api/payments/cancel/'
        url = self.prepare_url(url_path)
        data = {
            'reference': reference
        }

        async with API(url=url) as api:
            response = await api.post(data=data, headers=self._headers)
            try:
                model = schemas.Response(**response)
                return model
            except ValidationError as e:
                return e.json()
示例#6
0
    async def change_payment_amount(self, reference: int, amount: int):
        url_path = f'/api/payments/{reference}/amount/'
        url = self.prepare_url(url_path)
        data = {
            'amount': amount
        }

        async with API(url=url) as api:
            try:
                response = await api.put(data=data, headers=self._headers)
                return response
            except JSONDecodeError as e:
                # TODO: Need discussing
                return {'status': '204 No Content'}
示例#7
0
    async def get_client_saved_card_by_token(self, token: str, client_id: int):
        url_path = f'/api/cards/{token}/'
        params = {
            'client_id': client_id
        }
        url = self.prepare_url(url_path, params=params)

        async with API(url=url) as api:
            response = await api.get(headers=self._headers)
            try:
                model = schemas.SavedCard(**response)
                return model
            except ValidationError as e:
                return e.json()
示例#8
0
    async def register_payment(self, payment: schemas.AbstractPayment):
        url_path = '/api/payments/register/'
        url = self.prepare_url(url_path)
        data = payment.dict()

        async with API(url=url) as api:
            response = await api.post(data=data, headers=self._headers)
            try:
                # TODO: error handling
                if 'detail' in response:
                    return response
                model = schemas.RegisterPaymentResponse(**response)
                return model
            except ValidationError as e:
                return e.json()
示例#9
0
    async def refund_payment(self, reference: int, amount: int, reason: str = None):
        url_path = '/api/payments/refund/'
        url = self.prepare_url(url_path)
        data = {
            'reference': reference,
            'amount': amount,
            'reason': reason
        }

        async with API(url=url) as api:
            response = await api.post(data=data, headers=self._headers)
            try:
                model = schemas.Response(**response)
                return model
            except ValidationError as e:
                return e.json()