1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bmatovu\Beyonic\Services; |
4
|
|
|
|
5
|
|
|
use Bmatovu\Beyonic\Traits\HttpClient; |
6
|
|
|
use GuzzleHttp\ClientInterface; |
7
|
|
|
use Illuminate\Container\Container; |
8
|
|
|
use Illuminate\Contracts\Config\Repository; |
9
|
|
|
|
10
|
|
|
class Collection |
11
|
|
|
{ |
12
|
|
|
use HttpClient; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* HTTP client. |
16
|
|
|
* |
17
|
|
|
* @var \GuzzleHttp\ClientInterface |
18
|
|
|
*/ |
19
|
|
|
protected $client; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Constructor. |
23
|
|
|
* |
24
|
|
|
* @uses \Illuminate\Container\Container |
25
|
|
|
*/ |
26
|
3 |
|
public function __construct() |
27
|
|
|
{ |
28
|
3 |
|
$this->client = $this->makeClient(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Set HTTP client. |
33
|
|
|
*/ |
34
|
3 |
|
public function setClient(ClientInterface $client) |
35
|
|
|
{ |
36
|
3 |
|
$this->client = $client; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get HTTP client. |
41
|
|
|
* |
42
|
|
|
* @return \GuzzleHttp\ClientInterface |
43
|
|
|
*/ |
44
|
1 |
|
public function getClient() |
45
|
|
|
{ |
46
|
1 |
|
return $this->client; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Collect funds from a customer. |
51
|
|
|
* |
52
|
|
|
* @param string $payee |
53
|
|
|
* @param float $amount |
54
|
|
|
* |
55
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
56
|
|
|
* |
57
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
58
|
|
|
*/ |
59
|
1 |
|
public function ask($payee, $amount) |
60
|
|
|
{ |
61
|
1 |
|
$config = Container::getInstance()->make(Repository::class); |
62
|
|
|
|
63
|
1 |
|
return $this->client->request('POST', 'collectionrequests', [ |
64
|
1 |
|
'json' => array_merge([ |
65
|
1 |
|
'phonenumber' => $payee, |
66
|
1 |
|
'amount' => $amount, |
67
|
1 |
|
], $config->get('beyonic.collection')), |
68
|
1 |
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Retrieve a single collection. |
73
|
|
|
* |
74
|
|
|
* @param int $collectionId |
75
|
|
|
* |
76
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
77
|
|
|
* |
78
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
79
|
|
|
*/ |
80
|
1 |
|
public function get($collectionId) |
81
|
|
|
{ |
82
|
1 |
|
return $this->client->request('GET', "collectionrequests/{$collectionId}"); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Retrieve all collections. |
87
|
|
|
* |
88
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
89
|
|
|
* |
90
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
91
|
|
|
*/ |
92
|
1 |
|
public function all() |
93
|
|
|
{ |
94
|
1 |
|
return $this->client->request('GET', 'collectionrequests'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|