Driver::redirectWithForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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