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

Dinamic username & password parameters #57

Open
hidabe opened this issue Jan 15, 2013 · 8 comments
Open

Dinamic username & password parameters #57

hidabe opened this issue Jan 15, 2013 · 8 comments

Comments

@hidabe
Copy link

hidabe commented Jan 15, 2013

Hello,

I need use dinamic username & password for paymentplugin,

Where can i do it?

Thanks!!

@hidabe
Copy link
Author

hidabe commented Jan 21, 2013

I have done it, finally i modify TokenAuthenticationStrategy.php file, from JMSPaymentPaypalBundle, function authenticate, adding posible external modification of auth params:

public function authenticate(Request $request)
{   
    if ($request->request->get('USER') == "") {
        $request->request->set('USER', $this->username);
    }
    if ($request->request->get('PWD') == "") {
        $request->request->set('PWD', $this->password);
    }
    if ($request->request->get('SIGNATURE') == "") {
        $request->request->set('SIGNATURE', $this->signature);
    }
}

From my controller, now add USER, PWD and SIGNATURE in checkout_params and it work.

It is ok? any suggest? Thanks

@hidabe
Copy link
Author

hidabe commented Jan 21, 2013

Finally I did:

    public function authenticate(Request $request)
    {   
        $USER_temp = explode(";",$this->username);
        $PWD_temp = explode(";",$this->password);
        $SIGNATURE_temp = explode(";",$this->signature);

        $i =$request->request->get('SELECT_USER');

        $request->request->set('USER', $USER_temp[$i]);
        $request->request->set('PWD', $PWD_temp[$i]);
        $request->request->set('SIGNATURE', $SIGNATURE_temp[$i]);
    }

And now, i can add ilimited accounts and select from controller, less intrusive code, too it is back compatible.

Suggest? Thanks!

@ClementGautier
Copy link

Hi,

I had to do the same thing in my project, I created a class named EditableTokenAuthenticationStrategy in my application witch extends TokenAuthenticationStrategy and implements setter methods:

class EditableTokenAuthenticationStrategy extends TokenAuthenticationStrategy
{
    /**
     * @param string $username
     */
    public function setUsername($username)
    {
        $this->username = $username;
    }

    /**
     * @param string $password
     */
    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * @param string $signature
     */
    public function setSignature($signature)
    {
        $this->signature = $signature;
    }
}

Then I overrode the container parameter:

<parameter key="payment.paypal.authentication_strategy.token.class">Foo\PaymentBundle\Paypal\Client\Authentication\EditableTokenAuthenticationStrategy</parameter>

Finally in your controller you can do something like this:

$this->get('payment.paypal.authentication_strategy.token')
            ->setUsername($username)
            ->setPassword($password)
            ->setSignature($signature);

I hope it will help.

I think we should create a TokenAuthenticationStrategyProvider who, by default, create a token from the container parameters and can be overrode in an application by something else.

@ClementGautier
Copy link

So the Configuration should be:

jms_payment_paypal:
    username: your api username (not your account username)
    password: your api password (not your account password)
    signature: your api signature
    debug: true/false # when true, connect to PayPal sandbox; uses kernel debug value when not specified

or

jms_payment_paypal:
    authentication_strategy:
        provider: your token provider

I will not have time to implement it now but it's an easy improvement to make

@hidabe
Copy link
Author

hidabe commented Jan 23, 2013

Ohhh, good solution, thanks, it is perfect, yes,

i will not have time now, and my know... are not enoght for it (i think),

Thanks anyway, regards

ruudk pushed a commit to ruudk/JMSPaymentPaypalBundle that referenced this issue Apr 10, 2014
@psrpinto
Copy link
Collaborator

psrpinto commented Oct 9, 2016

@ClementGautier I know it's been a while but I it would be useful to have your solution in the documentation. Would you be available to create a PR?

@ClementGautier
Copy link

@regularjack Hi, (and sorry for the delay). I've no time at the moment to contribute but you can probably just copy / paste my answer in the doc ;) I don't mind being mentioned on it so be pleased to use it as it was your own work.

@JoannaSM
Copy link

JoannaSM commented Feb 2, 2018

@ClementGautier I'm not shire, where I should do this:

$this->get('payment.paypal.authentication_strategy.token')
->setUsername($username)
->setPassword($password)
->setSignature($signature);

Before build paypal form?

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

No branches or pull requests

4 participants