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

Undefined variable: user #3

Closed
aqeelhashem opened this issue Jan 28, 2020 · 5 comments
Closed

Undefined variable: user #3

aqeelhashem opened this issue Jan 28, 2020 · 5 comments

Comments

@aqeelhashem
Copy link

Hi,

and thank you for great work.

I'm trying to call (pay) function in controller, but i get this error when set your example code:
Undefined variable: user

and when try to create user variable by using this code :
$user = Auth::user();

i get this error:
Call to undefined method App\User::pay()

So, how can get ($user) variable ?

@aemaddin
Copy link
Collaborator

Thanks for you'r contribution,

First to use pay method, don't forget to use HasKnet trait inside User model

<?php

namespace App;

use Asciisd\Knet\HasKnet;

class User extends Authenticatable {
   use HasKnet;
}

for second question, the pay method not static, so to call it you should get user instance first, for example if you are inside controller you can do this :-

 public function update(Request $request, $id)
    {
        $payment = $request->user()->pay($request->amount, [
            'udf1' => $request->user()->name,
            'udf2' => $request->user()->email,
        ]);
    }

@aqeelhashem
Copy link
Author

Thanks very much,
it's work

but it redirect to KPAYTEST page not KPAY, so i have to make some change in knet.php file , by change
$url = config('knet.development_url');
to
$url = config('knet.production_url');
but what is the correct way to switching between them

another thing, do you know what's the parameters for KPAYTEST like (tranportal id - password & resource key) so i can make testing.

@aemaddin
Copy link
Collaborator

just change .env file keys,

APP_ENV=#local# to #production#
KNET_DEBUG=#true# to #false#

@aemaddin
Copy link
Collaborator

to get parameters, you should ask your bank to send you test parameters.

@aqeelhashem
Copy link
Author

Thanks very much Amr great work,I have another questions but i will open another posts

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