TransactionService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthorizationUrl() 0 11 2
A redirectNow() 0 5 1
A verify() 0 12 5
1
<?php
2
3
namespace ParkwayProjects\PayWithBank3D\Actions;
4
5
use Exception;
6
use ParkwayProjects\PayWithBank3D\PRequest;
7
8
class TransactionService extends PRequest
9
{
10
    protected $initializeUrl = 'transaction/initialize';
11
    protected $verifyUrl = 'payment/verify/';
12
13
    protected $redirectUrl;
14
15
    public function getAuthorizationUrl()
16
    {
17
        try {
18
            $data = $this->performPostRequest($this->initializeUrl);
19
            $this->redirectUrl = $data['body']['data']['paymentUrl'];
20
21
            return $this;
22
        } catch (Exception $exception) {
23
            throw new Exception($exception->getMessage());
24
        }
25
    }
26
27
    public function redirectNow()
28
    {
29
        header('Location: '.$this->redirectUrl);
30
        exit;
31
    }
32
33
    public function verify()
34
    {
35
        $reference = isset($_GET['reference']) ? $_GET['reference'] : null;
36
        if (is_null($reference) || ! is_string($reference)) {
37
            die('No Reference');
38
        }
39
        try {
40
            return $this->performGetRequest($this->verifyUrl.$reference);
41
        } catch (Exception $exception) {
42
            throw new Exception($exception->getMessage());
43
        }
44
    }
45
}
46