Completed
Push — master ( bf97a3...fb31dc )
by Kazi Mainuddin
01:54
created

ProcessPayment::getStatus()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 17
rs 9.2
c 2
b 1
f 0
cc 4
eloc 10
nc 4
nop 0
1
<?php
2
namespace Tzsk\Payu;
3
4
5
use Illuminate\Http\Request;
6
7
class ProcessPayment
8
{
9
    /**
10
     * Payment statuses.
11
     */
12
    const STATUS_COMPLETED = 'Completed';
13
    const STATUS_PENDING   = 'Pending';
14
    const STATUS_FAILED    = 'Failed';
15
16
    /**
17
     * Request returned from gateway.
18
     *
19
     * @var Request
20
     */
21
    protected $request;
22
23
    /**
24
     * ProcessPayment constructor.
25
     *
26
     * @param Request $request
27
     */
28
    public function __construct(Request $request)
29
    {
30
        $this->request = $request;
31
    }
32
33
    /**
34
     * Get the status of the Payment.
35
     *
36
     * @return string
37
     */
38
    public function getStatus()
39
    {
40
        switch (strtolower($this->request->status)) {
41
            case 'success':
42
                return self::STATUS_COMPLETED;
43
44
            case 'pending':
45
                return self::STATUS_PENDING;
46
47
            case 'failure':
48
                return self::STATUS_FAILED;
49
50
            default:
51
                return self::STATUS_FAILED;
52
        }
53
54
    }
55
56
    /**
57
     * Get Transaction ID of the transaction.
58
     *
59
     * @return null|string
60
     */
61
    public function getTransactionId()
62
    {
63
        return $this->request->has('mihpayid') ? (string) $this->request->mihpayid : null;
64
    }
65
66
    /**
67
     * Get the hash returned by the gateway.
68
     *
69
     * @return null|string
70
     */
71
    protected function getHash()
72
    {
73
        return $this->request->has('hash') ? (string) $this->request->hash : null;
74
    }
75
76
}
77