0

I am using XERO API to integrate with my project, while authentication i am using consumer_key, consumer_secret, rsa_private_key, rsa_public_key to authenticate with xero account, i was generate rsa_private_key and rsa_public_key and placed in storage/app/certificates directory while fetching these keys i am using file_get_contents function to get the keys but facing the error file_get_contents(): Filename cannot be empty, how can i resolve this?

My File paths

enter image description here

Xero.php

private static function get_config(){

        return $config = [

            'oauth' => [

                'callback'         => '',

                'consumer_key'     => config('constants.XERO_CONSUMER_KEY'),

                'consumer_secret'  => config('constants.XERO_CONSUMER_SECRET'),

                'rsa_private_key'  => file_get_contents(config('constants.XERO_PRIVATE_KEY_CERTIFICATE_FILE_PATH')),

                'rsa_public_key'   => file_get_contents(config('constants.XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH')),

            ],
        ];
    }

config/constants/dev_constants.php

<?php

$xero_constants = [
    "XERO_CONSUMER_KEY"     => "***",
    "XERO_CONSUMER_SECRET"  => "***",
    "XERO_PRIVATE_KEY_CERTIFICATE_FILE_PATH"    =>  dirname(__FILE__,3)."/storage/app/certificates/privatekey.pem",
    "XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH"     =>  dirname(__FILE__,3)."/storage/app/certificates/publickey.cer",

];

?>
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Saad Masood
  • 312
  • 1
  • 2
  • 16
  • Is the error being thrown because it cant read the key files ??? you could use `storage_path('app/certificates/privatekey.pem)` helper method instead of `dirname(__FILE__)` – alithedeveloper Jan 24 '20 at 13:27
  • @alithedeveloper It is not working! – Saad Masood Jan 24 '20 at 13:38
  • @alithedeveloper this command can create issue i think.. How can i overcome it? 'rsa_public_key' => file_get_contents(config('constants.XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH')), – Saad Masood Jan 24 '20 at 13:40
  • Can you `dd(config('constants.XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH'))`. I think you are reading the config wrong. It should be `config('constants.dev_contants. XERO_PRIVATE_KEY_CERTIFICATE_FILE_PATH')` ??? – alithedeveloper Jan 24 '20 at 13:43

1 Answers1

1

You are yting to get config via :

config('constants.XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH')

It will return null. because config has no return. You need to edit your dev_constants.php :

<?php

return [
    "XERO_CONSUMER_KEY"     => "***",
    "XERO_CONSUMER_SECRET"  => "***",
    "XERO_PRIVATE_KEY_CERTIFICATE_FILE_PATH"    =>  dirname(__FILE__,3)."/storage/app/certificates/privatekey.pem",
    "XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH"     =>  dirname(__FILE__,3)."/storage/app/certificates/publickey.cer",

];
config('constants.dev_constants.XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH')
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
  • I have edited @wahyu answer, but looking at your config structure it should be `config('constants.dev_constants.XERO_PUBLIC_KEY_CERTIFICATE_FILE_PATH')` – alithedeveloper Jan 24 '20 at 13:54
  • @alithedeveloper you cannot edit someone's answer based on your answer. You can answer it. You can edit someone's answer because of typo, format or broken links. – Wahyu Kristianto Jan 24 '20 at 14:03
  • My bad, didnt know that. However, it was adding just `dev_constants` to your config read. – alithedeveloper Jan 24 '20 at 14:16