Completed
Push — master ( 30ef9c...66d5ad )
by
unknown
12s queued 11s
created

Facade::sendKycProof()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Covery\Client;
4
5
use Covery\Client\Credentials\Sha256;
6
use Psr\Log\LoggerInterface;
7
8
/**
9
 * Class Facade
10
 *
11
 * Static access facade to covery client
12
 *
13
 * @package Covery\Client
14
 */
15
class Facade
16
{
17
    /**
18
     * @var CredentialsInterface
19
     */
20
    private static $credentials;
21
    /**
22
     * @var TransportInterface
23
     */
24
    private static $transport;
25
    /**
26
     * @var PublicAPIClient
27
     */
28
    private static $client;
29
    /**
30
     * @var LoggerInterface|null
31
     */
32
    private static $logger;
33
34
    /**
35
     * Set logger
36
     *
37
     * @param LoggerInterface $logger
38
     */
39
    public static function setLogger(LoggerInterface $logger)
40
    {
41
        self::$logger = $logger;
42
    }
43
44
    /**
45
     * Sets (or replaces) credentials
46
     *
47
     * @param string $token
48
     * @param string $secret
49
     */
50
    public static function setCredentials($token, $secret)
51
    {
52
        self::$credentials = new Sha256($token, $secret);
53
    }
54
55
    /**
56
     * Sets (or replaces) transport
57
     *
58
     * @param TransportInterface $transport
59
     */
60
    public static function setTransport(TransportInterface $transport)
61
    {
62
        self::$transport = $transport;
63
    }
64
65
    /**
66
     * Utility method to take client
67
     *
68
     * @return PublicAPIClient
69
     * @throws Exception
70
     */
71
    private static function getClient()
72
    {
73
        if (self::$client === null) {
74
            if (self::$credentials !== null && self::$transport !== null) {
75
                self::$client = new PublicAPIClient(self::$credentials, self::$transport, self::$logger);
76
            } else {
77
                throw new Exception('Unable to obtain client - credentials and/or transport not set');
78
            }
79
        }
80
81
        return self::$client;
82
    }
83
84
    /**
85
     * Sends request to Covery and returns access level, associated with
86
     * used credentials
87
     *
88
     * This method can be used for Covery health check and availability
89
     * On any problem (network, credentials, server side) this method
90
     * will throw an exception
91
     *
92
     * @return mixed
93
     * @throws Exception
94
     */
95
    public static function ping()
96
    {
97
        return self::getClient()->ping();
98
    }
99
100
    /**
101
     * Sends envelope to Covery and returns it's ID on Covery side
102
     * Before sending, validation is performed
103
     *
104
     * @param EnvelopeInterface $envelope
105
     * @return int
106
     * @throws Exception
107
     */
108
    public static function sendEvent(EnvelopeInterface $envelope)
109
    {
110
        return self::getClient()->sendEvent($envelope);
111
    }
112
113
    /**
114
     * Sends postback envelope to Covery and returns it's ID on Covery side
115
     * Before sending, validation is performed
116
     *
117
     * @param EnvelopeInterface $envelope
118
     * @return int
119
     * @throws Exception
120
     */
121
    public static function sendPostback(EnvelopeInterface $envelope)
122
    {
123
        return self::getClient()->sendPostback($envelope);
124
    }
125
126
    /**
127
     * Sends envelope to Covery for analysis
128
     *
129
     * @param EnvelopeInterface $envelope
130
     * @return Result
131
     * @throws Exception
132
     */
133
    public static function makeDecision(EnvelopeInterface $envelope)
134
    {
135
        return self::getClient()->makeDecision($envelope);
136
    }
137
138
    /**
139
     * Sends KycProof envelope to Covery and returns data on Covery side
140
     *
141
     * @param EnvelopeInterface $envelope
142
     * @return KycProofResult
143
     * @throws Exception
144
     */
145
    public static function sendKycProof(EnvelopeInterface $envelope)
146
    {
147
        return self::getClient()->sendKycProof($envelope);
148
    }
149
}
150