forked from ctf0/laravel-paymob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDummyController.php
68 lines (59 loc) · 1.8 KB
/
DummyController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use ctf0\PayMob\Facades\PayMob;
use ctf0\PayMob\Integrations\CreditCard;
use ctf0\PayMob\Integrations\MobileWallet;
use Illuminate\Http\Client\RequestException;
class DummyController extends Controller
{
/**
* show the order details to the user.
*
* @return \Illuminate\View\View
*/
public function checkOut()
{
return view('paymob::checkout');
}
/**
* process the order on the gateway side.
*/
public function process(Request $request)
{
$request->validate([
'payment_type' => [
'required',
'string',
],
]);
$payment_type = $request->payment_type;
$user = $request->user();
$total = 0; // order total
try {
if ($payment_type == 'card_payment') {
return (new CreditCard($user))->checkOut($total)['url'] ?? '';
} else if ($payment_type == 'mobile_wallet') {
return (new MobileWallet($user))->checkOut($total)['url'] ?? '';
} else {
abort(403, __('Method not supported')); // // or MobileWallet, etc..
}
} catch (RequestException $e) {
return __('something went wrong, please try again later');
}
}
/**
* validate and complete the order.
*
* https://acceptdocs.paymobsolutions.com/docs/transaction-callbacks#transaction-response-callback.
*
* @return \Illuminate\View\View
*/
public function complete(Request $request)
{
PayMob::validateHmac($request->hmac, $request->id);
// save the transaction data to the server
$data = $request->all();
return view('paymob::complete');
}
}