Completed
Push — master ( 8c5590...0f9b49 )
by mahdi
03:47
created

Driver::redirectWithForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Shetabit\Payment\Abstracts;
4
5
use Shetabit\Payment\Contracts\DriverInterface;
6
use Shetabit\Payment\Invoice;
7
8
abstract class Driver implements DriverInterface
9
{
10
    /**
11
     * Invoice
12
     *
13
     * @var Invoice
14
     */
15
    protected $invoice;
16
17
    /**
18
     * Driver's settings
19
     *
20
     * @var
21
     */
22
    protected $settings;
23
24
    /**
25
     * Driver constructor.
26
     *
27
     * Driver constructor.
28
     * @param Invoice $invoice
29
     * @param $settings
30
     */
31
    abstract public function __construct(Invoice $invoice, $settings);
32
33
    /**
34
     * Set payment amount.
35
     *
36
     * @param $amount
37
     * @return $this
38
     * @throws \Exception
39
     */
40
    public function amount($amount)
41
    {
42
        $this->invoice->amount($amount);
43
44
        return $this;
45
    }
46
47
    /**
48
     * Set a piece of data to the details.
49
     *
50
     * @param $key
51
     * @param $value|null
52
     * @return $this|DriverInterface
53
     */
54
    public function detail($key, $value = null)
55
    {
56
        $key = is_array($key) ? $key : [$key => $value];
57
58
        foreach ($key as $k => $v) {
59
            $this->invoice->detail($key, $value);
60
        }
61
62
        return $this;
63
    }
64
65
    /**
66
     * Set invoice.
67
     *
68
     * @param Invoice $invoice
69
     * @return $this
70
     */
71
    public function invoice(Invoice $invoice)
72
    {
73
        $this->invoice = $invoice;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Retrieve invoice.
80
     *
81
     * @return Invoice
82
     */
83
    public function getInvoice()
84
    {
85
        return $this->invoice;
86
    }
87
88
    /**
89
     * Create payment redirection form.
90
     *
91
     * @param $action
92
     * @param array $inputs
93
     * @param string $method
94
     * @return string
95
     */
96
    public function redirectWithForm($action, array $inputs = [], $method = 'POST')
97
    {
98
99
        return view('shetabitPayment::redirectForm')->with(
100
            [
101
                'action' => $action,
102
                'inputs' => $inputs,
103
                'method' => $method,
104
            ]
105
        );
106
    }
107
108
    /**
109
     * Purchase the invoice
110
     *
111
     * @return string
112
     */
113
    abstract public function purchase();
114
115
    /**
116
     * Pay the invoice
117
     *
118
     * @return mixed
119
     */
120
    abstract public function pay();
121
122
    /**
123
     * Verify the payment
124
     *
125
     * @return mixed
126
     */
127
    abstract public function verify();
128
}
129