1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Samerior\MobileMoney\Mpesa\Commands; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\GuzzleException; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Samerior\MobileMoney\Mpesa\Library\RegisterUrl; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Registra |
11
|
|
|
* @package Samerior\MobileMoney\Commands |
12
|
|
|
*/ |
13
|
|
|
class Registra extends Command |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The name and signature of the console command. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'mpesa:register_url'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Register mpesa validation and confirmation URL'; |
28
|
|
|
/** |
29
|
|
|
* @var RegisterUrl |
30
|
|
|
*/ |
31
|
|
|
private $registerUrl; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Create a new command instance. |
35
|
|
|
* |
36
|
|
|
* @param RegisterUrl $registerUrl |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct(RegisterUrl $registerUrl) |
39
|
|
|
{ |
40
|
1 |
|
parent::__construct(); |
41
|
1 |
|
$this->registerUrl = $registerUrl; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Execute the console command. |
46
|
|
|
* |
47
|
|
|
* @return mixed |
48
|
|
|
* @throws GuzzleException |
49
|
|
|
* @throws \Exception |
50
|
|
|
*/ |
51
|
|
|
public function handle() |
52
|
|
|
{ |
53
|
|
|
$register = $this->registerUrl |
54
|
|
|
->register($this->askShortcode()) |
55
|
|
|
->onConfirmation($this->askConfirmationUrl()) |
56
|
|
|
->onValidation($this->askValidationUrl()) |
57
|
|
|
->submit(); |
58
|
|
|
dd($register); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function askShortcode(): string |
62
|
|
|
{ |
63
|
|
|
return $this->ask('What is your shortcode', \config('samerior.mpesa.c2b.short_code')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function askConfirmationUrl(): string |
67
|
|
|
{ |
68
|
|
|
return $this->ask('Confirmation Url', \config('samerior.mpesa.c2b.confirmation_url')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function askValidationUrl(): string |
72
|
|
|
{ |
73
|
|
|
return $this->ask('Validation Url', \config('samerior.mpesa.c2b.validation_url')); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|