/
YMComponent.php
51 lines (39 loc) · 1.06 KB
/
YMComponent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace grigorieff\ym;
use \YandexMoney\API;
use yii\base\Component;
use yii\base\InvalidConfigException;
class YMComponent extends Component
{
/** @var int */
public $client_id;
/** @var string */
public $code;
/** @var string */
public $redirect_uri;
/** @var null|string */
public $client_secret = null;
/** @var \YandexMoney\API */
private $api = null;
public function init()
{
if (!$this->client_id) {
throw new InvalidConfigException("Client_id can't be empty!");
}
if (!$this->code) {
throw new InvalidConfigException("Code can't be empty!");
}
if (!$this->redirect_uri) {
throw new InvalidConfigException("Redirect_uri can't be empty!");
}
$access_token = API::getAccessToken($this->client_id,$this->code,$this->redirect_uri, $this->client_secret);
$this->api = new API($access_token);
}
/**
* @return \YandexMoney\API
*/
public function getYm()
{
return $this->api;
}
}