| 1 |
<?php |
| 2 |
|
| 3 |
namespace Monei\Services\sdk; |
| 4 |
|
| 5 |
use Monei\Configuration; |
| 6 |
use Monei\MoneiClient; |
| 7 |
use Monei\Services\ApiKeyService; |
| 8 |
|
| 9 |
class MoneiSdkClientFactory { |
| 10 |
private ApiKeyService $apiKeyService; |
| 11 |
private $client; |
| 12 |
|
| 13 |
public function __construct( ApiKeyService $apiKeyService ) { |
| 14 |
$this->apiKeyService = $apiKeyService; |
| 15 |
$this->client = null; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* @return MoneiClient |
| 20 |
*/ |
| 21 |
public function get_client() { |
| 22 |
if ( $this->client === null ) { |
| 23 |
include_once WC_Monei()->plugin_path() . '/vendor/autoload.php'; |
| 24 |
$config = Configuration::getDefaultConfiguration(); |
| 25 |
$this->client = new MoneiClient( $this->apiKeyService->get_api_key(), $config ); |
| 26 |
$this->client->setUserAgent( |
| 27 |
'MONEI/WooCommerce/' . WC_Monei()->version . |
| 28 |
' (WordPress v' . get_bloginfo( 'version' ) . |
| 29 |
'; Woo v' . WC()->version . |
| 30 |
'; PHP v' . phpversion() . ')' |
| 31 |
); } |
| 32 |
return $this->client; |
| 33 |
} |
| 34 |
} |
| 35 |
|