Example #1
0
    def refund(cls,
               token: str,
               amount: float,
               child_buy_order: str,
               child_commerce_code: str,
               options: Options = None):
        options = cls.build_options(options)
        endpoint = "{}/{}/refunds".format(
            cls.__base_url(options.integration_type), token)

        request = MallTransactionRefundRequest(
            commerce_code=child_commerce_code,
            buy_order=child_buy_order,
            amount=amount)
        response = requests.post(
            url=endpoint,
            headers=HeadersBuilder.build(options),
            data=MallTransactionRefundRequestSchema().dumps(request).data)

        json_response = response.text
        dict_response = TransactionRefundResponseSchema().loads(
            json_response).data

        if response.status_code not in range(200, 299):
            raise TransactionRefundError(
                message=dict_response["error_message"],
                code=response.status_code)

        return TransactionRefundResponse(**dict_response)
Example #2
0
 def refund(self, token: str, amount: float):
     ValidationUtil.has_text_with_max_length(token,
                                             ApiConstants.TOKEN_LENGTH,
                                             "token")
     try:
         endpoint = Transaction.REFUND_ENDPOINT.format(token)
         request = TransactionRefundRequest(amount)
         return RequestService.post(
             endpoint,
             TransactionRefundRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionRefundError(e.message, e.code)
Example #3
0
 def refund(cls, token: str, amount: str, options: Options = None):
     options = cls.build_options(options)
     endpoint = '{}/{}/refunds'.format(
         cls.__base_url(options.integration_type), token)
     request = TransactionRefundRequest(amount=amount)
     response = requests.post(
         endpoint,
         data=RefundTransactionRequestSchema().dumps(request).data,
         headers=HeadersBuilder.build(options))
     response_json = response.text
     response_dict = RefundTransactionResponseSchema().loads(
         response_json).data
     if response.status_code in range(200, 299):
         return TransactionRefundResponse(**response_dict)
     raise TransactionRefundError(message=response_dict["error_message"])
 def refund(self, buy_order: str, child_commerce_code: str,
            child_buy_order: str, amount: float):
     ValidationUtil.has_text_with_max_length(
         child_commerce_code, ApiConstants.COMMERCE_CODE_LENGTH,
         "child_commerce_code")
     ValidationUtil.has_text_with_max_length(buy_order,
                                             ApiConstants.BUY_ORDER_LENGTH,
                                             "buy_order")
     ValidationUtil.has_text_with_max_length(child_buy_order,
                                             ApiConstants.BUY_ORDER_LENGTH,
                                             "child_buy_order")
     try:
         endpoint = MallTransaction.REFUND_ENDPOINT.format(buy_order)
         request = MallTransactionRefundRequest(child_commerce_code,
                                                child_buy_order, amount)
         return RequestService.post(
             endpoint,
             MallTransactionRefundRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionRefundError(e.message, e.code)
Example #5
0
    def refund(cls,
               buy_order: str,
               child_commerce_code: str,
               child_buy_order: str,
               amount: float,
               options: Options = None) -> TransactionRefundResponse:
        options = cls.build_options(options)
        endpoint = '{}/{}/{}/refunds'.format(
            cls.__base_url(options.integration_type), 'transactions',
            buy_order)
        request = TransactionRefundRequest(child_commerce_code,
                                           child_buy_order, amount)
        response = requests.post(
            endpoint,
            data=TransactionRefundRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        response_json = response.text
        response_dict = TransactionRefundResponseSchema().loads(
            response_json).data
        if response.status_code not in range(200, 299):
            raise TransactionRefundError(
                message=response_dict["error_message"])

        return TransactionRefundResponse(**response_dict)