Passed
Push — main ( 1246ad...d1c484 )
by Iain
06:09
created

PaymentMethodFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A buildFromCardFile() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Factory;
16
17
use Obol\Model\CardFile;
18
use Parthenon\Billing\Entity\CustomerInterface;
19
use Parthenon\Billing\Entity\PaymentMethod;
20
21
final class PaymentMethodFactory implements PaymentMethodFactoryInterface
22
{
23
    public function buildFromCardFile(CustomerInterface $customer, CardFile $cardFile, string $provider): PaymentMethod
24
    {
25
        $paymentDetails = new PaymentMethod();
26
        $paymentDetails->setCustomer($customer);
27
        $paymentDetails->setStoredCustomerReference($customer->getExternalCustomerReference());
28
        $paymentDetails->setStoredPaymentReference($cardFile->getStoredPaymentReference());
29
        $paymentDetails->setProvider($provider);
30
        $paymentDetails->setDefaultPaymentOption(true);
31
        $paymentDetails->setName('Default');
32
        $paymentDetails->setBrand($cardFile->getBrand());
33
        $paymentDetails->setLastFour($cardFile->getLastFour());
34
        $paymentDetails->setExpiryMonth($cardFile->getExpiryMonth());
35
        $paymentDetails->setExpiryYear($cardFile->getExpiryYear());
36
        $paymentDetails->setDeleted(false);
37
        $paymentDetails->setCreatedAt(new \DateTime());
38
39
        return $paymentDetails;
40
    }
41
}
42