Issues (220)

src/Provider/Apple/ApplePayDirectProvider.php (5 issues)

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\Provider\Apple;
13
14
use BitBag\SyliusMolliePlugin\Client\MollieApiClient;
15
use BitBag\SyliusMolliePlugin\Provider\Order\OrderPaymentApplePayDirectProviderInterface;
16
use BitBag\SyliusMolliePlugin\Resolver\Address\ApplePayAddressResolverInterface;
17
use Sylius\AdminOrderCreationPlugin\Provider\CustomerProviderInterface;
18
use Sylius\Component\Core\Model\PaymentInterface;
19
use Sylius\Component\Order\Model\OrderInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Webmozart\Assert\Assert;
22
23
final class ApplePayDirectProvider implements ApplePayDirectProviderInterface
24
{
25
    /** @var ApplePayAddressResolverInterface */
26
    private $applePayAddressResolver;
27
28
    /** @var MollieApiClient */
29
    private $mollieApiClient;
30
31
    /** @var OrderPaymentApplePayDirectProviderInterface */
32
    private $paymentApplePayDirectProvider;
33
34
    /** @var CustomerProviderInterface */
35
    private $customerProvider;
36
37
    /** @var ApplePayDirectPaymentProviderInterface */
38
    private $applePayDirectPaymentProvider;
39
40
    public function __construct(
41
        ApplePayAddressResolverInterface $applePayAddressResolver,
42
        MollieApiClient $mollieApiClient,
43
        OrderPaymentApplePayDirectProviderInterface $paymentApplePayDirectProvider,
44
        CustomerProviderInterface $customerProvider,
45
        ApplePayDirectPaymentProviderInterface $applePayDirectPaymentProvider
46
    ) {
47
        $this->applePayAddressResolver = $applePayAddressResolver;
48
        $this->mollieApiClient = $mollieApiClient;
49
        $this->paymentApplePayDirectProvider = $paymentApplePayDirectProvider;
50
        $this->customerProvider = $customerProvider;
51
        $this->applePayDirectPaymentProvider = $applePayDirectPaymentProvider;
52
    }
53
54
    public function provideOrder(OrderInterface $order, Request $request): void
55
    {
56
        $applePayPaymentToken = $request->get('token');
57
        $applePayAddress['shippingContact'] = $request->get('shippingContact');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$applePayAddress was never initialized. Although not strictly required by PHP, it is generally a good practice to add $applePayAddress = array(); before regardless.
Loading history...
58
        $applePayAddress['billingContact'] = $request->get('billingContact');
59
60
        Assert::notNull($applePayPaymentToken);
61
        Assert::notNull($applePayAddress['shippingContact']);
62
        Assert::notNull($applePayAddress['billingContact']);
63
64
        if (isset($applePayAddress['shippingContact']['emailAddress'])) {
65
            $applePayAddress['billingContact']['emailAddress'] = $applePayAddress['shippingContact']['emailAddress'];
66
        }
67
68
        $this->applePayAddressResolver->resolve($order, $applePayAddress);
69
        $this->paymentApplePayDirectProvider->provideOrderPayment($order, PaymentInterface::STATE_NEW);
70
71
        if (null !== $customer = $order->getShippingAddress()->getCustomer()) {
0 ignored issues
show
The method getShippingAddress() does not exist on Sylius\Component\Order\Model\OrderInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Order\Model\Order. Are you sure you never get one of those? ( Ignorable by Annotation )

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

71
        if (null !== $customer = $order->/** @scrutinizer ignore-call */ getShippingAddress()->getCustomer()) {
Loading history...
72
            $order->setCustomer($customer);
0 ignored issues
show
The method setCustomer() does not exist on Sylius\Component\Order\Model\OrderInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Order\Model\Order. Are you sure you never get one of those? ( Ignorable by Annotation )

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

72
            $order->/** @scrutinizer ignore-call */ 
73
                    setCustomer($customer);
Loading history...
73
        }
74
75
        if (null === $order->getCustomer()) {
0 ignored issues
show
The method getCustomer() does not exist on Sylius\Component\Order\Model\OrderInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Order\Model\Order. Are you sure you never get one of those? ( Ignorable by Annotation )

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

75
        if (null === $order->/** @scrutinizer ignore-call */ getCustomer()) {
Loading history...
76
            $this->customerProvider->provideNewCustomer($applePayAddress['shippingContact']['emailAddress']);
77
        }
78
79
        $this->applePayDirectPaymentProvider->provideApplePayPayment($order, $applePayPaymentToken);
0 ignored issues
show
It seems like $applePayPaymentToken can also be of type null; however, parameter $applePayPaymentToken of BitBag\SyliusMolliePlugi...rovideApplePayPayment() does only seem to accept array, 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

79
        $this->applePayDirectPaymentProvider->provideApplePayPayment($order, /** @scrutinizer ignore-type */ $applePayPaymentToken);
Loading history...
80
    }
81
}
82