1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Furic\RedeemCodes\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Furic\RedeemCodes\Models\RedeemCode; |
6
|
|
|
use Furic\RedeemCodes\Models\RedeemCodeHistory; |
7
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
use Validator; |
10
|
|
|
|
11
|
|
|
// The controller for redeem code api calls. |
12
|
|
|
class RedeemController extends Controller |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function redeem($code) |
16
|
|
|
{ |
17
|
|
|
$validator = Validator::make(['code' => $code], ['code' => 'exists:redeem_codes,code']); |
18
|
|
|
if ($validator->fails()) { |
19
|
|
|
return response([ |
20
|
|
|
'error' => 'No redeem code found.' |
21
|
|
|
], 400); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$redeemCode = RedeemCode::findByCode($code); |
25
|
|
|
|
26
|
|
|
if ($redeemCode->redeemed != false) { |
|
|
|
|
27
|
|
|
return response([ |
28
|
|
|
'error' => 'Redeem code has already redeemed.' |
29
|
|
|
], 400); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Check event valid date |
33
|
|
|
$event = $redeemCode->event; |
34
|
|
|
if ($event != null) { |
35
|
|
|
$validator = Validator::make($event->toArray(), ['start_at' => 'before:tomorrow']); |
36
|
|
|
if ($validator->fails()) { |
37
|
|
|
return response([ |
38
|
|
|
'error' => 'Redeem code cannot be used yet.' |
39
|
|
|
], 400); |
40
|
|
|
} |
41
|
|
|
$validator = Validator::make($event->toArray(), ['end_at' => 'after:yesterday']); |
42
|
|
|
if ($validator->fails()) { |
43
|
|
|
return response([ |
44
|
|
|
'error' => 'Redeem code has expired.' |
45
|
|
|
], 400); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($redeemCode->reusable == false) { |
|
|
|
|
50
|
|
|
$redeemCode->setRedeemed(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Add a redeem code history |
54
|
|
|
$data['redeem_code_id'] = $redeemCode->id; |
|
|
|
|
55
|
|
|
$data['ip'] = filter_input(INPUT_SERVER, "REMOTE_ADDR"); |
56
|
|
|
$data['agent'] = filter_input(INPUT_SERVER, "HTTP_USER_AGENT"); |
57
|
|
|
RedeemCodeHistory::create($data); |
58
|
|
|
|
59
|
|
|
return $redeemCode; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths