Passed
Push — master ( 0676a7...01ab94 )
by Artem
11:54
created

PaymentRepository::createPayPalPayment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Account\Repository;
13
14
use Linode\Account\Payment;
15
use Linode\Account\PaymentRepositoryInterface;
16
use Linode\Account\PayPalPayment;
17
use Linode\Entity;
18
use Linode\Internal\AbstractRepository;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class PaymentRepository extends AbstractRepository implements PaymentRepositoryInterface
24
{
25
    public function createPayment(string $usd, string $cvv): Payment
26
    {
27
        $parameters = [
28
            'usd' => $usd,
29
            'cvv' => $cvv,
30
        ];
31
32
        $response = $this->client->post($this->getBaseUri(), $parameters);
33
        $contents = $response->getBody()->getContents();
34
        $json     = json_decode($contents, true);
35
36
        return new Payment($this->client, $json);
37
    }
38
39
    public function createPayPalPayment(string $usd, string $redirect_url, string $cancel_url): PayPalPayment
40
    {
41
        $parameters = [
42
            'usd'          => $usd,
43
            'redirect_url' => $redirect_url,
44
            'cancel_url'   => $cancel_url,
45
        ];
46
47
        $response = $this->client->post(sprintf('%s/paypal', $this->getBaseUri()), $parameters);
48
        $contents = $response->getBody()->getContents();
49
        $json     = json_decode($contents, true);
50
51
        return new PayPalPayment($this->client, $json);
52
    }
53
54
    public function executePayPalPayment(string $payer_id, string $payment_id): void
55
    {
56
        $parameters = [
57
            'payer_id'   => $payer_id,
58
            'payment_id' => $payment_id,
59
        ];
60
61
        $this->client->post(sprintf('%s/paypal/execute', $this->getBaseUri()), $parameters);
62
    }
63
64
    protected function getBaseUri(): string
65
    {
66
        return '/account/payments';
67
    }
68
69
    protected function getSupportedFields(): array
70
    {
71
        return [
72
            Payment::FIELD_ID,
73
            Payment::FIELD_DATE,
74
            Payment::FIELD_USD,
75
        ];
76
    }
77
78
    protected function jsonToEntity(array $json): Entity
79
    {
80
        return new Payment($this->client, $json);
81
    }
82
}
83