Example #1
0
    def auth_capture(self, body):
        """POST Request

        Args:
            body: An object containing the fields to
                POST for the request.  See the corresponding object definition
                for field details.
        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success
        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.
        """

        # Prepare query URL
        _url_path = constant.AUTH_CAPTURE
        _query_builder = self.config.get_base_uri()
        _query_url = _query_builder + _url_path

        # Parameters validation
        outAuthInfoNo = body.get('outAuthInfoNo')
        authInfoNo = body.get('authInfoNo')
        if (outAuthInfoNo and authInfoNo and
            (body['outAuthInfoNo'] and body['authInfoNo']) is None) or (
                not outAuthInfoNo and not authInfoNo):
            raise InvalidParamsError(
                "outAuthInfoNo and authInfoNo cannot be null at the same time")

        if outAuthInfoNo and authInfoNo and (body['outAuthInfoNo'] and
                                             body['authInfoNo']) is not None:
            raise InvalidParamsError(
                "outAuthInfoNo and authInfoNo cannot exist at the same time")

        requiredFileds = [
            'currency', 'settleCurrency', 'outAuthDetailNo', 'reference'
        ]
        self.validate_parameter(requiredFileds, body)

        self.amount_validate('amount', body['amount'])

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url,
                                                headers=None,
                                                parameters=body)
        _response = self.execute_request(_request)

        if type(_response.response) is not dict:
            _errors = _response.reason
        else:
            _errors = None
        _result = ApiResponse(_response,
                              body=_response.response,
                              errors=_errors)
        return _result
Example #2
0
    def reverse(self, body):
        """POST Request to reverse transaction
        Reverse Yuansfer transaction
        Args:
            body: An object containing the fields to
                POST for the request.  See the corresponding object definition
                for field details.
        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success
        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.
        """

        # Prepare query URL
        _url_path = constant.REVERSE
        _query_builder = self.config.get_base_uri()
        _query_url = _query_builder + _url_path

        # Parameters validation
        transcationNo = body.get('transactionNo')
        reference = body.get('reference')
        if (transcationNo and reference and
            (body['transactionNo'] and body['reference']) is None) or (
                not transcationNo and not reference):
            raise InvalidParamsError(
                "transaction and reference cannot be null at the same time")

        if transcationNo and reference and (body['transactionNo']
                                            and body['reference']) is not None:
            raise InvalidParamsError(
                "transaction and reference cannot exist at the same time")

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url,
                                                headers=None,
                                                parameters=body)
        _response = self.execute_request(_request)

        if type(_response.response) is not dict:
            _errors = _response.reason
        else:
            _errors = None
        _result = ApiResponse(_response,
                              body=_response.response,
                              errors=_errors)
        return _result
Example #3
0
    def amount_validate(self, name, value):
        # Check if amount exists
        if value is None:
            raise RequireParamsError(params=name)

        reg = r"(?=.*?\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|\d+)?(\.\d{1,2})?$"

        if not re.match(reg, value):
            raise InvalidParamsError("data error: " + name)
Example #4
0
    def number_validate(self, name, value):
        # Check if number exists
        if value is None:
            raise RequireParamsError(params=name)

        reg = r"^[0-9]*[1-9][0-9]*$"

        if not re.match(reg, value):
            raise InvalidParamsError("data error: " + name)
Example #5
0
    def date_validate(self, name, value):
        # Check if date exists
        if value is None:
            raise RequireParamsError(params=name)

        reg = r"^\\d{4}\\d{2}\\d{2}$"

        if not re.match(reg, value):
            raise InvalidParamsError("data error: " + name)
Example #6
0
 def __init__(self,
              timeout=60,
              max_retries=3,
              merchantNo=None,
              environment='production',
              storeNo=None,
              token=None):
     if (merchantNo or storeNo or token) is None:
         raise InvalidParamsError('Configs are missing')
     else:
         self.config = Configuration(timeout=timeout,
                                     max_retries=max_retries,
                                     environment=environment,
                                     merchantNo=merchantNo,
                                     storeNo=storeNo,
                                     token=token)
    def append_parameters(parameters):
        """Conconcate parameters
        Args:
            parameters (OrderedDict): The parameters to append.
        Returns:
            str: string with appended parameters.
        """
        # Parameter validation
        if parameters is None:
            raise InvalidParamsError('Parameters are missing')

        queryString = ""

        # Loop through all parameters and concatenate the parameter names and values using '=' and '&' character
        for key, value in parameters.items():
            seperator = '&'
            if value is not None:
                queryString += "{0}{1}={2}".format(seperator, key, str(value))
        queryString = queryString[1:]
        return queryString
Example #8
0
    def verify_sign_method(self, parameters):
        """Convert object to request params
        Args:
            parameters (object): The parameters to convert.
        Returns:
            str: string with appended parameters.
        """
        # Parameter validation
        if self.config is None:
            raise InvalidParamsError('Configs are missing')

        parameters['merchantNo'] = self.config.merchantNo
        parameters['storeNo'] = self.config.storeNo
        dictionaryParams = APIHelper.to_dictionary(parameters)
        stringParams = APIHelper.append_parameters(dictionaryParams)
        md5TokenStr = hashlib.md5(
            self.config.token.encode("utf-8")).hexdigest()
        res = hashlib.md5(
            (stringParams + '&' + md5TokenStr).encode("utf-8")).hexdigest()

        return res
Example #9
0
    def update_recurring(self,
                  body):
        """POST Request to UpdateRecurring payment
        Process a UpdateRecurring payment .
        Args:
            body: An object containing the fields to
                POST for the request.  See the corresponding object definition
                for field details.
        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success
        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.
        """

        # Prepare query URL
        _url_path = constant.UPDATE_RECURRING
        _query_builder = self.config.get_base_uri()
        _query_url = _query_builder+_url_path

        # Parameters validation
        requiredFileds = ['paymentCount','status']
        self.validate_parameter(requiredFileds,body)

        if requiredFileds['paymentCount'] <= 0:
            raise InvalidParamsError('paymentCount should be greater than 0')

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url, headers=None, parameters=body)
        _response = self.execute_request(_request)

        if type(_response.response) is not dict:
            _errors = _response.reason
        else:
            _errors = None
        _result = ApiResponse(_response, body=_response.response, errors=_errors)
        return _result