controllers/Credential.php
protected function validateFileUploadCredential()
    {
        $upload = $this->request->file('file');

        if (empty($upload)) {

            if (!isset($this->data_credential['credential_id'])) {
                $this->setError('data.file', $this->text('File is required'));
                return false;
            }

            return null;
        }

        if ($this->isError()) {
            return null;
        }

        $result = $this->file_transfer->upload($upload, false, gplcart_file_private_module('gapi'));

        if ($result !== true) {
            $this->setError('data.file', $result);
            return false;
        }

        $file = $this->file_transfer->getTransferred();
        $decoded = json_decode(file_get_contents($file), true);

        if (empty($decoded['private_key'])) {
            unlink($file);
            $this->setError('data.file', $this->text('Failed to read JSON file'));
            return false;
        }

        if (isset($this->data_credential['data']['file'])) {
            $existing = gplcart_file_absolute($this->data_credential['data']['file']);
            if (file_exists($existing)) {
                unlink($existing);
            }
        }

        $this->setSubmitted('data.file', gplcart_file_relative($file));
        return true;
    }
protected function validateFileUploadCredential()
    {
        $upload = $this->request->file('file');

        if (empty($upload)) {

            if (!isset($this->data_credential['credential_id'])) {
                $this->setError('data.file', $this->text('File is required'));
                return false;
            }

            return null;
        }

        if ($this->isError()) {
            return null;
        }

        $result = $this->file_transfer->upload($upload, false, gplcart_file_private_module('gapi'));

        if ($result !== true) {
            $this->setError('data.file', $result);
            return false;
        }

        $file = $this->file_transfer->getTransferred();
        $decoded = json_decode(file_get_contents($file), true);

        if (empty($decoded['private_key'])) {
            unlink($file);
            $this->setError('data.file', $this->text('Failed to read JSON file'));
            return false;
        }

        if (isset($this->data_credential['data']['file'])) {
            $existing = gplcart_file_absolute($this->data_credential['data']['file']);
            if (file_exists($existing)) {
                unlink($existing);
            }
        }

        $this->setSubmitted('data.file', gplcart_file_relative($file));
        return true;
    }
protected function validateFileUploadCredential ( ) { $ upload = $ this -> request -> file ( 'file' ) ; if ( empty ( $ upload ) ) { if ( ! isset ( $ this -> data_credential [ 'credential_id' ] ) ) { $ this -> setError ( 'data.file' , $ this -> text ( 'File is required' ) ) ; return false ; } return null ; } if ( $ this -> isError ( ) ) { return null ; } $ result = $ this -> file_transfer -> upload ( $ upload , false , gplcart_file_private_module ( 'gapi' ) ) ; if ( $ result !== true ) { $ this -> setError ( 'data.file' , $ result ) ; return false ; } $ file = $ this -> file_transfer -> getTransferred ( ) ; $ decoded = json_decode ( file_get_contents ( $ file ) , true ) ; if ( empty ( $ decoded [ 'private_key' ] ) ) { unlink ( $ file ) ; $ this -> setError ( 'data.file' , $ this -> text ( 'Failed to read JSON file' ) ) ; return false ; } if ( isset ( $ this -> data_credential [ 'data' ] [ 'file' ] ) ) { $ existing = gplcart_file_absolute ( $ this -> data_credential [ 'data' ] [ 'file' ] ) ; if ( file_exists ( $ existing ) ) { unlink ( $ existing ) ; } } $ this -> setSubmitted ( 'data.file' , gplcart_file_relative ( $ file ) ) ; return true ; }
Validates JSON file upload
@return bool
Validates JSON file upload