-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonoTokenGenerator.php
More file actions
62 lines (52 loc) · 1.32 KB
/
MonoTokenGenerator.php
File metadata and controls
62 lines (52 loc) · 1.32 KB
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
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Bow\Payment\MTMMobileMoney;
use Bow\Payment\Common\PaymentToken as MomoToken;
use GuzzleHttp\Client as HttpClient;
class MomoEnvironment
{
/**
* HTTP client instance
*
* @var HttpClient
*/
private $http;
/**
* MomoEnvironment constructor
*
* @param MomoEnvironment $environment
* @return mixed
*/
public function __construct(private MomoEnvironment $environment, private string $interface_name = 'collection')
{
$this->http = new HttpClient(['base_uri' => $this->environment->getBaseUri()]);
}
/**
* Get the token
*
* @return string
*/
public function getToken()
{
$headers = $this->environment->getAuthorization();
$response = $this->http->post('/'.$this->interface_name.'/token', [
'headers' => $headers
]);
// Get the response content
$content = $response->getBody()->getContents();
$token = json_decode($content);
return new MomoToken(
$token->access_token,
$token->token_type,
$token->expires_in
);
}
/**
* Set the interface type nane
*
* @param string $name
*/
public function setInterfaceName($name)
{
$this->interface_name = $name;
}
}