def authorize(self, username: str, tbk_user: str, parent_buy_order: str,
                  details: MallTransactionAuthorizeDetails):
        ValidationUtil.has_text_with_max_length(username,
                                                ApiConstants.USER_NAME_LENGTH,
                                                "username")
        ValidationUtil.has_text_with_max_length(tbk_user,
                                                ApiConstants.TBK_USER_LENGTH,
                                                "tbk_user")
        ValidationUtil.has_text_with_max_length(parent_buy_order,
                                                ApiConstants.BUY_ORDER_LENGTH,
                                                "parent_buy_order")
        ValidationUtil.has_elements(details.details, "details")

        for item in details.details:
            ValidationUtil.has_text_with_max_length(
                item.commerce_code, ApiConstants.COMMERCE_CODE_LENGTH,
                "details.commerce_code")
            ValidationUtil.has_text_with_max_length(
                item.buy_order, ApiConstants.BUY_ORDER_LENGTH,
                "details.buy_order")
        try:
            endpoint = MallTransaction.AUTHORIZE_ENDPOINT
            request = MallTransactionAuthorizeRequest(username, tbk_user,
                                                      parent_buy_order,
                                                      details.details)
            return RequestService.post(
                endpoint,
                MallTransactionAuthorizeRequestSchema().dumps(request).data,
                self.options)
        except TransbankError as e:
            raise TransactionAuthorizeError(e.message, e.code)
    def create(self, buy_order: str, session_id: str, amount: float, cvv: str,
               card_number: str, card_expiration_date: str):
        ValidationUtil.has_text_with_max_length(buy_order,
                                                ApiConstants.BUY_ORDER_LENGTH,
                                                "buy_order")
        ValidationUtil.has_text_with_max_length(session_id,
                                                ApiConstants.SESSION_ID_LENGTH,
                                                "session_id")
        ValidationUtil.has_text_with_max_length(
            card_number, ApiConstants.CARD_NUMBER_LENGTH, "card_number")
        ValidationUtil.has_text_with_max_length(
            card_expiration_date, ApiConstants.CARD_EXPIRATION_DATE_LENGTH,
            "card_expiration_date")

        try:
            endpoint = Transaction.CREATE_ENDPOINT
            request = TransactionCreateRequest(buy_order, session_id, amount,
                                               card_number, cvv,
                                               card_expiration_date)
            return RequestService.post(
                endpoint,
                TransactionCreateRequestSchema().dumps(request).data,
                self.options)
        except TransbankError as e:
            raise TransactionCreateError(e.message, e.code)
Example #3
0
 def create(self, 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):
     ValidationUtil.has_text_with_max_length(buy_order,
                                             ApiConstants.BUY_ORDER_LENGTH,
                                             "buy_order")
     ValidationUtil.has_text_with_max_length(session_id,
                                             ApiConstants.SESSION_ID_LENGTH,
                                             "session_id")
     ValidationUtil.has_text_with_max_length(return_url,
                                             ApiConstants.RETURN_URL_LENGTH,
                                             "return_url")
     try:
         endpoint = Transaction.CREATE_ENDPOINT
         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)
         return RequestService.post(
             endpoint,
             TransactionCreateRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionCreateError(e.message, e.code)
 def status(self, token: str):
     try:
         endpoint = Inscription.STATUS_ENDPOINT
         request = InscriptionStatusRequest(token)
         return RequestService.post(endpoint, InscriptionStatusRequestSchema().dumps(request).data, self.options)
     except TransbankError as e:
         raise InscriptionStatusError(e.message, e.code)
 def start(self, url: str,
           name: str,
           last_name: str,
           second_last_name: str,
           rut: str,
           service_id: str,
           final_url: str,
           max_amount: float,
           phone: str,
           cell_phone: str,
           patpass_name: str,
           person_email: str,
           commerce_email: str,
           address: str,
           city: str):
     try:
         m_amount = max_amount
         if max_amount == 0:
             m_amount = ''
         endpoint = Inscription.START_ENDPOINT
         request = InscriptionStartRequest(url, name, last_name, second_last_name, rut,
                                       service_id, final_url, self.options.commerce_code, m_amount,
                                       phone, cell_phone, patpass_name, person_email,
                                       commerce_email, address, city)
         return RequestService.post(endpoint, InscriptionStartRequestSchema().dumps(request).data, self.options)
     except TransbankError as e:
         raise InscriptionStartError(e.message, e.code)
Example #6
0
    def create(self, buy_order: str, session_id: str, return_url: str,
               details: MallTransactionCreateDetails):
        ValidationUtil.has_text_with_max_length(buy_order,
                                                ApiConstants.BUY_ORDER_LENGTH,
                                                "buy_order")
        ValidationUtil.has_text_with_max_length(session_id,
                                                ApiConstants.SESSION_ID_LENGTH,
                                                "session_id")
        ValidationUtil.has_text_with_max_length(return_url,
                                                ApiConstants.RETURN_URL_LENGTH,
                                                "return_url")
        ValidationUtil.has_elements(details.details, "details")

        for item in details.details:
            ValidationUtil.has_text_with_max_length(
                item.commerce_code, ApiConstants.COMMERCE_CODE_LENGTH,
                "details.commerce_code")
            ValidationUtil.has_text_with_max_length(
                item.buy_order, ApiConstants.BUY_ORDER_LENGTH,
                "details.buy_order")

        try:
            endpoint = MallTransaction.CREATE_ENDPOINT
            request = MallTransactionCreateRequest(buy_order, session_id,
                                                   return_url, details.details)
            return RequestService.post(
                endpoint,
                MallTransactionCreateRequestSchema().dumps(request).data,
                self.options)
        except TransbankError as e:
            raise TransactionCreateError(e.message, e.code)
Example #7
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)
 def installments(self, token: str, installments_number: int):
     ValidationUtil.has_text_with_max_length(token,
                                             ApiConstants.TOKEN_LENGTH,
                                             "token")
     try:
         endpoint = Transaction.INSTALLMENTS_ENDPOINT.format(token)
         request = TransactionInstallmentsRequest(installments_number)
         return RequestService.post(
             endpoint,
             TransactionInstallmentsRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionInstallmentsError(e.message, e.code)
 def start(self, username: str, email: str, response_url: str):
     ValidationUtil.has_text_trim_with_max_length(
         username, ApiConstants.USER_NAME_LENGTH, "username")
     ValidationUtil.has_text_trim_with_max_length(email,
                                                  ApiConstants.EMAIL_LENGTH,
                                                  "email")
     ValidationUtil.has_text_with_max_length(response_url,
                                             ApiConstants.RETURN_URL_LENGTH,
                                             "response_url")
     try:
         endpoint = MallInscription.START_ENDPOINT
         request = MallInscriptionStartRequest(username, email,
                                               response_url)
         return RequestService.post(
             endpoint,
             MallInscriptionStartRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise InscriptionStartError(e.message, e.code)
 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 #11
0
 def create(self, buy_order: str, session_id: str, amount: float,
            return_url: str):
     ValidationUtil.has_text_with_max_length(buy_order,
                                             ApiConstants.BUY_ORDER_LENGTH,
                                             "buy_order")
     ValidationUtil.has_text_with_max_length(session_id,
                                             ApiConstants.SESSION_ID_LENGTH,
                                             "session_id")
     ValidationUtil.has_text_with_max_length(return_url,
                                             ApiConstants.RETURN_URL_LENGTH,
                                             "return_url")
     try:
         endpoint = Transaction.CREATE_ENDPOINT
         request = TransactionCreateRequest(buy_order, session_id, amount,
                                            return_url)
         return RequestService.post(
             endpoint,
             TransactionCreateRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionCreateError(e.message, e.code)
 def single_installment(self, token: str, installments_number: float,
                        buy_order: str, commerce_code: str):
     ValidationUtil.has_text_with_max_length(token,
                                             ApiConstants.TOKEN_LENGTH,
                                             "token")
     ValidationUtil.has_text_with_max_length(
         commerce_code, ApiConstants.COMMERCE_CODE_LENGTH, "commerce_code")
     ValidationUtil.has_text_with_max_length(buy_order,
                                             ApiConstants.BUY_ORDER_LENGTH,
                                             "buy_order")
     try:
         endpoint = MallTransaction.INSTALLMENTS_ENDPOINT.format(token)
         request = TransactionInstallmentsRequest(
             installments_number=installments_number,
             buy_order=buy_order,
             commerce_code=commerce_code)
         return RequestService.post(
             endpoint,
             TransactionInstallmentsRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionInstallmentsError(e.message, e.code)
 def create(self,
            buy_order: str,
            session_id: str,
            card_number: str,
            card_expiration_date: str,
            details: list,
            cvv: str = None):
     ValidationUtil.has_text_with_max_length(buy_order,
                                             ApiConstants.BUY_ORDER_LENGTH,
                                             "buy_order")
     ValidationUtil.has_text_with_max_length(session_id,
                                             ApiConstants.SESSION_ID_LENGTH,
                                             "session_id")
     ValidationUtil.has_text_with_max_length(
         card_number, ApiConstants.CARD_NUMBER_LENGTH, "card_number")
     ValidationUtil.has_text_with_max_length(
         card_expiration_date, ApiConstants.CARD_EXPIRATION_DATE_LENGTH,
         "card_expiration_date")
     ValidationUtil.has_elements(details, "details")
     for item in details:
         ValidationUtil.has_text_with_max_length(
             item['commerce_code'], ApiConstants.COMMERCE_CODE_LENGTH,
             "details.commerce_code")
         ValidationUtil.has_text_with_max_length(
             item['buy_order'], ApiConstants.BUY_ORDER_LENGTH,
             "details.buy_order")
     try:
         endpoint = MallTransaction.CREATE_ENDPOINT
         request = TransactionCreateRequest(buy_order, session_id,
                                            card_number,
                                            card_expiration_date, details,
                                            cvv)
         return RequestService.post(
             endpoint,
             TransactionCreateRequestSchema().dumps(request).data,
             self.options)
     except TransbankError as e:
         raise TransactionCreateError(e.message, e.code)