CodeIgniter Forums

Full Version: Codeignter 3 how install a third_part class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi , sorry for english , im tryng to install https://github.com/paypal/Payouts-PHP-SDK in codeigniter how can i do ?

Im tryng to insert it in vendor and with $config['composer_autoload'] = TRUE ;

but if i call $request = new PayoutsPostRequest(); 

i have 

Message: Class 'PayoutsPostRequest' not found

The other class (facebook and google login work fine inside vendor folder)

Its better insert the sdk in third party ?
Code:
$request = new \PaypalPayoutsSDK\Payouts\PayoutsPostRequest();
(06-11-2020, 04:13 PM)ivantcholakov Wrote: [ -> ]
Code:
$request = new \PaypalPayoutsSDK\Payouts\PayoutsPostRequest();

Thanks work fine but i have some answer for you :

In this package there is a folder called sample with some classes  , how can i create  an istance of CreatePayoutSample ( this class are in sample folder) ?

How can i set correct path to a class ( \PaypalPayoutsSDK\Payouts\PayoutsPostRequest is inside lib) ?

in this folder there is a class calle PayPalClient where must insert the cofiguration , how can i modify to get the configuration variable from my application/config/paypal.php file
1.

Maybe it would be convenient if you make a CI3-style library that extends \PaypalPayoutsSDK\Payouts\PayoutsPostRequest

application/libraries/Payouts_post_request.php :

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed.');

class Payouts_post_request extends \PaypalPayoutsSDK\Payouts\PayoutsPostRequest {

    public function __construct($config = array()) {

        if (!is_array($config)) {
            $config = array();
        }

        // Maybe something from options should be injected here (at the constructor);
        parent::__construct($config['SomeOption'], .....);

        // Or maybe configuration may be passed through some additional methods that parent class posesses.
        $this->setSomeOption2($config['SomeOption2']);
    }

}

application/config/payouts_post_request.php - should contain configuration options:

Code:
$config['SomeOption'] = 'hksdhfkjfkasfu';
$config['SomeOption2'] = 'jvkdjbfvkjbkkjiewf';

And then load as an ordinary library and access its methods:

Code:
$this->load->library('payouts_post_request');
$this->payouts_post_request->doSomething();

The library is a singleton, so if you use it twice or more times with different options you should provide a method for resetting its internal data.

Here is another example with detailed explanations of this idea: https://forum.codeigniter.com/thread-61112.html

2.

But if usage of these classes within the package is more complex, then use them directly, make a separate special configuration file application/config/paypal.php and load its content when it is needed:

Code:
$paypal_config = $this->load->config('paypal', TRUE);

Pass the elements of the array $paypal_config as parameters where it is appropriate.
(06-12-2020, 03:15 AM)ivantcholakov Wrote: [ -> ]1.

Maybe it would be convenient if you make a CI3-style library that extends \PaypalPayoutsSDK\Payouts\PayoutsPostRequest

application/libraries/Payouts_post_request.php :

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed.');

class Payouts_post_request extends \PaypalPayoutsSDK\Payouts\PayoutsPostRequest {

    public function __construct($config = array()) {

        if (!is_array($config)) {
            $config = array();
        }

        // Maybe something from options should be injected here (at the constructor);
        parent::__construct($config['SomeOption'], .....);

        // Or maybe configuration may be passed through some additional methods that parent class posesses.
        $this->setSomeOption2($config['SomeOption2']);
    }

}

application/config/payouts_post_request.php - should contain configuration options:

Code:
$config['SomeOption'] = 'hksdhfkjfkasfu';
$config['SomeOption2'] = 'jvkdjbfvkjbkkjiewf';

And then load as an ordinary library and access its methods:

Code:
$this->load->library('payouts_post_request');
$this->payouts_post_request->doSomething();

The library is a singleton, so if you use it twice or more times with different options you should provide a method for resetting its internal data.

Here is another example with detailed explanations of this idea: https://forum.codeigniter.com/thread-61112.html

2.

But if usage of these classes within the package is more complex, then use them directly, make a separate special configuration file application/config/paypal.php and load its content when it is needed:

Code:
$paypal_config = $this->load->config('paypal', TRUE);

Pass the elements of the array $paypal_config as parameters where it is appropriate.

Tank you so much , the last answer , are you expert on paypal ? Because i must do a payout , with curl i can do a payout and i can get the sender_batch_id , i use this with curl to get the transaction id of paypal , the problem is that this payment is asincronous and i must implement a webhook  to listen the response . I cannot find code expecially where i must the url of webook in my code , or is webhook  alwais listening ?
I've done payments, but not exactly on paypal, I can't help with it.