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.

SibsService   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 13

2 Methods

Rating   Name   Duplication   Size   Complexity  
C checkout() 0 49 12
A status() 0 3 1
1
<?php
2
3
namespace Apoca\Sibs\Services;
4
5
use Apoca\Sibs\Brands\Card;
6
use Apoca\Sibs\Brands\Checkout;
7
use Apoca\Sibs\Brands\PaymentWithCard;
8
use Apoca\Sibs\Brands\PaymentWithMBWay;
9
use Apoca\Sibs\Brands\Transaction;
10
use Apoca\Sibs\Contracts\PaymentInterface;
11
use Exception;
12
13
/**
14
 * Class SibsService
15
 *
16
 * @package Apoca\Sibs\Services
17
 */
18
class SibsService
19
{
20
    /**
21
     * @param array $request
22
     *
23
     * @return PaymentInterface
24
     * @throws Exception
25
     */
26
    public function checkout(array $request): PaymentInterface
27
    {
28
        switch (strtoupper($request['brand'])) {
29
            case 'MASTER':
30
            case 'AMEX':
31
            case 'VPAY':
32
            case 'MAESTRO':
33
            case 'VISADEBIT':
34
            case 'VISAELECTRON':
35
            case 'VISA':
36
                $payment = new PaymentWithCard(
37
                    $request['amount'],
38
                    strtoupper($request['currency']),
39
                    strtoupper($request['brand']),
40
                    strtoupper($request['type']),
41
                    $request['optionalParameters'],
42
                    new Card(
43
                        $request['number'],
44
                        $request['holder'],
45
                        $request['expiry_month'],
46
                        $request['expiry_year'],
47
                        $request['cvv']
48
                    )
49
                );
50
                break;
51
            case 'CHECKOUT':
52
                $payment = new Checkout($request['amount'], $request['currency'], $request['type'], $request['optionalParameters']);
53
                break;
54
            case 'SIBS_MULTIBANCO':
55
                throw new \RuntimeException('SIBS_MULTIBANCO Service Payment not found.', 404);
56
                break;
57
            case 'DIRECTDEBIT_SEPA':
58
                throw new \RuntimeException('DIRECTDEBIT_SEPA Service Payment not found.', 404);
59
                break;
60
            case 'MBWAY':
61
                $payment = new PaymentWithMBWay(
62
                    $request['amount'],
63
                    strtoupper($request['currency']),
64
                    strtoupper($request['brand']),
65
                    strtoupper($request['type']),
66
                    $request['accountId'],
67
                    $request['optionalParameters']
68
                );
69
                break;
70
            default:
71
                throw new \RuntimeException('Sibs Service Payment not found.', 404);
72
        }
73
74
        return $payment;
75
    }
76
77
    /**
78
     * Get payment status
79
     *
80
     * @param string $checkoutId
81
     *
82
     * @return object
83
     */
84
    public function status(string $checkoutId): object
85
    {
86
        return (new Transaction($checkoutId))->status();
87
    }
88
}
89