|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Country; |
|
6
|
|
|
use App\Models\Purse; |
|
7
|
|
|
use App\Models\ShopInventory; |
|
8
|
|
|
use Illuminate\Http\JsonResponse; |
|
9
|
|
|
use Illuminate\Http\RedirectResponse; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
use Illuminate\Http\Response; |
|
12
|
|
|
use Illuminate\Support\Facades\DB; |
|
13
|
|
|
use Laravel\Lumen\Http\Redirector; |
|
14
|
|
|
use Laravel\Lumen\Http\ResponseFactory; |
|
15
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class ShopController |
|
19
|
|
|
* @package App\Http\Controllers |
|
20
|
|
|
*/ |
|
21
|
|
|
class ShopController extends BaseController |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* List all Shop Countries |
|
25
|
|
|
* |
|
26
|
|
|
* @return JsonResponse |
|
27
|
|
|
*/ |
|
28
|
|
|
public function listCountries(): JsonResponse |
|
29
|
|
|
{ |
|
30
|
|
|
return response()->json(Country::all()); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get the Shop Inventory of a Country |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $countryCode |
|
37
|
|
|
* @return JsonResponse |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getInventory(string $countryCode): JsonResponse |
|
40
|
|
|
{ |
|
41
|
|
|
return response()->json(new ShopInventory(Country::where('countryCode', $countryCode)->first()), |
|
|
|
|
|
|
42
|
|
|
200, array(), JSON_UNESCAPED_SLASHES); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get User Purse |
|
47
|
|
|
* |
|
48
|
|
|
* @param Request $request |
|
49
|
|
|
* @return JsonResponse |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getPurse(Request $request): JsonResponse |
|
52
|
|
|
{ |
|
53
|
|
|
return response()->json(new Purse($request->user()->uniqueId)); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Proceed Payment Checkout |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $paymentCategory |
|
60
|
|
|
* @param string $countryCode |
|
61
|
|
|
* @param int $shopItem |
|
62
|
|
|
* @param string $paymentMethod |
|
63
|
|
|
* @return RedirectResponse|Response|Redirector|ResponseFactory |
|
64
|
|
|
*/ |
|
65
|
|
|
public function proceed(string $paymentCategory, string $countryCode, int $shopItem, string $paymentMethod) |
|
66
|
|
|
{ |
|
67
|
|
|
$paymentCheckout = DB::table('chocolatey_shop_payment_checkout') |
|
68
|
|
|
->where('category', $paymentCategory)->where('country', $countryCode) |
|
69
|
|
|
->where('item', $shopItem)->where('method', $paymentMethod)->first(); |
|
70
|
|
|
|
|
71
|
|
|
return $paymentCheckout != null ? redirect($paymentCheckout->redirect) |
|
72
|
|
|
: response(view('failed-payment'), 400); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.