GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BraintreeApiClient   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 25
eloc 35
dl 0
loc 86
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
C sale() 0 31 14
A refund() 0 3 1
A generateClientToken() 0 7 3
A findPaymentMethodNonce() 0 3 1
A initialise() 0 19 6
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusBraintreePlugin\ApiClient;
14
15
use Braintree\ClientToken;
16
use Braintree\Configuration;
17
use Braintree\PaymentMethodNonce;
18
use Braintree\Result\Error;
19
use Braintree\Result\Successful;
20
use Braintree\Transaction;
21
use Payum\Core\Bridge\Spl\ArrayObject;
22
23
class BraintreeApiClient implements BraintreeApiClientInterface
24
{
25
    /** @var array */
26
    protected $options = [];
27
28
    public function initialise(array $options): void
29
    {
30
        $this->options = $options;
31
32
        Configuration::reset();
33
34
        $environment = 'sandbox';
35
36
        if (array_key_exists('environment', $this->options) && null !== $this->options['environment']) {
37
            $environment = $this->options['environment'];
38
        } elseif (array_key_exists('sandbox', $this->options) && null !== $this->options['sandbox']) {
39
            $environment = !$this->options['sandbox'] ? 'production' : 'sandbox';
40
        }
41
42
        Configuration::environment($environment);
43
44
        Configuration::merchantId($this->options['merchantId']);
45
        Configuration::publicKey($this->options['publicKey']);
46
        Configuration::privateKey($this->options['privateKey']);
47
    }
48
49
    public function generateClientToken(array $params): string
50
    {
51
        if (array_key_exists('merchantAccountId', $this->options) && null !== $this->options['merchantAccountId']) {
52
            $params['merchantAccountId'] = $this->options['merchantAccountId'];
53
        }
54
55
        return ClientToken::generate($params);
56
    }
57
58
    public function findPaymentMethodNonce(string $nonceString): PaymentMethodNonce
59
    {
60
        return PaymentMethodNonce::find($nonceString);
61
    }
62
63
    /**
64
     * @param ArrayObject $params
65
     *
66
     * @return Error|Successful
67
     */
68
    public function sale(ArrayObject $params)
69
    {
70
        $options = $params->offsetExists('options') ? $params['options'] : [];
71
72
        if (null !== $this->options['storeInVault'] && !isset($options['storeInVault'])) {
73
            $options['storeInVault'] = $this->options['storeInVault'];
74
        }
75
76
        if (null !== $this->options['storeInVaultOnSuccess'] && !isset($options['storeInVaultOnSuccess'])) {
77
            $options['storeInVaultOnSuccess'] = $this->options['storeInVaultOnSuccess'];
78
        }
79
80
        if (null !== $this->options['addBillingAddressToPaymentMethod'] &&
81
            !isset($options['addBillingAddressToPaymentMethod']) &&
82
            $params->offsetExists('billing')) {
83
            $options['addBillingAddressToPaymentMethod'] = $this->options['addBillingAddressToPaymentMethod'];
84
        }
85
86
        if (null !== $this->options['storeShippingAddressInVault'] &&
87
            !isset($options['storeShippingAddressInVault']) &&
88
            $params->offsetExists('shipping')) {
89
            $options['storeShippingAddressInVault'] = $this->options['storeShippingAddressInVault'];
90
        }
91
92
        $params['options'] = $options;
93
94
        if (array_key_exists('merchantAccountId', $this->options) && null !== $this->options['merchantAccountId']) {
95
            $params['merchantAccountId'] = $this->options['merchantAccountId'];
96
        }
97
98
        return Transaction::sale((array) $params);
99
    }
100
101
    /**
102
     * @param string $transactionId
103
     *
104
     * @return Successful|Error
105
     */
106
    public function refund(string $transactionId)
107
    {
108
        return Transaction::refund($transactionId);
109
    }
110
}
111