Passed
Pull Request — master (#27)
by Sébastien
02:36
created

Card   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A createToken() 0 14 1
1
<?php
2
3
namespace Sebdesign\VivaPayments;
4
5
use GuzzleHttp\RequestOptions;
6
7
class Card
8
{
9 3
    public function __construct(protected Client $client)
10
    {
11
    }
12
13
    /**
14
     * Create card token.
15
     *
16
     * @see https://developer.vivawallet.com/apis-for-payments/payment-api/#tag/Transactions/paths/~1acquiring~1v1~1cards~1tokens/post
17
     *
18
     * @param  array<string,mixed>  $guzzleOptions
19
     */
20 6
    public function createToken(string $transactionId, array $guzzleOptions = []): string
21
    {
22 6
        $parameters = ['transactionId' => $transactionId];
23
24 6
        $response = $this->client->post(
25 6
            $this->client->getApiUrl()->withPath('/acquiring/v1/cards/tokens'),
26 6
            array_merge_recursive(
27 2
                [RequestOptions::JSON => $parameters],
28 6
                $this->client->authenticateWithBearerToken(),
29
                $guzzleOptions
30
            )
31
        );
32
33 3
        return strval($response['token'] ?? '');
34
    }
35
}
36