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

Card::createToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 1
rs 10
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