Completed
Push — master ( 0f7158...c955d1 )
by Kazi Mainuddin
02:38
created

PayuGateway::redirectRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
namespace Tzsk\Payu;
3
4
use Illuminate\Http\Request;
5
use Illuminate\Support\Facades\Cache;
6
use Tzsk\Payu\Helpers\Redirector;
7
use Tzsk\Payu\Model\PayuPayment;
8
9
class PayuGateway
10
{
11
12
    /**
13
     * Model to add;
14
     *
15
     * @var null
16
     */
17
    protected $model = null;
18
19
    /**
20
     * Pass any model to Add Polymorphic Relation.
21
     *
22
     * @param $model
23
     * @return $this
24
     */
25
    public function with($model)
26
    {
27
        $this->model = $model;
28
29
        return $this;
30
    }
31
32
    /**
33
     *
34
     * @param array $data
35
     * @param $callback
36
     * @return \Illuminate\Http\RedirectResponse
37
     */
38
    public function make(array $data, $callback)
39
    {
40
        $redirector = new Redirector();
41
42
        call_user_func($callback, $redirector);
43
        Cache::put('tzsk_data', $data, 5);
44
        Cache::put('tzsk_status_url', $redirector->getUrl(), 5);
45
        Cache::put('tzsk_model', $this->model, 15);
46
47
        return redirect()->to('tzsk/payment');
48
    }
49
50
    /**
51
     * Receive Payment and Return Payment Model.
52
     *
53
     * @return PayuPayment
54
     */
55
    public function capture()
56
    {
57
        $pay = Cache::get('tzsk_payment');
58
59
        if (config('payu.driver') == 'database') {
60
            return PayuPayment::find($pay);
61
        }
62
63
        return new PayuPayment($pay);
64
    }
65
66
    /**
67
     * Get Status of a given Transaction.
68
     *
69
     * @param $txn_id
70
     * @return object
71
     */
72
    public function verify($txnid)
73
    {
74
        $txnid = is_array($txnid) ? $txnid : [$txnid];
75
        $verification = new PaymentVerification($txnid);
76
77
        return $verification->request();
78
    }
79
80
81
}
82