protonemedia / laravel-paddle

Paddle.com API integration for Laravel with support for webhooks/events
https://protone.media/en/blog/a-new-laravel-package-to-handle-payments-and-subscriptions-with-paddle
MIT License
203 stars 18 forks source link

Support .env variables according read.me #31

Closed rcarvs closed 3 months ago

rcarvs commented 2 years ago

Hello! I'm using v2.4.0 and according to documentation I could set the vendor_id, vendor_auth_code and public_key on .env or in published config file. But I've set in .env and my Paddle::subscription()->listPlans() returned a non permission returned from Paddle ([107] You don't have permission to access this resource). So I investigated and found on the src/Api/Request.php line 101 the code:

$data = $this->getData() + ['vendor_id' => config('paddle.vendor_id')];

if ($method === static::METHOD_POST) {
    $data['vendor_auth_code'] = config('paddle.vendor_auth_code');
}

This mean that the vendor_id and vendor_auth_code is coming only from config file and it's not getting from .env, right?

I solved it adding a null coalescing operator in this part and I would like to check if can I send a PR with this new code?

$data = $this->getData() + ['vendor_id' => config('paddle.vendor_id')??env('PADDLE_VENDOR_ID')];

if ($method === static::METHOD_POST) {
    $data['vendor_auth_code'] = config('paddle.vendor_auth_code')??env('PADDLE_VENDOR_AUTH_CODE');
}

I've changed all other config usages too for try to use the .env if config variable is not set.
Thanks!

sokolnikov911 commented 1 year ago

@rcarvs hello. You shouldn't change "laravel-paddle" package source code. You can update your config/paddle.php like this:

'vendor_id' => env('PADDLE_VENDOR_ID'),
'vendor_auth_code' => env('PADDLE_VENDOR_AUTH_CODE'),

In this case, the package will take variable values from your .env file.