(self, data)
return tx
Given a data dict coming from redsys, verify it and
        find the related transaction record.
Given a data dict coming from redsys, verify it and
        find the related transaction record.
Given a data dict coming from redsys verify it and find the related transaction record .
def _redsys_form_get_tx_from_data(self, data):
        """Given a data dict coming from redsys, verify it and
        find the related transaction record."""
        parameters = data.get("Ds_MerchantParameters", "")
        parameters_dic = json.loads(base64.b64decode(parameters).decode())
        reference = urllib.parse.unquote(parameters_dic.get("Ds_Order", ""))
        pay_id = parameters_dic.get("Ds_AuthorisationCode")
        shasign = data.get("Ds_Signature", "").replace("_", "/").replace("-", "+")
        test_env = config["test_enable"]
        if not reference or not pay_id or not shasign:
            error_msg = (
                "Redsys: received data with missing reference"
                " (%s) or pay_id (%s) or shashign (%s)" % (reference, pay_id, shasign)
            )
            if not test_env:
                _logger.info(error_msg)
                raise ValidationError(error_msg)
            # For tests
            http.OpenERPSession.tx_error = True
        tx = self.search([("reference", "=", reference)])
        if not tx or len(tx) > 1:
            error_msg = "Redsys: received data for reference %s" % (reference)
            if not tx:
                error_msg += "; no order found"
            else:
                error_msg += "; multiple order found"
            if not test_env:
                _logger.info(error_msg)
                raise ValidationError(error_msg)
            # For tests
            http.OpenERPSession.tx_error = True
        if tx and not test_env:
            # verify shasign
            shasign_check = tx.acquirer_id.sign_parameters(
                tx.acquirer_id.redsys_secret_key, parameters
            )
            if shasign_check != shasign:
                error_msg = (
                    "Redsys: invalid shasign, received %s, computed %s, "
                    "for data %s" % (shasign, shasign_check, data)
                )
                _logger.info(error_msg)
                raise ValidationError(error_msg)
        return tx
def _redsys_form_get_tx_from_data ( self , data ) : parameters = data . get ( "Ds_MerchantParameters" , "" ) parameters_dic = json . loads ( base64 . b64decode ( parameters ) . decode ( ) ) reference = urllib . parse . unquote ( parameters_dic . get ( "Ds_Order" , "" ) ) pay_id = parameters_dic . get ( "Ds_AuthorisationCode" ) shasign = data . get ( "Ds_Signature" , "" ) . replace ( "_" , "/" ) . replace ( "-" , "+" ) test_env = config [ "test_enable" ] if not reference or not pay_id or not shasign : error_msg = ( "Redsys: received data with missing reference" " (%s) or pay_id (%s) or shashign (%s)" % ( reference , pay_id , shasign ) ) if not test_env : _logger . info ( error_msg ) raise ValidationError ( error_msg ) # For tests http . OpenERPSession . tx_error = True tx = self . search ( [ ( "reference" , "=" , reference ) ] ) if not tx or len ( tx ) > 1 : error_msg = "Redsys: received data for reference %s" % ( reference ) if not tx : error_msg += "; no order found" else : error_msg += "; multiple order found" if not test_env : _logger . info ( error_msg ) raise ValidationError ( error_msg ) # For tests http . OpenERPSession . tx_error = True if tx and not test_env : # verify shasign shasign_check = tx . acquirer_id . sign_parameters ( tx . acquirer_id . redsys_secret_key , parameters ) if shasign_check != shasign : error_msg = ( "Redsys: invalid shasign, received %s, computed %s, " "for data %s" % ( shasign , shasign_check , data ) ) _logger . info ( error_msg ) raise ValidationError ( error_msg ) return tx