Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

published config file is not applied at all #95

Closed
r-yeganeh opened this issue Aug 12, 2020 · 6 comments
Closed

published config file is not applied at all #95

r-yeganeh opened this issue Aug 12, 2020 · 6 comments

Comments

@r-yeganeh
Copy link

Hi! I'm trying to run your package on laravel 5.8 using docker (laradock).
There seems to be a problem in Payment class:

protected function loadDefaultConfig() : array
{
    dd(static::getDefaultConfigPath());
    return require(static::getDefaultConfigPath());
}

When I dd static::getDefaultConfigPath() here, I get the path to the config file of the package instead of my published vendor file which I have configured.

I tried removing my own config file and republishing vendor. I also tried clearing cache and config with artisan commands. But my own config file is not applied at all!

@khanzadimahdi
Copy link
Member

khanzadimahdi commented Aug 12, 2020

as the name loadDefaultConfig says, this method loads the default config of the package.
if you publish the configs using php artisan vendor:publish then your configs will be loaded instead of defaults.

your config file should be exists in config/payment.php path.

@r-yeganeh
Copy link
Author

Yes, I've already used that artisan command and the file does exist at config/payment.php. But anything I configure in config/payment.php is not applied including merchantId.

@khanzadimahdi
Copy link
Member

run your project outside of docker and publish vendors, then check if every thing goes correctly or not and let me know about it.

@r-yeganeh
Copy link
Author

Dear friend, I tried running the project outside docker on production environment. The problem still exists. Could you please determine where in your code that published vendor config file is read?
This is the code I'm using for payment:

// create invoice
$invoice->amount(1000)
    ->detail('detail1', 'your detail1 goes here')
    ->detail('detailName2', 'your detail2 goes here');
// dd($invoice);
$orderAuditNumber = 10406;
$payment = new Payment();
dd($payment);

return $payment->callbackUrl(route('verify-order-payment', $orderAuditNumber))
            ->purchase(
                $invoice,
                function ($driver, $transactionId)
                {
                    // dd('inside callback');
                }
            )
            ->pay()
            ->render();

So, getting those invoice and payment objects shows that my merchantId is empty string and other configs are not applied, too. Also, another issue I saw was when I tried to run static function calls as suggested in github document like:

return Payment::purchase(
    (new Invoice)->amount(1000), 
    function($driver, $transactionId) {
	    // Store transactionId in database.
        // We need the transactionId to verify payment in the future.
    }
)->pay()->render();

Purchase function seems to be declared as a non-static function in driver files (like Zarinpal.php).

public function purchase()

But called statically in github document like the above call.

@khanzadimahdi
Copy link
Member

you have done a mistake in your codes.
the Payment constructor accepts configs, so if you wanna to instantiate it, you MUST pass configs to it by yourself.
you have not fellow the docs, you should use Payment facade instead, then the package will handle configs itself.

change the codes like the below:

// Create new invoice.
$invoice = (new Invoice)->amount(1000);
// Purchase and pay the given invoice.
// You should use return statement to redirect user to the bank page.
return Payment::purchase($invoice, function($driver, $transactionId) {
    // Store transactionId in database as we need it to verify payment in the future.
})->pay()->render();

and about non-static function in driver files , i could say that Payment class handles calling methods and its not related to Zarinpal , this is a kind of Proxy pattern.

@r-yeganeh
Copy link
Author

You're right! Thank you for your support! Actually there were 2 classes called Payment. And I had added the other one (by PHPStorm autocomplete), instead of Payment facade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants