예제 #1
0
    def capture(cls,
                token: str,
                buy_order: str,
                authorization_code: str,
                capture_amount: float,
                options: Options = None):
        options = cls.build_options(options)
        endpoint = "{}/{}/capture".format(
            cls.__base_url(options.integration_type), token)
        request = DeferredTransactionRequest(buy_order, authorization_code,
                                             capture_amount)

        response = requests.put(
            url=endpoint,
            headers=HeadersBuilder.build(options),
            data=DeferredTransactionRequestSchema().dumps(request).data)
        json_response = response.text
        dict_response = DeferredTransactionResponseSchema().loads(
            json_response).data

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

        return DeferredTransactionResponse(**dict_response)
예제 #2
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)
예제 #3
0
 def single_installment(cls, endpoint, options, installments_number: float,
                        buy_order: str, commerce_code: str):
     request = TransactionInstallmentsRequest(
         installments_number=installments_number,
         buy_order=buy_order,
         commerce_code=commerce_code)
     response = requests.post(
         endpoint,
         data=InstallmentsTransactionRequestSchema().dumps(request).data,
         headers=HeadersBuilder.build(options))
     return response
예제 #4
0
 def status(cls, token: str, options: Options = None):
     options = cls.build_options(options)
     endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                               token)
     request = TransactionStatusRequest(token=token)
     response = requests.get(endpoint,
                             headers=HeadersBuilder.build(options))
     response_json = response.text
     response_dict = CommitTransactionResponseSchema().loads(
         response_json).data
     if response.status_code in range(200, 299):
         return TransactionStatusResponse(**response_dict)
     raise TransactionStatusError(message=response_dict["error_message"])
예제 #5
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"])
예제 #6
0
 def commit(cls, token: str, details: list, options: Options = None):
     options = cls.build_options(options)
     endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                               token)
     request = TransactionCommitRequest(details=details)
     response = requests.put(
         endpoint,
         data=CommitTransactionRequestSchema().dumps(request).data,
         headers=HeadersBuilder.build(options))
     response_json = response.text
     response_dict = CommitTransactionResponseSchema().loads(
         response_json).data
     if response.status_code in range(200, 299):
         return TransactionCommitResponse(**response_dict)
     raise TransactionCommitError(message=response_dict["error_message"])
예제 #7
0
    def delete(cls, tbk_user: str, user_name: str, options: Options = None):
        options = cls.build_options(options)
        endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                                  'inscriptions')

        request = InscriptionDeleteRequest(user_name, tbk_user)
        data = InscriptionDeleteRequestSchema().dumps(request).data

        response = requests.delete(url=endpoint,
                                   data=data,
                                   headers=HeadersBuilder.build(options))

        if response.status_code not in range(200, 299):
            raise InscriptionDeleteError(
                message="Delete could not be performed",
                code=response.status_code)
예제 #8
0
    def status(cls, token: str, options: Options = None):
        options = cls.build_options(options)
        endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                                  token)

        response = requests.get(url=endpoint,
                                headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = TransactionStatusResponseSchema().loads(
            json_response).data

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

        return TransactionStatusResponse(**dict_response)
예제 #9
0
    def finish(cls,
               token: str,
               options: Options = None) -> InscriptionFinishResponse:
        options = cls.build_options(options)
        endpoint = '{}/{}/{}'.format(cls.__base_url(options.integration_type),
                                     'inscriptions', token)

        response = requests.put(url=endpoint,
                                headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = InscriptionFinishResponseSchema().loads(
            json_response).data
        if response.status_code not in range(200, 299):
            raise InscriptionFinishError(
                message=dict_response["error_message"],
                code=response.status_code)

        return InscriptionFinishResponse(**dict_response)
예제 #10
0
    def start(cls,
              url: str,
              name: str,
              first_last_name: str,
              second_last_name: str,
              rut: str,
              service_id: str,
              final_url: str,
              max_amount: float,
              phone_number: str,
              mobile_number: str,
              patpass_name: str,
              person_email: str,
              commerce_email: str,
              address: str,
              city: str,
              options: Options = None) -> InscriptionStartResponse:
        options = cls.build_options(options)
        endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                                  'patInscription')
        m_amount = max_amount
        if max_amount == 0:
            m_amount = ''

        request = InscriptionStartRequest(
            url, name, first_last_name, second_last_name, rut, service_id,
            final_url, options.commerce_code, m_amount, phone_number,
            mobile_number, patpass_name, person_email, commerce_email, address,
            city)

        response = requests.post(
            endpoint,
            data=InscriptionStartRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = InscriptionStartResponseSchema().loads(
            json_response).data
        if response.status_code not in range(200, 299):
            raise InscriptionStartError(message=dict_response["description"],
                                        code=response.status_code)

        return InscriptionStartResponse(**dict_response)
예제 #11
0
 def create(cls,
            buy_order: str,
            session_id: str,
            card_number: str,
            card_expiration_date: str,
            details: list,
            options: Options = None) -> TransactionCreateResponse:
     options = cls.build_options(options)
     endpoint = cls.__base_url(options.integration_type)
     request = TransactionCreateRequest(buy_order, session_id, card_number,
                                        card_expiration_date, details)
     response = requests.post(
         endpoint,
         data=CreateTransactionRequestSchema().dumps(request).data,
         headers=HeadersBuilder.build(options))
     response_json = response.text
     response_dict = CreateTransactionResponseSchema().loads(
         response_json).data
     if response.status_code in range(200, 299):
         return TransactionCreateResponse(**response_dict)
     raise TransactionCreateError(message=response_dict["error_message"])
예제 #12
0
    def create(cls, buy_order: str, session_id: str, amount: float, return_url: str, options: Options = None) \
            -> TransactionCreateResponse:
        options = cls.build_options(options)
        endpoint = cls.__base_url(options.integration_type)
        request = TransactionCreateRequest(buy_order, session_id, amount,
                                           return_url)

        response = requests.post(
            endpoint,
            data=TransactionCreateRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = TransactionCreateResponseSchema().loads(
            json_response).data

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

        return TransactionCreateResponse(**dict_response)
예제 #13
0
    def installments(cls,
                     token: str,
                     installments_number: float,
                     options: Options = None):
        options = cls.build_options(options)
        endpoint = '{}/{}/installments'.format(
            cls.__base_url(options.integration_type), token)

        request = TransactionInstallmentsRequest(
            installments_number=installments_number)
        response = requests.post(
            endpoint,
            data=InstallmentsTransactionRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        response_json = response.text
        response_dict = InstallmentsTransactionResponseSchema().loads(
            response_json).data
        if response.status_code in range(200, 299):
            return TransactionInstallmentsResponse(**response_dict)
        raise TransactionInstallmentsError(
            message=response_dict["error_message"])
예제 #14
0
    def status(cls,
               token: str,
               options: Options = None) -> InscriptionStatusResponse:
        options = cls.build_options(options)
        endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                                  'status')

        request = InscriptionStatusRequest(token)

        response = requests.post(
            url=endpoint,
            data=InscriptionStatusRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = InscriptionStatusResponseSchema().loads(
            json_response).data
        if response.status_code not in range(200, 299):
            raise InscriptionStatusError(message=dict_response["description"],
                                         code=response.status_code)

        return InscriptionStatusResponse(**dict_response)
예제 #15
0
    def create(cls,
               buy_order: str,
               session_id: str,
               amount: float,
               return_url: str,
               service_id: str,
               card_holder_id: str,
               card_holder_name: str,
               card_holder_last_name1: str,
               card_holder_last_name2: str,
               card_holder_mail: str,
               cellphone_number: str,
               expiration_date: str,
               commerce_mail: str,
               uf_flag: bool,
               options: Options = None) -> TransactionCreateResponse:
        options = cls.build_options(options)
        endpoint = cls.__base_url(options.integration_type)
        request = TransactionCreateRequest(
            buy_order, session_id, amount, return_url, service_id,
            card_holder_id, card_holder_name, card_holder_last_name1,
            card_holder_last_name2, card_holder_mail, cellphone_number,
            expiration_date, commerce_mail, uf_flag)

        response = requests.post(
            endpoint,
            data=TransactionCreateRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = TransactionCreateResponseSchema().loads(
            json_response).data

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

        return TransactionCreateResponse(**dict_response)
예제 #16
0
    def start(cls,
              user_name: str,
              email: str,
              response_url: str,
              options: Options = None) -> InscriptionStartResponse:
        options = cls.build_options(options)
        endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                                  'inscriptions')

        request = InscriptionStartRequest(user_name, email, response_url)

        response = requests.post(
            endpoint,
            data=InscriptionStartRequestSchema().dumps(request).data,
            headers=HeadersBuilder.build(options))
        json_response = response.text
        dict_response = InscriptionStartResponseSchema().loads(
            json_response).data
        if response.status_code not in range(200, 299):
            raise InscriptionStartError(message=dict_response["error_message"],
                                        code=response.status_code)

        return InscriptionStartResponse(**dict_response)
예제 #17
0
    def authorize(cls,
                  user_name: str,
                  tbk_user: str,
                  buy_order: str,
                  details: MallTransactionAuthorizeDetails,
                  options: Options = None) -> TransactionAuthorizeResponse:
        options = cls.build_options(options)
        endpoint = '{}/{}'.format(cls.__base_url(options.integration_type),
                                  'transactions')
        request = TransactionAuthorizeRequest(user_name, tbk_user, buy_order,
                                              details.details)

        data = TransactionAuthorizeRequestSchema().dumps(request).data
        response = requests.post(endpoint,
                                 data,
                                 headers=HeadersBuilder.build(options))
        response_json = response.text
        response_dict = TransactionAuthorizeResponseSchema().loads(
            response_json).data
        if response.status_code not in range(200, 299):
            raise TransactionAuthorizeError(
                message=response_dict["error_message"])

        return TransactionAuthorizeResponse(**response_dict)
예제 #18
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)
 def get(cls, endpoint: str, options: Options):
     endpoint = "{}{}".format(cls.host(options), endpoint)
     response = requests.get(url=endpoint, headers=HeadersBuilder.build(options))
     return cls.process_response(response)