Getnet::setKeySession()   A
last analyzed

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 Getnet\API;
4
5
/**
6
 * Class Getnet
7
 *
8
 * @package Getnet\API
9
 */
10
class Getnet
11
{
12
    /** @var */
13
    private $client_id;
14
15
    /** @var */
16
    private $client_secret;
17
18
    /** @var */
19
    private $environment;
20
21
    /** @var */
22
    private $authorizationToken;
23
24
    /** @var */
25
    private $keySession;
26
27
    /**
28
     * Getnet constructor.
29
     * @param $client_id
30
     * @param $client_secret
31
     * @param Environment|null $environment
32
     * @param null $keySession
33
     * @throws \Exception
34
     */
35
    public function __construct(
36
        $client_id,
37
        $client_secret,
38
        Environment $environment = null,
39
        $keySession = null
40
    ) {
41
        if (!$environment) {
42
            $environment = Environment::production();
43
        }
44
45
        $this->setClientId($client_id);
46
        $this->setClientSecret($client_secret);
47
        $this->setEnvironment($environment);
48
        $this->setKeySession($keySession);
49
50
        $request = new Request($this);
51
52
        return $request->auth($this);
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getClientId()
59
    {
60
        return $this->client_id;
61
    }
62
63
    /**
64
     * @param $client_id
65
     * @return $this
66
     */
67
    public function setClientId($client_id)
68
    {
69
        $this->client_id = (string)$client_id;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getClientSecret()
78
    {
79
        return $this->client_secret;
80
    }
81
82
    /**
83
     * @param $client_secret
84
     * @return $this
85
     */
86
    public function setClientSecret($client_secret)
87
    {
88
        $this->client_secret = (string)$client_secret;
89
90
        return $this;
91
    }
92
93
    /**
94
     * @return Environment
95
     */
96
    public function getEnvironment()
97
    {
98
        return $this->environment;
99
    }
100
101
    /**
102
     * @param Environment $environment
103
     * @return $this
104
     */
105
    public function setEnvironment(Environment $environment)
106
    {
107
        $this->environment = $environment;
108
109
        return $this;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getAuthorizationToken()
116
    {
117
        return $this->authorizationToken;
118
    }
119
120
    /**
121
     * @param $authorizationToken
122
     * @return $this
123
     */
124
    public function setAuthorizationToken($authorizationToken)
125
    {
126
        $this->authorizationToken = (string)$authorizationToken;
127
128
        return $this;
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getKeySession()
135
    {
136
        return $this->keySession;
137
    }
138
139
    /**
140
     * @param $keySession
141
     */
142
    public function setKeySession($keySession)
143
    {
144
        $this->keySession = (string)$keySession;
145
    }
146
147
    /**
148
     * @param Transaction $transaction
149
     * @return AuthorizeResponse|BaseResponse
150
     */
151
    public function authorize(Transaction $transaction)
152
    {
153
        try {
154
            $request = new Request($this);
155
156
            if ($transaction->getCredit()) {
157
                $response = $request->post($this, "/v1/payments/credit", $transaction->toJSON());
158
            } elseif ($transaction->getDebit()) {
159
                $response = $request->post($this, "/v1/payments/debit", $transaction->toJSON());
160
            } else {
161
                throw new \Exception("Error select credit or debit");
162
            }
163
        } catch (\Exception $e) {
164
            $error = new BaseResponse();
165
            $error->mapperJson(json_decode($e->getMessage(), true));
166
167
            return $error;
168
        }
169
170
        $authresponse = new AuthorizeResponse();
171
        $authresponse->mapperJson($response);
172
173
        return $authresponse;
174
    }
175
176
    /**
177
     * @param $payment_id
178
     * @return AuthorizeResponse|BaseResponse
179
     */
180
    public function authorizeConfirm($payment_id)
181
    {
182
        try {
183
            $request = new Request($this);
184
            $response = $request->post($this, "/v1/payments/credit/".$payment_id."/confirm", "");
185
        } catch (\Exception $e) {
186
            $error = new BaseResponse();
187
            $error->mapperJson(json_decode($e->getMessage(), true));
188
189
            return $error;
190
        }
191
192
        $authresponse = new AuthorizeResponse();
193
        $authresponse->mapperJson($response);
194
195
        return $authresponse;
196
    }
197
198
    /**
199
     * @param $payment_id
200
     * @param $payer_authentication_response
201
     * @return AuthorizeResponse|BaseResponse
202
     */
203 View Code Duplication
    public function authorizeConfirmDebit($payment_id, $payer_authentication_response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
204
    {
205
        try {
206
            $payer_authentication_response = ["payer_authentication_response" => $payer_authentication_response];
207
            $request = new Request($this);
208
            $response = $request->post($this, "/v1/payments/debit/".$payment_id."/authenticated/finalize", json_encode($payer_authentication_response));
209
        } catch (\Exception $e) {
210
            $error = new BaseResponse();
211
            $error->mapperJson(json_decode($e->getMessage(), true));
212
213
            return $error;
214
        }
215
216
        $authresponse = new AuthorizeResponse();
217
        $authresponse->mapperJson($response);
218
219
        return $authresponse;
220
    }
221
222
    /**
223
     * @param $payment_id
224
     * @param $amount_val
225
     * @return AuthorizeResponse|BaseResponse
226
     */
227 View Code Duplication
    public function authorizeCancel($payment_id, $amount_val)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
228
    {
229
        $amount = ["amount" => $amount_val];
230
231
        try {
232
            $request = new Request($this);
233
            $response = $request->post($this, "/v1/payments/credit/".$payment_id."/cancel", json_encode($amount));
234
        } catch (\Exception $e) {
235
            $error = new BaseResponse();
236
            $error->mapperJson(json_decode($e->getMessage(), true));
237
238
            return $error;
239
        }
240
241
        $authresponse = new AuthorizeResponse();
242
        $authresponse->mapperJson($response);
243
244
        return $authresponse;
245
    }
246
247
    /**
248
     * @param Transaction $transaction
249
     * @return BaseResponse|BoletoResponse
250
     */
251
    public function boleto(Transaction $transaction)
252
    {
253
        try {
254
            $request = new Request($this);
255
            $response = $request->post($this, "/v1/payments/boleto", $transaction->toJSON());
256
        } catch (\Exception $e) {
257
            $error = new BaseResponse();
258
            $error->mapperJson(json_decode($e->getMessage(), true));
259
260
            return $error;
261
        }
262
263
        $boletoresponse = new BoletoResponse();
264
        $boletoresponse->mapperJson($response);
265
        $boletoresponse->setBaseUrl($request->getBaseUrl());
266
        $boletoresponse->generateLinks();
267
268
        return $boletoresponse;
269
    }
270
271
    /**
272
     * @param Card $card
273
     * @return BaseResponse|CardVerificationResponse
274
     */
275
    public function verifyCard(Card $card)
276
    {
277
        try {
278
            $request = new Request($this);
279
            $response = $request->post($this, "/v1/cards/verification", $card->toJSON());
280
        } catch (\Exception $e) {
281
            $error = new BaseResponse();
282
            $error->mapperJson(json_decode($e->getMessage(), true));
283
284
            return $error;
285
        }
286
287
        $cardVerificationResponse = new CardVerificationResponse();
288
        $cardVerificationResponse->mapperJson($response);
289
290
        return $cardVerificationResponse;
291
    }
292
}
293