1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LBHurtado\EngageSpark\Jobs; |
4
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
6
|
|
|
use LBHurtado\EngageSpark\EngageSpark; |
7
|
|
|
use Illuminate\Queue\SerializesModels; |
8
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
9
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
10
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
11
|
|
|
use LBHurtado\EngageSpark\Classes\ServiceMode; |
12
|
|
|
use LBHurtado\EngageSpark\Classes\TopupHttpApiParams; |
13
|
|
|
|
14
|
|
View Code Duplication |
class TransferAirtime implements ShouldQueue |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
17
|
|
|
|
18
|
|
|
const MODE = 'topup'; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
public $mobile; |
22
|
|
|
|
23
|
|
|
/** @var int */ |
24
|
|
|
public $amount; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
public $reference; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* TopupAmount constructor. |
31
|
|
|
* @param string $mobile |
32
|
|
|
* @param int $amount |
33
|
|
|
* @param string $reference |
34
|
|
|
*/ |
35
|
|
|
public function __construct(string $mobile, int $amount, string $reference) |
36
|
|
|
{ |
37
|
|
|
$this->mobile = $mobile; |
38
|
|
|
$this->amount = $amount; |
39
|
|
|
$this->reference = $reference; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param EngageSpark $service |
44
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
45
|
|
|
*/ |
46
|
|
|
public function handle(EngageSpark $service) |
47
|
|
|
{ |
48
|
|
|
$this->setService($service)->topup(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function topup() |
52
|
|
|
{ |
53
|
|
|
tap(new TopupHttpApiParams($this->service, $this->mobile, $this->amount, $this->reference), function ($params) { |
|
|
|
|
54
|
|
|
$this->service->send($params->toArray(), ServiceMode::TOPUP); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function setService(EngageSpark $service) |
59
|
|
|
{ |
60
|
|
|
$this->service = $service; |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.