ApplePayDirectPaymentTypeResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createPaymentOrder() 0 6 1
A __construct() 0 6 1
A createPayment() 0 3 1
A resolve() 0 24 2
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
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Resolver\ApplePayDirect;
13
14
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
15
use BitBag\SyliusMolliePlugin\Entity\OrderInterface;
16
use BitBag\SyliusMolliePlugin\Payments\Methods\AbstractMethod;
17
use Sylius\Component\Core\Model\PaymentInterface;
18
19
final class ApplePayDirectPaymentTypeResolver implements ApplePayDirectPaymentTypeResolverInterface
20
{
21
    /** @var ApplePayDirectApiPaymentResolverInterface */
22
    private $apiPaymentResolver;
23
24
    /** @var ApplePayDirectApiOrderPaymentResolverInterface */
25
    private $apiOrderPaymentResolver;
26
27
    public function __construct(
28
        ApplePayDirectApiPaymentResolverInterface $apiPaymentResolver,
29
        ApplePayDirectApiOrderPaymentResolverInterface $apiOrderPaymentResolver
30
    ) {
31
        $this->apiPaymentResolver = $apiPaymentResolver;
32
        $this->apiOrderPaymentResolver = $apiOrderPaymentResolver;
33
    }
34
35
    public function resolve(
36
        MollieGatewayConfigInterface $mollieGatewayConfig,
37
        PaymentInterface $payment,
38
        array $applePayDirectToken
39
    ): void {
40
        $details = [];
41
        $order = $payment->getOrder();
42
43
        $amount = number_format(abs($payment->getAmount() / 100), 2, '.', '');
44
45
        $details['amount'] = [
46
            'currency' => $payment->getCurrencyCode(),
47
            'value' => "$amount",
48
        ];
49
50
        $details['applePayDirectToken'] = json_encode($applePayDirectToken);
51
        $details['backurl'] = $payment->getDetails()['backurl'];
52
        if (AbstractMethod::ORDER_API === $mollieGatewayConfig->getPaymentType()) {
53
            $this->createPaymentOrder($order, $mollieGatewayConfig, $details);
0 ignored issues
show
Bug introduced by
It seems like $order can also be of type null; however, parameter $order of BitBag\SyliusMolliePlugi...r::createPaymentOrder() does only seem to accept BitBag\SyliusMolliePlugin\Entity\OrderInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
            $this->createPaymentOrder(/** @scrutinizer ignore-type */ $order, $mollieGatewayConfig, $details);
Loading history...
54
55
            return;
56
        }
57
58
        $this->createPayment($order, $details);
0 ignored issues
show
Bug introduced by
It seems like $order can also be of type null; however, parameter $order of BitBag\SyliusMolliePlugi...solver::createPayment() does only seem to accept BitBag\SyliusMolliePlugin\Entity\OrderInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
        $this->createPayment(/** @scrutinizer ignore-type */ $order, $details);
Loading history...
59
    }
60
61
    private function createPayment(OrderInterface $order, array $details): void
62
    {
63
        $this->apiPaymentResolver->resolve($order, $details);
64
    }
65
66
    private function createPaymentOrder(
67
        OrderInterface $order,
68
        MollieGatewayConfigInterface $mollieGatewayConfig,
69
        array $details
70
    ): void {
71
        $this->apiOrderPaymentResolver->resolve($order, $mollieGatewayConfig, $details);
72
    }
73
}
74