|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BootstrapCommand. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Bmatovu\MtnMomo\Console; |
|
7
|
|
|
|
|
8
|
|
|
use Bmatovu\MtnMomo\Traits\CommandUtilTrait; |
|
9
|
|
|
use Illuminate\Console\Command; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Bootstrap integration. |
|
13
|
|
|
*/ |
|
14
|
|
|
class BootstrapCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
use CommandUtilTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The name and signature of the console command. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $signature = 'mtn-momo:init |
|
24
|
|
|
{--no-write= : Don\'t write credentials to .env file.} |
|
25
|
|
|
{--f|force : Force the operation to run when in production.}'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The console command description. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $description = 'Bootstrap/setup integration.'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Create a new command instance. |
|
36
|
|
|
*/ |
|
37
|
25 |
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
25 |
|
parent::__construct(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Execute the console command. |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
7 |
|
public function handle() |
|
48
|
|
|
{ |
|
49
|
7 |
|
if (! $this->runInProduction()) { |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
7 |
|
$this->printLabels('MTN MOMO API integration', [ |
|
54
|
|
|
'Please enter the values for the following settings,', |
|
55
|
|
|
"Or press 'Enter' to accept the given default values in square brackets.", |
|
56
|
|
|
'These settings will be written to your .env', |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
7 |
|
$this->setClientName(); |
|
60
|
|
|
|
|
61
|
7 |
|
$this->setEnvironment(); |
|
62
|
|
|
|
|
63
|
7 |
|
$this->setCurrency(); |
|
64
|
|
|
|
|
65
|
7 |
|
$this->setProviderCallbackHost(); |
|
66
|
|
|
|
|
67
|
7 |
|
$this->setProductName(); |
|
68
|
|
|
|
|
69
|
7 |
|
$this->setProductSubscriptionKey(); |
|
70
|
|
|
|
|
71
|
7 |
|
$this->info("\r\nNext: Register your client application's ID."); |
|
72
|
7 |
|
$this->line("\r\n>>> php artisan mtn-momo:register-id"); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Create/update client APP name. |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
7 |
|
protected function setClientName() |
|
81
|
|
|
{ |
|
82
|
7 |
|
$this->printLabels('Client APP name', [ |
|
83
|
|
|
'May be indicated in the message sent to the payee', |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
7 |
|
$clientName = $this->laravel['config']->get('mtn-momo.app'); |
|
87
|
7 |
|
$clientName = $this->ask('MOMO_APP', $clientName); |
|
88
|
|
|
|
|
89
|
7 |
|
$this->updateSetting('MOMO_APP', 'mtn-momo.app', $clientName); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Create/update target environment. |
|
94
|
|
|
* |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
7 |
|
protected function setEnvironment() |
|
98
|
|
|
{ |
|
99
|
7 |
|
$this->printLabels('Environment', [ |
|
100
|
|
|
'Also called: <options=bold>targetEnvironment</>.', |
|
101
|
|
|
]); |
|
102
|
|
|
|
|
103
|
7 |
|
$environment = $this->laravel['config']->get('mtn-momo.environment'); |
|
104
|
7 |
|
$environments = ['sandbox', 'live']; |
|
105
|
7 |
|
$index = array_search($environment, $environments); |
|
106
|
7 |
|
$default = ($index === false) ? null : $index; |
|
107
|
7 |
|
$environment = $this->choice('MOMO_ENVIRONMENT', $environments, $default); |
|
108
|
|
|
|
|
109
|
7 |
|
$this->updateSetting('MOMO_ENVIRONMENT', 'mtn-momo.environment', $environment); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Create/update currency. |
|
114
|
|
|
* |
|
115
|
|
|
* @return void |
|
116
|
|
|
*/ |
|
117
|
7 |
|
protected function setCurrency() |
|
118
|
|
|
{ |
|
119
|
7 |
|
$this->printLabels('Currency', [ |
|
120
|
|
|
"Use 'EUR' for sandbox environment", |
|
121
|
|
|
]); |
|
122
|
|
|
|
|
123
|
7 |
|
$currency = $this->laravel['config']->get('mtn-momo.currency'); |
|
124
|
7 |
|
$currency = $this->ask('MOMO_CURRENCY', $currency); |
|
125
|
|
|
|
|
126
|
7 |
|
$this->updateSetting('MOMO_CURRENCY', 'mtn-momo.currency', strtoupper($currency)); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Create/update currency. |
|
131
|
|
|
* |
|
132
|
|
|
* @return void |
|
133
|
|
|
*/ |
|
134
|
7 |
|
protected function setProviderCallbackHost() |
|
135
|
|
|
{ |
|
136
|
7 |
|
$this->printLabels('Provider Callback Host', ['Your server hostname']); |
|
137
|
|
|
|
|
138
|
7 |
|
$providerCallbackHost = $this->laravel['config']->get('mtn-momo.provider_callback_host'); |
|
139
|
7 |
|
$providerCallbackHost = $this->ask('MOMO_PROVIDER_CALLBACK_HOST', $providerCallbackHost); |
|
140
|
|
|
|
|
141
|
7 |
|
$this->updateSetting('MOMO_PROVIDER_CALLBACK_HOST', 'mtn-momo.provider_callback_host', $providerCallbackHost); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Create/update target product subscribed too. |
|
146
|
|
|
* |
|
147
|
|
|
* @return void |
|
148
|
|
|
*/ |
|
149
|
7 |
|
protected function setProductName() |
|
150
|
|
|
{ |
|
151
|
7 |
|
$this->printLabels('Product'); |
|
152
|
|
|
|
|
153
|
7 |
|
$product = $this->laravel['config']->get('mtn-momo.product'); |
|
154
|
7 |
|
$products = ['collection', 'disbursement', 'remittance']; |
|
155
|
7 |
|
$index = array_search($product, $products); |
|
156
|
7 |
|
$default = ($index === false) ? 0 : $index; |
|
157
|
|
|
|
|
158
|
7 |
|
$product = $this->choice('MOMO_PRODUCT', $products, $default); |
|
159
|
|
|
|
|
160
|
7 |
|
$this->updateSetting('MOMO_PRODUCT', 'mtn-momo.product', $product); |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Create/update product subscription key. |
|
165
|
|
|
* |
|
166
|
|
|
* @return void |
|
167
|
|
|
*/ |
|
168
|
7 |
|
protected function setProductSubscriptionKey() |
|
169
|
|
|
{ |
|
170
|
7 |
|
$this->printLabels('Product subscription key', [ |
|
171
|
|
|
'Also called: <options=bold>Ocp-Apim-Subscription-Key</>.', |
|
172
|
|
|
]); |
|
173
|
|
|
|
|
174
|
7 |
|
$product = $this->laravel['config']->get('mtn-momo.product'); |
|
175
|
|
|
|
|
176
|
7 |
|
$uProduct = strtoupper($product); |
|
177
|
|
|
|
|
178
|
7 |
|
$productKey = $this->laravel['config']->get("mtn-momo.products.{$product}.key"); |
|
179
|
7 |
|
$productKey = $this->ask("MOMO_{$uProduct}_SUBSCRIPTION_KEY", $productKey); |
|
180
|
|
|
|
|
181
|
7 |
|
$this->updateSetting("MOMO_{$uProduct}_SUBSCRIPTION_KEY", "mtn-momo.products.{$product}.key", $productKey); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|