Passed
Push — main ( 241451...172c2c )
by Iain
05:00
created

createPaymentDetailsFromToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2024 Iain Cambridge
7
 *
8
 *     This program is free software: you can redistribute it and/or modify
9
 *     it under the terms of the GNU General Public License as published by
10
 *     the Free Software Foundation, either version 3 of the License, or
11
 *     (at your option) any later version.
12
 *
13
 *     This program is distributed in the hope that it will be useful,
14
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *     GNU General Public License for more details.
17
 *
18
 *     You should have received a copy of the GNU General Public License
19
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\Billing\BillaBear\PaymentMethod;
23
24
use BillaBear\Model\FrontendToken;
0 ignored issues
show
Bug introduced by
The type BillaBear\Model\FrontendToken was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use BillaBear\Model\PaymentDetails;
0 ignored issues
show
Bug introduced by
The type BillaBear\Model\PaymentDetails was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Parthenon\Billing\BillaBear\SdkFactory;
27
use Parthenon\Billing\Entity\CustomerInterface;
28
use Parthenon\Billing\Entity\PaymentCard;
29
use Parthenon\Billing\PaymentMethod\FrontendAddProcessorInterface;
30
31
class FrontendAddProcessor implements FrontendAddProcessorInterface
32
{
33
    public function __construct(private SdkFactory $sdkFactory)
34
    {
35
    }
36
37
    public function startTokenProcess(CustomerInterface $customer): string
38
    {
39
        $response = $this->sdkFactory->createPaymentDetails()->startFrontendPaymentDetails($customer->getExternalCustomerReference());
40
41
        return $response->getToken();
42
    }
43
44
    public function createPaymentDetailsFromToken(CustomerInterface $customer, string $token): PaymentCard
45
    {
46
        $token = new FrontendToken(['token' => $token]);
47
48
        $response = $this->sdkFactory->createPaymentDetails()->completeFrontendPaymentDetails($token, $customer->getExternalCustomerReference());
49
50
        return $this->buildPaymentCard($response);
51
    }
52
53
    private function buildPaymentCard(PaymentDetails $paymentDetails): PaymentCard
54
    {
55
        $paymentCard = new PaymentCard();
56
        $paymentCard->setId($paymentDetails->getId());
57
        $paymentCard->setName($paymentDetails->getName());
58
        $paymentCard->setDefaultPaymentOption($paymentDetails->getDefault());
59
        $paymentCard->setBrand($paymentDetails->getBrand());
60
        $paymentCard->setLastFour($paymentDetails->getLastFour());
61
        $paymentCard->setExpiryMonth($paymentDetails->getExpiryMonth());
62
        $paymentCard->setExpiryYear($paymentDetails->getExpiryYear());
63
        $paymentCard->setCreatedAt(new \DateTime($paymentDetails->getCreatedAt()));
64
65
        return $paymentCard;
66
    }
67
}
68